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

38 lines
1.1 KiB
C#
Raw Permalink Normal View History

using LyraApi.Ecs;
using ExampleWorld.wit.imports.lyra.api;
using System.Numerics;
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:
var handle = IAsset.AssetManager.FromEcsResource(result.AsWasmResource) ?? throw new MismatchedResourceResultException();
return new AssetManager(handle);
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>();
}
}