From 3fe876adcd9bcf6a382bff5628ffe4d4d7786e1a Mon Sep 17 00:00:00 2001 From: pharan Date: Fri, 19 May 2017 08:45:44 +0800 Subject: [PATCH] [unity] Fix SpineAttributes not seeing sibling fields in arrays and serialized structs/classes. --- .../spine-unity/Editor/SpineAttributeDrawers.cs | 9 ++++----- .../spine-unity/Editor/SpineInspectorUtility.cs | 14 ++++++++++++++ 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/spine-unity/Assets/spine-unity/Editor/SpineAttributeDrawers.cs b/spine-unity/Assets/spine-unity/Editor/SpineAttributeDrawers.cs index 2cf555c1b..efa9c180b 100644 --- a/spine-unity/Assets/spine-unity/Editor/SpineAttributeDrawers.cs +++ b/spine-unity/Assets/spine-unity/Editor/SpineAttributeDrawers.cs @@ -74,7 +74,7 @@ namespace Spine.Unity.Editor { return; } - var dataField = property.serializedObject.FindProperty(TargetAttribute.dataField); + var dataField = property.FindBaseOrSiblingProperty(TargetAttribute.dataField); if (dataField != null) { if (dataField.objectReferenceValue is SkeletonDataAsset) { skeletonDataAsset = (SkeletonDataAsset)dataField.objectReferenceValue; @@ -108,7 +108,7 @@ namespace Spine.Unity.Editor { } public ISkeletonComponent GetTargetSkeletonComponent (SerializedProperty property) { - var dataField = property.serializedObject.FindProperty(TargetAttribute.dataField); + var dataField = property.FindBaseOrSiblingProperty(TargetAttribute.dataField); if (dataField != null) { var skeletonComponent = dataField.objectReferenceValue as ISkeletonComponent; @@ -282,10 +282,9 @@ namespace Spine.Unity.Editor { menu.AddSeparator(""); } - Skin defaultSkin = data.Skins.Items[0]; + var slotProperty = property.FindBaseOrSiblingProperty(TargetAttribute.slotField); - SerializedProperty slotProperty = property.serializedObject.FindProperty(targetAttribute.slotField); string slotMatch = ""; if (slotProperty != null) { if (slotProperty.propertyType == SerializedPropertyType.String) @@ -369,7 +368,7 @@ namespace Spine.Unity.Editor { if (string.IsNullOrEmpty(atlasAssetFieldName)) atlasAssetFieldName = "atlasAsset"; - atlasProp = property.serializedObject.FindProperty(atlasAssetFieldName); + atlasProp = property.FindBaseOrSiblingProperty(atlasAssetFieldName); if (atlasProp == null) { EditorGUI.LabelField(position, "ERROR:", "Must have AtlasAsset variable!"); diff --git a/spine-unity/Assets/spine-unity/Editor/SpineInspectorUtility.cs b/spine-unity/Assets/spine-unity/Editor/SpineInspectorUtility.cs index 8f5dd6242..285aff0f6 100644 --- a/spine-unity/Assets/spine-unity/Editor/SpineInspectorUtility.cs +++ b/spine-unity/Assets/spine-unity/Editor/SpineInspectorUtility.cs @@ -79,6 +79,20 @@ namespace Spine.Unity.Editor { return EditorGUIUtility.ObjectContent(null, type).image as Texture2D; } + #region SerializedProperty Helpers + public static SerializedProperty FindBaseOrSiblingProperty (this SerializedProperty property, string propertyName) { + if (string.IsNullOrEmpty(propertyName)) return null; + SerializedProperty relativeProperty = property.serializedObject.FindProperty(propertyName); // baseProperty + if (relativeProperty == null) { // If no baseProperty, find sibling property. + int nameLength = property.name.Length; + string propertyPath = property.propertyPath; + propertyPath = propertyPath.Remove(propertyPath.Length - nameLength, nameLength) + propertyName; + relativeProperty = property.serializedObject.FindProperty(propertyPath); + } + return relativeProperty; + } + #endregion + #region Layout Scopes static GUIStyle grayMiniLabel; public static GUIStyle GrayMiniLabel {