ScriptCore: Added Parent property to Transform

This commit is contained in:
Simon Lübeß
2024-01-25 22:29:11 +01:00
parent 3815b70f06
commit d8e4e8d028
3 changed files with 40 additions and 0 deletions
+20
View File
@@ -460,6 +460,26 @@ static class ScriptGlue
#region TransformComponent #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")] [RegisterCall("ScriptGlue::Transform_GetTranslation")]
static void Transform_GetTranslation(UUID entityId, out float3 translation) static void Transform_GetTranslation(UUID entityId, out float3 translation)
{ {
+14
View File
@@ -9,6 +9,20 @@ namespace GlitchyEngine.Core;
/// </summary> /// </summary>
public class Transform : Component 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);
}
/// <summary> /// <summary>
/// Gets or sets the translation (position) of the entity. /// Gets or sets the translation (position) of the entity.
/// </summary> /// </summary>
+6
View File
@@ -67,6 +67,12 @@ internal static class ScriptGlue
#region TransformComponent #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)] [MethodImpl(MethodImplOptions.InternalCall)]
internal static extern void Transform_GetTranslation(UUID entityId, out float3 translation); internal static extern void Transform_GetTranslation(UUID entityId, out float3 translation);