/************************************************************************************************************************/

        /// <summary>Draws the GUI the the target transition's main property.</summary>
        protected virtual void DoMainPropertyGUI(Rect area, out Rect labelArea,
                                                 SerializedProperty rootProperty, SerializedProperty mainProperty)
        {
            labelArea = area;
            if (mainProperty == null)
            {
                return;
            }

            var fullArea = area;

            labelArea = AnimancerGUI.StealFromLeft(ref area, EditorGUIUtility.labelWidth, AnimancerGUI.StandardSpacing);

            var mainPropertyReferenceIsMissing =
                mainProperty.propertyType == SerializedPropertyType.ObjectReference &&
                mainProperty.objectReferenceValue == null;

            var hierarchyMode = EditorGUIUtility.hierarchyMode;

            EditorGUIUtility.hierarchyMode = true;

            if (rootProperty.propertyType == SerializedPropertyType.ManagedReference)
            {
                if (rootProperty.isExpanded || _Mode == Mode.AlwaysExpanded)
                {
                    EditorGUI.indentLevel++;

                    AnimancerGUI.NextVerticalArea(ref fullArea);
                    using (ObjectPool.Disposable.AcquireContent(out var label, mainProperty))
                        EditorGUI.PropertyField(fullArea, mainProperty, label, true);

                    EditorGUI.indentLevel--;
                }
            }
            else
            {
                var indentLevel = EditorGUI.indentLevel;
                EditorGUI.indentLevel = 0;

                EditorGUI.PropertyField(area, mainProperty, GUIContent.none, true);

                EditorGUI.indentLevel = indentLevel;
            }

            EditorGUIUtility.hierarchyMode = hierarchyMode;

            // If the main Object reference was just assigned and all fields were at their type default,
            // reset the value to run its default constructor and field initializers then reassign the reference.
            var reference = mainProperty.objectReferenceValue;

            if (mainPropertyReferenceIsMissing && reference != null)
            {
                mainProperty.objectReferenceValue = null;
                if (Serialization.IsDefaultValueByType(rootProperty))
                {
                    rootProperty.GetAccessor().ResetValue(rootProperty);
                }
                mainProperty.objectReferenceValue = reference;
            }
        }
Beispiel #2
0
        /************************************************************************************************************************/

        private void DoHeaderGUI(Rect area, SerializedProperty property, GUIContent label, bool isPreviewing, out float height)
        {
            area.height = AnimancerGUI.LineHeight;

            DoPreviewButtonGUI(ref area, property, isPreviewing);

            label.text = AnimancerGUI.GetNarrowText(label.text);

            var mainProperty = GetMainProperty(property);

            if (mainProperty != null)
            {
                var mainPropertyReferenceIsMissing =
                    mainProperty.propertyType == SerializedPropertyType.ObjectReference &&
                    mainProperty.objectReferenceValue == null;

                DoPropertyGUI(ref area, property, mainProperty, label);

                // If the main Object reference was just assigned and all fields were at their type default,
                // reset the value to run its default constructor and field initialisers then reassign the reference.
                var reference = mainProperty.objectReferenceValue;
                if (mainPropertyReferenceIsMissing && reference != null)
                {
                    mainProperty.objectReferenceValue = null;
                    if (Serialization.IsDefaultValueByType(property))
                    {
                        Serialization.ResetValue(property);
                    }
                    mainProperty.objectReferenceValue = reference;
                }

                if (_Mode != Mode.AlwaysExpanded)
                {
                    var hierarchyMode = EditorGUIUtility.hierarchyMode;
                    EditorGUIUtility.hierarchyMode = true;

                    property.isExpanded = EditorGUI.Foldout(area, property.isExpanded, GUIContent.none, true);

                    EditorGUIUtility.hierarchyMode = hierarchyMode;
                }
            }
            else
            {
                area.height = EditorGUI.GetPropertyHeight(property, label, false);
                if (_Mode != Mode.AlwaysExpanded)
                {
                    EditorGUI.PropertyField(area, property, label, false);
                }
                else
                {
                    label = EditorGUI.BeginProperty(area, label, property);
                    EditorGUI.LabelField(area, label);
                    EditorGUI.EndProperty();
                }
            }

            height = area.height;
        }