Esempio n. 1
0
        private VisualElement CreateFoldout(SerializedProperty property)
        {
            property = property.Copy();
            var foldout = new Foldout()
            {
                text = property.localizedDisplayName
            };

            foldout.value       = property.isExpanded;
            foldout.bindingPath = property.propertyPath;
            foldout.name        = "Foldout:" + property.propertyPath;

            var endProperty = property.GetEndProperty();

            property.NextVisible(true); // Expand the first child.
            do
            {
                if (SerializedProperty.EqualContents(property, endProperty))
                {
                    break;
                }

                var field = new PropertyField(property);
                field.m_ParentPropertyField = this;
                field.name = "PropertyField:" + property.propertyPath;
                if (field == null)
                {
                    continue;
                }

                foldout.Add(field);
            }while (property.NextVisible(false)); // Never expand children.

            return(foldout);
        }
Esempio n. 2
0
        private void CreateDefaultInspector(SerializedObject serializedObject)
        {
            if (serializedObject == null)
            {
                return;
            }

            SerializedProperty property = serializedObject.GetIterator();

            if (property.NextVisible(true)) // Expand first child.
            {
                do
                {
                    var field = new PropertyField(property);
                    field.name = "PropertyField:" + property.propertyPath;
                    shadow.Add(field);
                }while (property.NextVisible(false));
            }
        }
Esempio n. 3
0
        private void UpdateArrayFoldout(
            ChangeEvent <int> changeEvent,
            PropertyField targetPropertyField,
            PropertyField parentPropertyField)
        {
            if (targetPropertyField == null || targetPropertyField.m_SerializedProperty == null)
            {
                return;
            }

            // We need to unbind *first* before we change the array size property value.
            // If we don't, the binding system could try to sync properties that no longer
            // exist - if the array shrunk.
            var parentSerializedObject = parentPropertyField?.m_SerializedProperty?.serializedObject;

            if (parentSerializedObject != null)
            {
                parentPropertyField.Unbind();
            }

            // We're forcefully updating the SerializedProperty value here, even
            // though we have a binding on it, because the very next step is to
            // Rebind() it. The Rebind() will regenerate the field (this field) and
            // bind it to another copy of this property. We need the value to be correct
            // on that copy of this property.
            var serialiedObject = targetPropertyField.m_SerializedProperty.serializedObject;

            serialiedObject.UpdateIfRequiredOrScript();
            targetPropertyField.m_SerializedProperty.intValue = changeEvent.newValue;
            serialiedObject.ApplyModifiedProperties();

            // We rebind the parent property field (which should be the foldout expanded field)
            // so that it regenerates (and rebinds) all array property fields (the new
            // number of them).
            if (parentSerializedObject != null)
            {
                parentPropertyField.Bind(parentSerializedObject);
            }
        }