using Coral.Managed.Interop; using System; using System.Reflection.Metadata; namespace Nuake.Net { public class Scene { internal static unsafe delegate* GetEntityIcall; internal static unsafe delegate* unmanaged*, void> GetEntityScriptFromNameIcall; internal static unsafe delegate*> GetEntityScriptFromHandleIcall; internal static unsafe delegate* InstancePrefabIcall; public static T? GetEntity(string entityName) where T : class { NativeInstance handle; // This doesnt :( unsafe { GetEntityScriptFromNameIcall(entityName, &handle); } object? entity = handle.Get(); Engine.Log("Fetched entityL: " + entity); if (entity != null && entity is T) { return entity as T; } return null; } public static T? GetEntity(int entityHandle) where T : class { NativeInstance handle; unsafe { handle = GetEntityScriptFromHandleIcall(entityHandle); } Entity? entity = handle.Get(); if (entity != null && entity is T) { return entity as T; } return null; } public static Entity GetEntity(string entityName) { int handle; unsafe { handle = GetEntityIcall(entityName); } if (handle == -1) { throw new Exception("Entity not found"); } Entity entity = new Entity(handle); return entity; } public static T? InstancePrefab(string path, Entity? parent = null) where T : class { int handle; unsafe { handle = InstancePrefabIcall(path); } if (handle == -1) { return null; } //NativeInstance nativeInstance; //unsafe { nativeInstance = GetEntityScriptFromHandleIcall(handle); } // //Entity? entity = nativeInstance.Get(); //if (entity != null && entity is T) //{ // return entity as T; //} NativeInstance nativeInstance; unsafe { nativeInstance = GetEntityScriptFromHandleIcall(handle); } Entity? entity = nativeInstance.Get(); if (entity != null && entity is T) { return entity as T; } return null; } } }