Added new Prefab C# type

This commit is contained in:
Antoine Pilote
2024-08-15 22:24:26 -04:00
parent 04926476d7
commit 58a179be4f
8 changed files with 181 additions and 14 deletions

View File

@@ -202,4 +202,46 @@ namespace Nuake.Net
return isValid;
}
}
public class Prefab
{
internal static unsafe delegate*<NativeString, Vector3, float, float, float, float, int> PrefabInstanceIcall;
string Path { get; set; }
public Prefab()
{
}
public Prefab(string path)
{
Path = path;
Engine.Log("Prefab instance created with path: " + path);
}
public Entity? Instance(Vector3 position = default, Quaternion quat = default)
{
int handle;
unsafe { handle = PrefabInstanceIcall(Path, position, quat.X, quat.Y, quat.Z, quat.W); }
if (handle == -1)
{
return null;
}
Entity entity = new Entity(handle);
return entity;
}
public static implicit operator bool(Prefab prefab)
{
if (object.ReferenceEquals(prefab, null))
{
return false;
}
return prefab.Path != string.Empty;
}
}
}