![]() |
VOOZH | about |
dotnet add package MonoGameHtml --version 1.0.1-alpha
NuGet\Install-Package MonoGameHtml -Version 1.0.1-alpha
<PackageReference Include="MonoGameHtml" Version="1.0.1-alpha" />
<PackageVersion Include="MonoGameHtml" Version="1.0.1-alpha" />Directory.Packages.props
<PackageReference Include="MonoGameHtml" />Project file
paket add MonoGameHtml --version 1.0.1-alpha
#r "nuget: MonoGameHtml, 1.0.1-alpha"
#:package MonoGameHtml@1.0.1-alpha
#addin nuget:?package=MonoGameHtml&version=1.0.1-alpha&prereleaseInstall as a Cake Addin
#tool nuget:?package=MonoGameHtml&version=1.0.1-alpha&prereleaseInstall as a Cake Tool
MonoGameHtml is a library that brings React-like HTML-based UI development to the MonoGame environment using C#.
Note: Although it may look like it, no Javascript is used. MonoGameHtml is intended for use with C#.
Essentially, this package serves as an extension to the C# language in which Html UI-nodes can be easily created with embedded C# fragments within MonoGame projects.
UI-components are defined in a functional manner (borrowing some JS syntax):
const App = () => {
var fruitList = new List<string> {'apple', 'orange', 'banana'};
return (
<div backgroundColor='white' @fill>
<h4 color='blue'>Comprehensive List of Fruit:</h4>
<div marginLeft={20}>
{fruitList.map(fruit =>
<p>{fruit}</p>
)}
</div>
</div>
);
}
using System;
using System.IO;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using MonoGameHtml;
namespace Example {
public class Game1 : Game {
private GraphicsDeviceManager _graphics;
private SpriteBatch _spriteBatch;
public HtmlRunner htmlInstance;
public Game1() {
_graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
IsMouseVisible = true;
}
protected override void Initialize() {
base.Initialize();
InitializeHtml();
}
private async void InitializeHtml() {
// HtmlMain MUST be initialized with the Game instance.
HtmlMain.Initialize(this);
// this is how you pass in outside variables (without using static access)
// note: the name provided must be prefaced by a dollar sign when used in UI-code (ex. $exampleVariable)
StatePack pack = StatePack.Create(
"exampleVariable", 10
);
// components can be defined either in strings or .monohtml files
const string components = @"
const App = () => {
var fruitList = new List<string> {'apple', 'orange', 'banana'};
return (
<div backgroundColor='white' @fill>
<h4 color='blue'>Comprehensive List of Fruit:</h4>
{fruitList.map(fruit =>
<p>{fruit}</p>
)}
</div>
);
}
";
// this compiles the components provided and creates a runnable HTML Instance.
htmlInstance = await HtmlProcessor.GenerateRunner("<App/>", pack,
components: HtmlComponents.Create(components));
}
protected override void LoadContent() {
_spriteBatch = new SpriteBatch(GraphicsDevice);
}
protected override void Update(GameTime gameTime) {
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed ||
Keyboard.GetState().IsKeyDown(Keys.Escape))
Exit();
base.Update(gameTime);
// updates html (uses a GameTime, MouseState, and KeyState)
htmlInstance?.Update(gameTime, Mouse.GetState(), Keyboard.GetState());
}
protected override void Draw(GameTime gameTime) {
GraphicsDevice.Clear(Color.CornflowerBlue);
base.Draw(gameTime);
// renders html (uses a Spritebatch)
htmlInstance?.Render(_spriteBatch);
}
}
}
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 net5.0 was computed. net5.0-windows net5.0-windows was computed. net6.0 net6.0 was computed. net6.0-android net6.0-android was computed. net6.0-ios net6.0-ios was computed. net6.0-maccatalyst net6.0-maccatalyst was computed. net6.0-macos net6.0-macos was computed. net6.0-tvos net6.0-tvos was computed. net6.0-windows net6.0-windows was computed. net7.0 net7.0 was computed. net7.0-android net7.0-android was computed. net7.0-ios net7.0-ios was computed. net7.0-maccatalyst net7.0-maccatalyst was computed. net7.0-macos net7.0-macos was computed. net7.0-tvos net7.0-tvos was computed. net7.0-windows net7.0-windows was computed. net8.0 net8.0 was computed. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 was computed. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 was computed. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
| .NET Core | netcoreapp3.1 netcoreapp3.1 is compatible. |
This package is not used by any NuGet packages.
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.0.1-alpha | 351 | 7/2/2022 |
| 1.0.0-alpha | 254 | 6/16/2022 |
Removed use of hard-coded path for loading default resources; upgraded Microsoft.CodeAnalysis dependencies to 3.11.0; slightly modified API for setting CSS.