feat(scripting): add runtime gameobject lifecycle api
This commit is contained in:
@@ -11,6 +11,23 @@ namespace XCEngine
|
||||
|
||||
public ulong UUID => m_uuid;
|
||||
|
||||
public static GameObject Find(string name)
|
||||
{
|
||||
ulong uuid = InternalCalls.GameObject_Find(name ?? string.Empty);
|
||||
return uuid != 0 ? new GameObject(uuid) : null;
|
||||
}
|
||||
|
||||
public static GameObject Create(string name)
|
||||
{
|
||||
return Create(name, null);
|
||||
}
|
||||
|
||||
public static GameObject Create(string name, GameObject parent)
|
||||
{
|
||||
ulong uuid = InternalCalls.GameObject_Create(name ?? string.Empty, parent?.UUID ?? 0);
|
||||
return uuid != 0 ? new GameObject(uuid) : null;
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get => InternalCalls.GameObject_GetName(UUID) ?? string.Empty;
|
||||
@@ -32,6 +49,11 @@ namespace XCEngine
|
||||
InternalCalls.GameObject_SetActive(UUID, value);
|
||||
}
|
||||
|
||||
public void Destroy()
|
||||
{
|
||||
InternalCalls.GameObject_Destroy(UUID);
|
||||
}
|
||||
|
||||
public Transform Transform => GetComponent<Transform>();
|
||||
public Transform transform => Transform;
|
||||
|
||||
|
||||
@@ -41,6 +41,15 @@ namespace XCEngine
|
||||
[MethodImpl(MethodImplOptions.InternalCall)]
|
||||
internal static extern ulong GameObject_AddComponent(ulong gameObjectUUID, Type componentType);
|
||||
|
||||
[MethodImpl(MethodImplOptions.InternalCall)]
|
||||
internal static extern ulong GameObject_Find(string name);
|
||||
|
||||
[MethodImpl(MethodImplOptions.InternalCall)]
|
||||
internal static extern ulong GameObject_Create(string name, ulong parentGameObjectUUID);
|
||||
|
||||
[MethodImpl(MethodImplOptions.InternalCall)]
|
||||
internal static extern void GameObject_Destroy(ulong gameObjectUUID);
|
||||
|
||||
[MethodImpl(MethodImplOptions.InternalCall)]
|
||||
internal static extern bool Behaviour_GetEnabled(ulong scriptComponentUUID);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user