2026-03-27 13:07:39 +08:00
|
|
|
using System;
|
|
|
|
|
using System.Reflection;
|
|
|
|
|
|
|
|
|
|
namespace XCEngine
|
|
|
|
|
{
|
2026-04-03 14:31:07 +08:00
|
|
|
public abstract class Component : Object
|
2026-03-27 13:07:39 +08:00
|
|
|
{
|
|
|
|
|
internal ulong m_gameObjectUUID;
|
|
|
|
|
|
|
|
|
|
protected Component()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected Component(ulong gameObjectUUID)
|
|
|
|
|
{
|
|
|
|
|
m_gameObjectUUID = gameObjectUUID;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ulong GameObjectUUID => m_gameObjectUUID;
|
|
|
|
|
|
|
|
|
|
public GameObject GameObject => new GameObject(m_gameObjectUUID);
|
|
|
|
|
public GameObject gameObject => GameObject;
|
|
|
|
|
|
|
|
|
|
public Transform Transform => GameObject.Transform;
|
|
|
|
|
public Transform transform => Transform;
|
|
|
|
|
|
2026-04-03 15:10:37 +08:00
|
|
|
public string Tag
|
|
|
|
|
{
|
|
|
|
|
get => GameObject.tag;
|
|
|
|
|
set => GameObject.tag = value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string tag
|
|
|
|
|
{
|
|
|
|
|
get => Tag;
|
|
|
|
|
set => Tag = value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int Layer
|
|
|
|
|
{
|
|
|
|
|
get => GameObject.layer;
|
|
|
|
|
set => GameObject.layer = value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int layer
|
|
|
|
|
{
|
|
|
|
|
get => Layer;
|
|
|
|
|
set => Layer = value;
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-27 13:07:39 +08:00
|
|
|
public bool HasComponent<T>() where T : Component
|
|
|
|
|
{
|
|
|
|
|
return GameObject.HasComponent<T>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public T GetComponent<T>() where T : Component
|
|
|
|
|
{
|
|
|
|
|
return GameObject.GetComponent<T>();
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-03 14:51:52 +08:00
|
|
|
public T[] GetComponents<T>() where T : Component
|
|
|
|
|
{
|
|
|
|
|
return GameObject.GetComponents<T>();
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-03 14:31:07 +08:00
|
|
|
public T GetComponentInChildren<T>() where T : Component
|
|
|
|
|
{
|
|
|
|
|
return GameObject.GetComponentInChildren<T>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public T GetComponentInParent<T>() where T : Component
|
|
|
|
|
{
|
|
|
|
|
return GameObject.GetComponentInParent<T>();
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-27 15:32:37 +08:00
|
|
|
public T AddComponent<T>() where T : Component
|
|
|
|
|
{
|
|
|
|
|
return GameObject.AddComponent<T>();
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-27 13:07:39 +08:00
|
|
|
public bool TryGetComponent<T>(out T component) where T : Component
|
|
|
|
|
{
|
|
|
|
|
component = GetComponent<T>();
|
|
|
|
|
return component != null;
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-03 15:10:37 +08:00
|
|
|
public bool CompareTag(string tag)
|
|
|
|
|
{
|
|
|
|
|
return GameObject.CompareTag(tag);
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-27 13:07:39 +08:00
|
|
|
internal static T Create<T>(ulong gameObjectUUID) where T : Component
|
|
|
|
|
{
|
|
|
|
|
return Create(typeof(T), gameObjectUUID) as T;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal static Component Create(Type componentType, ulong gameObjectUUID)
|
|
|
|
|
{
|
|
|
|
|
if (componentType == null || gameObjectUUID == 0 || !typeof(Component).IsAssignableFrom(componentType))
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return Activator.CreateInstance(
|
|
|
|
|
componentType,
|
|
|
|
|
BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic,
|
|
|
|
|
binder: null,
|
|
|
|
|
args: new object[] { gameObjectUUID },
|
|
|
|
|
culture: null) as Component;
|
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|