//internal void ForceUpdatePropertyNameAndPath(int? newIndex) //{ // if (newIndex != null) // { // this.Index = newIndex.Value; // } // this.unityPropertyPath = null; // this.prefabModificationPath = null; // if (this.Parent != null) // { // this.Path = this.Parent.Children.GetPath(this.Index); // } // else // { // this.Path = this.Info.PropertyName; // } // // Children may be null, as this may be called before the property has ever updated itself // if (this.Children != null) // { // this.Children.ClearCaches(); // for (int i = 0; i < this.Children.Count; i++) // { // this.Children[i].ForceUpdatePropertyNameAndPath(null); // } // } //} internal static InspectorProperty Create(PropertyTree tree, InspectorProperty parent, InspectorPropertyInfo info, int index, bool isSecretRoot) { // Validate parameters first if (tree == null) { throw new ArgumentNullException("tree"); } if (info == null) { throw new ArgumentNullException("info"); } if (parent != null) { if (tree != parent.Tree) { throw new ArgumentException("The given tree and the given parent's tree are not the same tree."); } if (index < 0 || index >= parent.Children.Count) { throw new IndexOutOfRangeException("The given index for the property to create is out of bounds."); } } // Now start building a property InspectorProperty property = new InspectorProperty(); // Set some basic values property.Tree = tree; property.Info = info; property.Parent = parent; property.Index = index; property.Context = new PropertyContextContainer(property); // Find property path { if (parent != null) { property.Path = parent.Children.GetPath(index); } else { property.Path = info.PropertyName; } if (property.Path == null) { Debug.Log("Property path is null for property " + ObjectNames.NicifyVariableName(info.PropertyName.TrimStart('#', '$')) + "!"); } } // Find parent value property if (parent != null) { InspectorProperty current = property; do { current = current.Parent; }while (current != null && current.BaseValueEntry == null); property.ParentValueProperty = current; } // Set parent type and values if (property.ParentValueProperty != null) { property.ParentType = property.ParentValueProperty.ValueEntry.TypeOfValue; property.ParentValues = new ImmutableList(property.ParentValueProperty.ValueEntry.WeakValues); } else { property.ParentType = tree.TargetType; property.ParentValues = new ImmutableList(tree.WeakTargets); } // Find serializing/owning property { InspectorProperty current = property.ParentValueProperty; while (current != null && !current.ValueEntry.TypeOfValue.InheritsFrom(typeof(UnityEngine.Object))) { current = current.ParentValueProperty; } if (current != null) { property.SerializationRoot = current; } else { property.SerializationRoot = isSecretRoot ? property : tree.SecretRootProperty; } } // Set name and label { property.Name = info.PropertyName; var mi = property.Info.GetMemberInfo() as MethodInfo; if (mi != null) { var name = property.Name; var parensIndex = name.IndexOf('('); if (parensIndex >= 0) { name = name.Substring(0, parensIndex); } property.NiceName = name.TrimStart('#', '$').SplitPascalCase(); } else { property.NiceName = ObjectNames.NicifyVariableName(property.Name.TrimStart('#', '$')); } property.Label = new GUIContent(property.NiceName); } // Create a value entry if necessary if (property.Info.PropertyType == PropertyType.Value) { property.BaseValueEntry = PropertyValueEntry.Create(property, info.TypeOfValue, isSecretRoot); property.ValueEntry = property.BaseValueEntry; } // Do NOT update the property here. Property updating may cause this property to be requested before // it has been registered, resulting in an infinite loop. It is the calling code's responsibility to // update the property before usage. if (!isSecretRoot) { property.RefreshProcessedAttributes(); property.ChildResolver = tree.PropertyResolverLocator.GetResolver(property); property.Children = new PropertyChildren(property); } return(property); }
internal static InspectorProperty Create(PropertyTree tree, InspectorProperty parent, InspectorPropertyInfo info, int index) { // Validate parameters first if (tree == null) { throw new ArgumentNullException("tree"); } if (info == null) { if (parent == null) { throw new ArgumentException("A parent is expected when the given InspectorPropertyInfo is null."); } if (parent.Children.IsCollection == false) { throw new ArgumentException("The children of the given parent must be from a collection when the given InspectorPropertyInfo is null."); } } if (parent != null) { if (tree != parent.Tree) { throw new ArgumentException("The given tree and the given parent's tree are not the same tree."); } if (parent.Children is DisabledPropertyChildren) { throw new ArgumentException("A given parent must be able to have children to create a child property for it."); } if (index < 0 || index >= parent.Children.Count) { throw new IndexOutOfRangeException("The given index for the property to create is out of bounds."); } } else { index = -1; } // Now start building a property InspectorProperty property = new InspectorProperty(); property.Tree = tree; if (parent != null) { property.Path = parent.Children.GetPath(index); } else { property.Path = info.PropertyName; } property.Parent = parent; property.Index = index; property.Context = new PropertyContextContainer(property); if (property.Path == null) { Debug.Log("Property path is null for property " + property.NiceName + "!"); } { InspectorProperty current = property; do { current = current.Parent; }while (current != null && current.BaseValueEntry == null); property.ParentValueProperty = current; } if (property.ParentValueProperty != null) { property.ParentType = property.ParentValueProperty.ValueEntry.TypeOfValue; property.ParentValues = new ImmutableList(property.ParentValueProperty.ValueEntry.WeakValues); } else { property.ParentType = tree.TargetType; property.ParentValues = new ImmutableList(tree.WeakTargets); } if (info != null) { property.Info = info; property.Name = info.PropertyName; property.NiceName = ObjectNames.NicifyVariableName(property.Name.TrimStart('#')); property.Label = new GUIContent(property.NiceName); } else { // Collection elements inherit the info of the collection itself // and have their name set a little further down property.Info = parent.Info; } if (property.Info.PropertyType == PropertyType.ValueType || property.Info.PropertyType == PropertyType.ReferenceType) { property.BaseValueEntry = PropertyValueEntry.Create(property, InspectorProperty.GetBaseContainedValueType(property)); property.ValueEntry = property.BaseValueEntry; } if (info == null) { property.ForceUpdatePropertyNameAndPath(index); } // Do NOT update the property here. Property updating may cause this property to be requested before // it has been registered, resulting in an infinite loop. It is the calling code's responsibility to // update the property before usage. return(property); }