diff --git a/GlitchyEngine/src/Scripting/ScriptGlue.bf b/GlitchyEngine/src/Scripting/ScriptGlue.bf index 305e90c..52a0c5b 100644 --- a/GlitchyEngine/src/Scripting/ScriptGlue.bf +++ b/GlitchyEngine/src/Scripting/ScriptGlue.bf @@ -459,6 +459,26 @@ static class ScriptGlue #endregion #region TransformComponent + + [RegisterCall("ScriptGlue::Transform_GetParent")] + static void Transform_GetParent(UUID entityId, out UUID parentId) + { + Scene scene = ScriptEngine.Context; + Entity entity = scene.GetEntityByID(entityId); + + parentId = entity.Parent?.UUID ?? .Zero; + } + + [RegisterCall("ScriptGlue::Transform_SetParent")] + static void Transform_SetParent(UUID entityId, in UUID parentId) + { + Scene scene = ScriptEngine.Context; + Entity entity = scene.GetEntityByID(entityId); + + Entity? parent = GetEntitySafe(parentId); + + entity.Parent = parent; + } [RegisterCall("ScriptGlue::Transform_GetTranslation")] static void Transform_GetTranslation(UUID entityId, out float3 translation) diff --git a/ScriptCore/Core/Transform.cs b/ScriptCore/Core/Transform.cs index 462631a..c4b06c6 100644 --- a/ScriptCore/Core/Transform.cs +++ b/ScriptCore/Core/Transform.cs @@ -9,6 +9,20 @@ namespace GlitchyEngine.Core; /// public class Transform : Component { + public Entity? Parent + { + get + { + ScriptGlue.Transform_GetParent(Entity.UUID, out UUID parentId); + + if (parentId == UUID.Zero) + return null; + + return new Entity(parentId); + } + set => ScriptGlue.Transform_SetParent(Entity.UUID, value?._uuid ?? UUID.Zero); + } + /// /// Gets or sets the translation (position) of the entity. /// diff --git a/ScriptCore/ScriptGlue.cs b/ScriptCore/ScriptGlue.cs index 57e2d01..5357f3e 100644 --- a/ScriptCore/ScriptGlue.cs +++ b/ScriptCore/ScriptGlue.cs @@ -67,6 +67,12 @@ internal static class ScriptGlue #region TransformComponent + [MethodImpl(MethodImplOptions.InternalCall)] + internal static extern void Transform_GetParent(UUID entityId, out UUID parentId); + + [MethodImpl(MethodImplOptions.InternalCall)] + internal static extern void Transform_SetParent(UUID entityId, in UUID parentId); + [MethodImpl(MethodImplOptions.InternalCall)] internal static extern void Transform_GetTranslation(UUID entityId, out float3 translation);