lyra-wasm-scripting-test/guests/csharp/dotnet-guest-test/LyraApi/Asset/AssetManager.cs

39 lines
1.2 KiB
C#

using LyraApi.Ecs;
using ExampleWorld.wit.imports.lyra.api;
namespace LyraApi.Asset;
public class AssetManager(IAsset.AssetManager assetManager) : IResource
{
internal IAsset.AssetManager inner = assetManager;
public static ulong TypeId => 567234789345;
public static object? FromWasmResult(IEcs.WorldResourceResult result)
{
switch (result.Tag)
{
case IEcs.WorldResourceResult.NONE:
return null;
case IEcs.WorldResourceResult.WASM_RESOURCE_REP:
Console.WriteLine($"Got the resource rep: {result.AsWasmResourceRep}");
var handle = new IAsset.AssetManager.THandle((int)result.AsWasmResourceRep);
var inner = new IAsset.AssetManager(handle);
return new AssetManager(inner);
case IEcs.WorldResourceResult.BYTES:
return null;
default:
return null;
}
}
public UntypedHandle Request(string path)
{
return new UntypedHandle(inner.Request(path));
}
public Handle<T> Request<T>(string path) where T : IAssetHandle
{
return Request(path).AsHandle<T>();
}
}