[unity] Fix SpineAttributes not seeing sibling fields in arrays and serialized structs/classes.

This commit is contained in:
pharan 2017-05-19 08:45:44 +08:00
parent f9c04584c3
commit 3fe876adcd
2 changed files with 18 additions and 5 deletions

View File

@ -74,7 +74,7 @@ namespace Spine.Unity.Editor {
return; return;
} }
var dataField = property.serializedObject.FindProperty(TargetAttribute.dataField); var dataField = property.FindBaseOrSiblingProperty(TargetAttribute.dataField);
if (dataField != null) { if (dataField != null) {
if (dataField.objectReferenceValue is SkeletonDataAsset) { if (dataField.objectReferenceValue is SkeletonDataAsset) {
skeletonDataAsset = (SkeletonDataAsset)dataField.objectReferenceValue; skeletonDataAsset = (SkeletonDataAsset)dataField.objectReferenceValue;
@ -108,7 +108,7 @@ namespace Spine.Unity.Editor {
} }
public ISkeletonComponent GetTargetSkeletonComponent (SerializedProperty property) { public ISkeletonComponent GetTargetSkeletonComponent (SerializedProperty property) {
var dataField = property.serializedObject.FindProperty(TargetAttribute.dataField); var dataField = property.FindBaseOrSiblingProperty(TargetAttribute.dataField);
if (dataField != null) { if (dataField != null) {
var skeletonComponent = dataField.objectReferenceValue as ISkeletonComponent; var skeletonComponent = dataField.objectReferenceValue as ISkeletonComponent;
@ -282,10 +282,9 @@ namespace Spine.Unity.Editor {
menu.AddSeparator(""); menu.AddSeparator("");
} }
Skin defaultSkin = data.Skins.Items[0]; Skin defaultSkin = data.Skins.Items[0];
var slotProperty = property.FindBaseOrSiblingProperty(TargetAttribute.slotField);
SerializedProperty slotProperty = property.serializedObject.FindProperty(targetAttribute.slotField);
string slotMatch = ""; string slotMatch = "";
if (slotProperty != null) { if (slotProperty != null) {
if (slotProperty.propertyType == SerializedPropertyType.String) if (slotProperty.propertyType == SerializedPropertyType.String)
@ -369,7 +368,7 @@ namespace Spine.Unity.Editor {
if (string.IsNullOrEmpty(atlasAssetFieldName)) if (string.IsNullOrEmpty(atlasAssetFieldName))
atlasAssetFieldName = "atlasAsset"; atlasAssetFieldName = "atlasAsset";
atlasProp = property.serializedObject.FindProperty(atlasAssetFieldName); atlasProp = property.FindBaseOrSiblingProperty(atlasAssetFieldName);
if (atlasProp == null) { if (atlasProp == null) {
EditorGUI.LabelField(position, "ERROR:", "Must have AtlasAsset variable!"); EditorGUI.LabelField(position, "ERROR:", "Must have AtlasAsset variable!");

View File

@ -79,6 +79,20 @@ namespace Spine.Unity.Editor {
return EditorGUIUtility.ObjectContent(null, type).image as Texture2D; 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 #region Layout Scopes
static GUIStyle grayMiniLabel; static GUIStyle grayMiniLabel;
public static GUIStyle GrayMiniLabel { public static GUIStyle GrayMiniLabel {