[unity] Fix FindBaseOrSiblingProperty.

This commit is contained in:
John 2018-03-27 10:14:42 +08:00 committed by GitHub
parent 17ce8d5bcf
commit 9bf12a4299
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -92,26 +92,30 @@ namespace Spine.Unity.Editor {
// If base property is not found, look for the sibling property. // If base property is not found, look for the sibling property.
if (relativeProperty == null) { if (relativeProperty == null) {
string propertyPath = property.propertyPath; string propertyPath = property.propertyPath;
int localPathLength = 0; int localPathLength = property.name.Length;
if (property.isArray) { string newPropertyPath = propertyPath.Remove(propertyPath.Length - localPathLength, localPathLength) + propertyName;
const int internalArrayPathLength = 14; // int arrayPathLength = ".Array.data[x]".Length; relativeProperty = property.serializedObject.FindProperty(newPropertyPath);
// If a direct sibling property was not found, try to find the sibling of the array.
if (relativeProperty == null && property.isArray) {
int propertyPathLength = propertyPath.Length; int propertyPathLength = propertyPath.Length;
int n = propertyPathLength - internalArrayPathLength;
// Find the dot before the array property name and int dotCount = 0;
// store the total length from the name of the array until the end of the propertyPath. const int siblingOfListDotCount = 3;
for (int i = internalArrayPathLength + 1; i < n; i++) { for (int i = 1; i < propertyPathLength; i++) {
if (propertyPath[propertyPathLength - i] == '.') { if (propertyPath[propertyPathLength - i] == '.') {
dotCount++;
if (dotCount >= siblingOfListDotCount) {
localPathLength = i - 1; localPathLength = i - 1;
break; break;
} }
} }
} else {
localPathLength = property.name.Length;
} }
propertyPath = propertyPath.Remove(propertyPath.Length - localPathLength, localPathLength) + propertyName; newPropertyPath = propertyPath.Remove(propertyPath.Length - localPathLength, localPathLength) + propertyName;
relativeProperty = property.serializedObject.FindProperty(propertyPath); relativeProperty = property.serializedObject.FindProperty(newPropertyPath);
}
} }
return relativeProperty; return relativeProperty;