This commit is contained in:
antopilo
2024-09-21 14:02:20 -04:00
parent 8079c47832
commit 0e750bda89
3 changed files with 60 additions and 17 deletions

View File

@@ -301,6 +301,22 @@ namespace Nuake.Net
return entity;
}
public T? Instance<T>(Vector3 position = default, Quaternion quat = default) where T : Entity
{
int handle;
unsafe { handle = PrefabInstanceIcall(Path, position, quat.X, quat.Y, quat.Z, quat.W); }
if (handle == -1)
{
return null;
}
T? instance = Scene.GetEntity<T>(handle);
instance.OnInit();
return instance;
}
public static implicit operator bool(Prefab prefab)
{
if (object.ReferenceEquals(prefab, null))

View File

@@ -54,7 +54,7 @@ namespace Nuake.Net
return entity;
}
public static Entity? InstancePrefab(string path, Entity? parent = null)
public static T? InstancePrefab<T>(string path, Entity? parent = null) where T : class
{
int handle;
unsafe { handle = InstancePrefabIcall(path); }
@@ -73,9 +73,17 @@ namespace Nuake.Net
// return entity as T;
//}
Entity entity = new Entity(handle);
NativeInstance<Entity> nativeInstance;
unsafe { nativeInstance = GetEntityScriptFromHandleIcall(handle); }
return entity;
Entity? entity = nativeInstance.Get();
if (entity != null && entity is T)
{
return entity as T;
}
return null;
}
}
}