Added prefab instancing through C# and support for mid-game rigidbody and skeletal animation

This commit is contained in:
Antoine Pilote
2024-04-23 23:22:19 -04:00
parent f854a2d783
commit 39025d8b06
7 changed files with 173 additions and 62 deletions

View File

@@ -1,5 +1,6 @@
using Coral.Managed.Interop;
using System;
using System.Reflection.Metadata;
namespace Nuake.Net
{
@@ -8,6 +9,7 @@ namespace Nuake.Net
internal static unsafe delegate*<NativeString, int> GetEntityIcall;
internal static unsafe delegate*<NativeString, NativeInstance<Entity>> GetEntityScriptFromNameIcall;
internal static unsafe delegate*<int, NativeInstance<Entity>> GetEntityScriptFromHandleIcall;
internal static unsafe delegate*<NativeString, int> InstancePrefabIcall;
public static T? GetEntity<T>(string entityName) where T : class
{
@@ -22,6 +24,7 @@ namespace Nuake.Net
return null;
}
public static T? GetEntity<T>(int entityHandle) where T : class
{
NativeInstance<Entity> handle;
@@ -53,5 +56,32 @@ namespace Nuake.Net
return entity;
}
public static Entity? InstancePrefab(string path, Entity? parent = null)
{
int handle;
unsafe { handle = InstancePrefabIcall(path); }
if (handle == -1)
{
return null;
}
//NativeInstance<Entity> nativeInstance;
//unsafe { nativeInstance = GetEntityScriptFromHandleIcall(handle); }
//
//Entity? entity = nativeInstance.Get();
//if (entity != null && entity is T)
//{
// return entity as T;
//}
Entity entity = new Entity
{
ECSHandle = handle
};
return entity;
}
}
}