From aaf997116bfd596572832ee97852e41303d1a804 Mon Sep 17 00:00:00 2001 From: Cameron Date: Sun, 28 Jul 2024 17:05:18 -0700 Subject: [PATCH] feat: Added some API to get LDtkFields point transform components --- .../Runtime/Fields/LDtkFieldElement.cs | 24 +++++++++ .../Runtime/Fields/LDtkFieldsPublicAPI.cs | 49 +++++++++++++++++++ 2 files changed, 73 insertions(+) diff --git a/Assets/LDtkUnity/Runtime/Fields/LDtkFieldElement.cs b/Assets/LDtkUnity/Runtime/Fields/LDtkFieldElement.cs index 9a7e50d83..4cbe381d5 100644 --- a/Assets/LDtkUnity/Runtime/Fields/LDtkFieldElement.cs +++ b/Assets/LDtkUnity/Runtime/Fields/LDtkFieldElement.cs @@ -178,6 +178,30 @@ public FieldsResult GetEnumValue() where TEnum : struct LDtkDebug.LogError($"C# enum \"{type.Name}\" does not define enum value \"{_string}\". Possible values are \"{joined}\""); return result; } + + public FieldsResult GetPointValueTransform() + { + FieldsResult result = GetData(_vector2, LDtkFieldType.Point); + if (!result.Success) + { + return FieldsResult.Null(); + } + if (_obj is Transform transform) + { + return new FieldsResult() + { + Success = true, + Value = transform + }; + } + //it's okay to return null + return new FieldsResult() + { + Success = true, + Value = null + }; + } + public FieldsResult GetPointValue() { FieldsResult result = GetData(_vector2, LDtkFieldType.Point); diff --git a/Assets/LDtkUnity/Runtime/Fields/LDtkFieldsPublicAPI.cs b/Assets/LDtkUnity/Runtime/Fields/LDtkFieldsPublicAPI.cs index 4999b5088..be04b5aa9 100644 --- a/Assets/LDtkUnity/Runtime/Fields/LDtkFieldsPublicAPI.cs +++ b/Assets/LDtkUnity/Runtime/Fields/LDtkFieldsPublicAPI.cs @@ -461,6 +461,16 @@ public LDtkDefinitionObjectField GetDefinition(string identifier) /// The field's value. If the field doesn't exist, then returns a default value type. /// public Vector2 GetPoint(string identifier) => GetFieldSingle(identifier, LDtkFieldType.Point, element => element.GetPointValue()); + /// + /// Gets a point field's value as transform. + /// + /// + /// The field instance's identifier. Case sensitive. + /// + /// + /// The field's value. If the field doesn't exist, then returns a default value type. + /// + public Transform GetPointTransform(string identifier) => GetFieldSingle(identifier, LDtkFieldType.Point, element => element.GetPointValueTransform()); /// /// Gets a point field's value. @@ -476,6 +486,20 @@ public LDtkDefinitionObjectField GetDefinition(string identifier) /// public bool TryGetPoint(string identifier, out Vector2 value) => TryGetFieldSingle(identifier, LDtkFieldType.Point, element => element.GetPointValue(), out value); + /// + /// Gets a point field's value as transform. + /// + /// + /// The field instance's identifier. Case sensitive. + /// + /// + /// The field's value. + /// + /// + /// If the field exists. + /// + public bool TryGetPointTransform(string identifier, out Transform value) => TryGetFieldSingle(identifier, LDtkFieldType.Point, element => element.GetPointValueTransform(), out value); + /// /// Gets a point field's values. /// @@ -487,6 +511,31 @@ public LDtkDefinitionObjectField GetDefinition(string identifier) /// public Vector2[] GetPointArray(string identifier) => GetFieldArray(identifier, LDtkFieldType.Point, element => element.GetPointValue()); + /// + /// Gets a point field's values as transforms. + /// + /// + /// The field instance's identifier. Case sensitive. + /// + /// + /// The field's value. If the field doesn't exist, then returns a default value type. + /// + public Transform[] GetPointTransformArray(string identifier) => GetFieldArray(identifier, LDtkFieldType.Point, element => element.GetPointValueTransform()); + + /// + /// Gets a point field's values as transforms. + /// + /// + /// The field instance's identifier. Case sensitive. + /// + /// + /// The field's values. + /// + /// + /// If the field exists. + /// + public bool TryGetPointTransformArray(string identifier, out Transform[] values) => TryGetFieldArray(identifier, LDtkFieldType.Point, element => element.GetPointValueTransform(), out values); + /// /// Gets a point field's values. ///