2024-11-07 23:10:57 +00:00
|
|
|
|
namespace ExampleWorld;
|
2024-11-05 20:10:19 +00:00
|
|
|
|
|
2024-11-09 02:05:02 +00:00
|
|
|
|
using ExampleWorld.wit.imports.lyra.api;
|
2024-11-12 23:57:46 +00:00
|
|
|
|
using LyraApi.Asset;
|
2024-11-10 00:13:15 +00:00
|
|
|
|
using LyraApi.Ecs;
|
|
|
|
|
using LyraApi.Engine;
|
|
|
|
|
using LyraApi.Math;
|
2024-11-07 02:26:03 +00:00
|
|
|
|
|
2024-11-09 02:05:02 +00:00
|
|
|
|
public class ExampleWorldImpl : IExampleWorld
|
|
|
|
|
{
|
2024-11-07 02:26:03 +00:00
|
|
|
|
public static void OnInit(IEcs.EcsWorld gameWorld, IEcs.Entity owningEntity)
|
2024-11-09 02:05:02 +00:00
|
|
|
|
{
|
2024-11-08 00:28:35 +00:00
|
|
|
|
var world = new World(gameWorld);
|
2024-11-09 02:05:02 +00:00
|
|
|
|
Entity entity = world.Spawn(new Vec3(7.0f, 30.0f, 18.0f));
|
|
|
|
|
Console.WriteLine("C#: Spawned entity with id {0}", entity.Id);
|
2024-11-07 02:26:03 +00:00
|
|
|
|
|
2024-11-09 02:05:02 +00:00
|
|
|
|
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-07 02:26:03 +00:00
|
|
|
|
}
|
2024-11-10 00:13:15 +00:00
|
|
|
|
|
2024-11-12 23:57:46 +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.##}");
|
2024-11-12 23:57:46 +00:00
|
|
|
|
} */
|
|
|
|
|
|
|
|
|
|
AssetManager? man = world.GetAssetManager();
|
|
|
|
|
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
|
|
|
|
}
|
2024-11-07 02:26:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void OnUpdate(IEcs.EcsWorld gameWorld, IEcs.Entity owningEntity)
|
2024-11-05 20:10:19 +00:00
|
|
|
|
{
|
2024-11-07 02:26:03 +00:00
|
|
|
|
throw new NotImplementedException();
|
2024-11-05 20:10:19 +00:00
|
|
|
|
}
|
|
|
|
|
}
|