143 lines
3.9 KiB
C#
143 lines
3.9 KiB
C#
namespace XCEngine
|
|
{
|
|
public sealed class GameObject : Object
|
|
{
|
|
private readonly ulong m_uuid;
|
|
|
|
internal GameObject(ulong uuid)
|
|
{
|
|
m_uuid = uuid;
|
|
}
|
|
|
|
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;
|
|
set => InternalCalls.GameObject_SetName(UUID, value ?? string.Empty);
|
|
}
|
|
|
|
public string name
|
|
{
|
|
get => Name;
|
|
set => Name = value;
|
|
}
|
|
|
|
public string Tag
|
|
{
|
|
get => InternalCalls.GameObject_GetTag(UUID) ?? string.Empty;
|
|
set => InternalCalls.GameObject_SetTag(UUID, value ?? string.Empty);
|
|
}
|
|
|
|
public string tag
|
|
{
|
|
get => Tag;
|
|
set => Tag = value;
|
|
}
|
|
|
|
public int Layer
|
|
{
|
|
get => InternalCalls.GameObject_GetLayer(UUID);
|
|
set => InternalCalls.GameObject_SetLayer(UUID, value);
|
|
}
|
|
|
|
public int layer
|
|
{
|
|
get => Layer;
|
|
set => Layer = value;
|
|
}
|
|
|
|
public bool activeSelf => InternalCalls.GameObject_GetActiveSelf(UUID);
|
|
|
|
public bool activeInHierarchy => InternalCalls.GameObject_GetActiveInHierarchy(UUID);
|
|
|
|
public void SetActive(bool value)
|
|
{
|
|
InternalCalls.GameObject_SetActive(UUID, value);
|
|
}
|
|
|
|
public void Destroy()
|
|
{
|
|
InternalCalls.GameObject_Destroy(UUID);
|
|
}
|
|
|
|
public bool CompareTag(string tag)
|
|
{
|
|
return InternalCalls.GameObject_CompareTag(UUID, tag ?? string.Empty);
|
|
}
|
|
|
|
public Transform Transform => GetComponent<Transform>();
|
|
public Transform transform => Transform;
|
|
|
|
public bool HasComponent<T>() where T : Component
|
|
{
|
|
return InternalCalls.GameObject_HasComponent(UUID, typeof(T));
|
|
}
|
|
|
|
public T GetComponent<T>() where T : Component
|
|
{
|
|
return InternalCalls.GameObject_GetComponent(UUID, typeof(T)) as T;
|
|
}
|
|
|
|
public T[] GetComponents<T>() where T : Component
|
|
{
|
|
Component[] components = InternalCalls.GameObject_GetComponents(UUID, typeof(T));
|
|
if (components == null || components.Length == 0)
|
|
{
|
|
return System.Array.Empty<T>();
|
|
}
|
|
|
|
if (components is T[] typedComponents)
|
|
{
|
|
return typedComponents;
|
|
}
|
|
|
|
T[] result = new T[components.Length];
|
|
for (int index = 0; index < components.Length; ++index)
|
|
{
|
|
result[index] = components[index] as T;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
public T GetComponentInChildren<T>() where T : Component
|
|
{
|
|
return InternalCalls.GameObject_GetComponentInChildren(UUID, typeof(T)) as T;
|
|
}
|
|
|
|
public T GetComponentInParent<T>() where T : Component
|
|
{
|
|
return InternalCalls.GameObject_GetComponentInParent(UUID, typeof(T)) as T;
|
|
}
|
|
|
|
public T AddComponent<T>() where T : Component
|
|
{
|
|
return InternalCalls.GameObject_AddComponent(UUID, typeof(T)) as T;
|
|
}
|
|
|
|
public bool TryGetComponent<T>(out T component) where T : Component
|
|
{
|
|
component = GetComponent<T>();
|
|
return component != null;
|
|
}
|
|
}
|
|
}
|