lyra-wasm-scripting-test/guests/csharp/dotnet-guest-test/ExampleWorldImpl.cs

53 lines
1.7 KiB
C#
Raw Permalink Normal View History

2024-11-07 23:10:57 +00:00
namespace ExampleWorld;
using ExampleWorld.wit.imports.lyra.api;
using LyraApi.Asset;
2024-11-10 00:13:15 +00:00
using LyraApi.Ecs;
using LyraApi.Engine;
using LyraApi.Math;
public class ExampleWorldImpl : IExampleWorld
{
public static void OnInit(IEcs.EcsWorld gameWorld, IEcs.Entity owningEntity)
{
var world = new World(gameWorld);
Entity entity = world.Spawn(new Vec3(7.0f, 30.0f, 18.0f));
Console.WriteLine("C#: Spawned entity with id {0}", entity.Id);
foreach ((Entity en, Vec3 comp) in world.View<Vec3>())
{
Console.WriteLine("C#: Found entity at ({0}, {1}, {2})", comp.X, comp.Y, comp.Z);
}
2024-11-10 00:13:15 +00:00
/* DeltaTime? dt = world.GetResource<DeltaTime>();
2024-11-10 00:13:15 +00:00
if (dt != null) {
Console.WriteLine($"C#: Delta time: {dt?.Seconds:0.##}");
} */
AssetManager? man = world.GetResource<AssetManager>();
if (man != null) {
Handle<ImageHandle> han = man.Request<ImageHandle>("test_assets/white.png");
Console.WriteLine($"C#: Asset uuid: {han.Uuid}");
// wait for asset to load before trying to get the data
han.WaitForLoadRecursive();
if (!han.IsLoaded)
{
Console.WriteLine("C#: Asset is still not loaded, even after waiting!");
}
// will be null if the image hasn't loaded yet
ImageHandle? img = han.GetData();
Console.WriteLine($"C#: Size of image: ({img?.Width}, {img?.Height})");
}
else
{
Console.WriteLine("C#: No manager found");
2024-11-10 00:13:15 +00:00
}
}
public static void OnUpdate(IEcs.EcsWorld gameWorld, IEcs.Entity owningEntity)
{
throw new NotImplementedException();
}
}