53 lines
1.7 KiB
C#
53 lines
1.7 KiB
C#
namespace ExampleWorld;
|
|
|
|
using ExampleWorld.wit.imports.lyra.api;
|
|
using LyraApi.Asset;
|
|
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);
|
|
}
|
|
|
|
/* DeltaTime? dt = world.GetResource<DeltaTime>();
|
|
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");
|
|
}
|
|
}
|
|
|
|
public static void OnUpdate(IEcs.EcsWorld gameWorld, IEcs.Entity owningEntity)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
} |