feat(scripting): add script add-component api

This commit is contained in:
2026-03-27 15:32:37 +08:00
parent 9c94adb4a2
commit f0d6d4f41c
10 changed files with 401 additions and 6 deletions

View File

@@ -34,6 +34,11 @@ namespace XCEngine
return GameObject.GetComponent<T>();
}
public T AddComponent<T>() where T : Component
{
return GameObject.AddComponent<T>();
}
public bool TryGetComponent<T>(out T component) where T : Component
{
component = GetComponent<T>();

View File

@@ -46,6 +46,12 @@ namespace XCEngine
return Component.Create<T>(componentOwnerUUID);
}
public T AddComponent<T>() where T : Component
{
ulong componentOwnerUUID = InternalCalls.GameObject_AddComponent(UUID, typeof(T));
return Component.Create<T>(componentOwnerUUID);
}
public bool TryGetComponent<T>(out T component) where T : Component
{
component = GetComponent<T>();

View File

@@ -38,6 +38,9 @@ namespace XCEngine
[MethodImpl(MethodImplOptions.InternalCall)]
internal static extern ulong GameObject_GetComponent(ulong gameObjectUUID, Type componentType);
[MethodImpl(MethodImplOptions.InternalCall)]
internal static extern ulong GameObject_AddComponent(ulong gameObjectUUID, Type componentType);
[MethodImpl(MethodImplOptions.InternalCall)]
internal static extern bool Behaviour_GetEnabled(ulong scriptComponentUUID);