diff --git a/Assets/LDtkUnity/Runtime/Fields/LDtkFieldElement.cs b/Assets/LDtkUnity/Runtime/Fields/LDtkFieldElement.cs index 9a7e50d8..4cbe381d 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 4999b508..be04b5aa 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. ///