Esempio n. 1
0
        internal override bool OnOptimizedInspectorGUI(Rect contentRect)
        {
            m_SerializedObject.UpdateIfRequiredOrScript();

            bool childrenAreExpanded = true;
            bool wasEnabled          = GUI.enabled;
            var  visibleRect         = GUIClip.visibleRect;
            var  contentOffset       = contentRect.y;

            if (Event.current.type != EventType.Repaint)
            {
                visibleRect = m_LastVisibleRect;
            }

            // Release keyboard focus before scrolling so that the virtual scrolling focus wrong control.
            if (Event.current.type == EventType.ScrollWheel)
            {
                GUIUtility.keyboardControl = 0;
            }

            var property = m_SerializedObject.GetIterator();
            var isInspectorModeNormal = inspectorMode == InspectorMode.Normal;

            while (property.NextVisible(childrenAreExpanded))
            {
                var handler = ScriptAttributeUtility.GetHandler(property);
                contentRect.height = handler.GetHeight(property, null, false);

                if (contentRect.Overlaps(visibleRect))
                {
                    EditorGUI.indentLevel = property.depth;
                    using (new EditorGUI.DisabledScope(isInspectorModeNormal && "m_Script" == property.propertyPath))
                        childrenAreExpanded = handler.OnGUI(contentRect, property, null, false, visibleRect) && property.isExpanded;
                }
                else
                {
                    childrenAreExpanded = property.isExpanded && EditorGUI.HasVisibleChildFields(property);
                }

                contentRect.y += contentRect.height + EditorGUI.kControlVerticalSpacing;
            }

            // Fix new height
            if (Event.current.type == EventType.Repaint)
            {
                m_LastVisibleRect = visibleRect;
                var newHeight = contentRect.y - contentOffset;
                if (newHeight != m_LastHeight)
                {
                    m_LastHeight = contentRect.y - contentOffset;
                    Repaint();
                }
            }

            GUI.enabled = wasEnabled;
            return(m_SerializedObject.ApplyModifiedProperties());
        }
        public float GetHeight(SerializedProperty property, GUIContent label, bool includeChildren)
        {
            float height = 0;

            if (m_DecoratorDrawers != null && !isCurrentlyNested)
            {
                foreach (DecoratorDrawer drawer in m_DecoratorDrawers)
                {
                    height += drawer.GetHeight();
                }
            }

            if (propertyDrawer != null)
            {
                height += propertyDrawer.GetPropertyHeightSafe(property.Copy(), label ?? EditorGUIUtility.TempContent(property.displayName));
            }
            else if (!includeChildren)
            {
                height += EditorGUI.GetSinglePropertyHeight(property, label);
            }
            else
            {
                property = property.Copy();

                // First property with custom label
                height += EditorGUI.GetSinglePropertyHeight(property, label);
                bool childrenAreExpanded = property.isExpanded && EditorGUI.HasVisibleChildFields(property);

                // Loop through all child properties
                var tc = EditorGUIUtility.TempContent(property.displayName);
                if (childrenAreExpanded)
                {
                    SerializedProperty endProperty = property.GetEndProperty();
                    while (property.NextVisible(childrenAreExpanded) && !SerializedProperty.EqualContents(property, endProperty))
                    {
                        height += ScriptAttributeUtility.GetHandler(property).GetHeight(property, tc, true);
                        childrenAreExpanded = false;
                        height += EditorGUI.kControlVerticalSpacing;
                    }
                }
            }

            return(height);
        }
Esempio n. 3
0
        public bool CanCacheInspectorGUI(SerializedProperty property)
        {
            if (m_DecoratorDrawers != null &&
                !isCurrentlyNested &&
                m_DecoratorDrawers.Any(decorator => !decorator.CanCacheInspectorGUI()))
            {
                return(false);
            }

            if (propertyDrawer != null)
            {
                // Retrieve drawer BEFORE increasing nesting.
                PropertyDrawer drawer = propertyDrawer;
                using (var nestingContext = IncrementNestingContext())
                {
                    return(drawer.CanCacheInspectorGUISafe(property.Copy()));
                }
            }

            property = property.Copy();

            bool childrenAreExpanded = property.isExpanded && EditorGUI.HasVisibleChildFields(property);

            // Loop through all child properties
            if (childrenAreExpanded)
            {
                PropertyHandler    handler     = null;
                SerializedProperty endProperty = property.GetEndProperty();
                while (property.NextVisible(childrenAreExpanded) && !SerializedProperty.EqualContents(property, endProperty))
                {
                    if (handler == null)
                    {
                        handler = ScriptAttributeUtility.GetHandler(property);
                    }
                    if (!handler.CanCacheInspectorGUI(property))
                    {
                        return(false);
                    }
                    childrenAreExpanded = false;
                }
            }

            return(true);
        }
        public float GetHeight(SerializedProperty property, GUIContent label, bool includeChildren)
        {
            float num1 = 0.0f;

            if (this.m_DecoratorDrawers != null && !this.isCurrentlyNested)
            {
                using (List <DecoratorDrawer> .Enumerator enumerator = this.m_DecoratorDrawers.GetEnumerator())
                {
                    while (enumerator.MoveNext())
                    {
                        DecoratorDrawer current = enumerator.Current;
                        num1 += current.GetHeight();
                    }
                }
            }
            float num2;

            if (this.propertyDrawer != null)
            {
                num2 = num1 + this.propertyDrawer.GetPropertyHeightSafe(property.Copy(), label ?? EditorGUIUtility.TempContent(property.displayName));
            }
            else if (!includeChildren)
            {
                num2 = num1 + EditorGUI.GetSinglePropertyHeight(property, label);
            }
            else
            {
                property = property.Copy();
                SerializedProperty endProperty = property.GetEndProperty();
                num2 = num1 + EditorGUI.GetSinglePropertyHeight(property, label);
                bool enterChildren = property.isExpanded && EditorGUI.HasVisibleChildFields(property);
                while (property.NextVisible(enterChildren) && !SerializedProperty.EqualContents(property, endProperty))
                {
                    float num3 = num2 + ScriptAttributeUtility.GetHandler(property).GetHeight(property, EditorGUIUtility.TempContent(property.displayName), true);
                    enterChildren = false;
                    num2          = num3 + 2f;
                }
            }
            return(num2);
        }
Esempio n. 5
0
        public float GetHeight(SerializedProperty property, GUIContent label, bool includeChildren)
        {
            float num = 0f;

            if (this.m_DecoratorDrawers != null)
            {
                foreach (DecoratorDrawer current in this.m_DecoratorDrawers)
                {
                    num += current.GetHeight();
                }
            }
            if (this.propertyDrawer != null)
            {
                num += this.propertyDrawer.GetPropertyHeightSafe(property.Copy(), label ?? EditorGUIUtility.TempContent(property.displayName));
            }
            else
            {
                if (!includeChildren)
                {
                    num += EditorGUI.GetSinglePropertyHeight(property, label);
                }
                else
                {
                    property = property.Copy();
                    SerializedProperty endProperty = property.GetEndProperty();
                    num += EditorGUI.GetSinglePropertyHeight(property, label);
                    bool enterChildren = property.isExpanded && EditorGUI.HasVisibleChildFields(property);
                    while (property.NextVisible(enterChildren) && !SerializedProperty.EqualContents(property, endProperty))
                    {
                        num          += ScriptAttributeUtility.GetHandler(property).GetHeight(property, EditorGUIUtility.TempContent(property.displayName), true);
                        enterChildren = false;
                        num          += 2f;
                    }
                }
            }
            return(num);
        }
        internal override bool OnOptimizedInspectorGUI(Rect contentRect)
        {
            bool childrenAreExpanded = true;
            bool wasEnabled          = GUI.enabled;
            var  visibleRect         = GUIClip.visibleRect;
            var  contentOffset       = contentRect.y;

            contentRect.xMin += InspectorWindow.kInspectorPaddingLeft;
            contentRect.xMax -= InspectorWindow.kInspectorPaddingRight;
            contentRect.y    += EditorGUI.kControlVerticalSpacing;

            var property = m_SerializedObject.GetIterator();
            var isInspectorModeNormal = m_InspectorMode == InspectorMode.Normal;

            while (property.NextVisible(childrenAreExpanded))
            {
                var handler = ScriptAttributeUtility.GetHandler(property);
                contentRect.height = handler.GetHeight(property, null, false);

                if (contentRect.Overlaps(visibleRect))
                {
                    EditorGUI.indentLevel = property.depth;
                    using (new EditorGUI.DisabledScope(isInspectorModeNormal && "m_Script" == property.propertyPath))
                        childrenAreExpanded = handler.OnGUI(contentRect, property, null, false, visibleRect);
                }
                else
                {
                    childrenAreExpanded = property.isExpanded;
                }

                contentRect.y += contentRect.height + EditorGUI.kControlVerticalSpacing;
            }

            m_LastHeight = contentRect.y - contentOffset;
            GUI.enabled  = wasEnabled;
            return(m_SerializedObject.ApplyModifiedProperties());
        }
        internal bool OnGUI(Rect position, SerializedProperty property, GUIContent label, bool includeChildren, Rect visibleArea)
        {
            float oldLabelWidth, oldFieldWidth;

            float propHeight = position.height;

            position.height = 0;
            if (m_DecoratorDrawers != null && !isCurrentlyNested)
            {
                foreach (DecoratorDrawer decorator in m_DecoratorDrawers)
                {
                    position.height = decorator.GetHeight();

                    oldLabelWidth = EditorGUIUtility.labelWidth;
                    oldFieldWidth = EditorGUIUtility.fieldWidth;
                    decorator.OnGUI(position);
                    EditorGUIUtility.labelWidth = oldLabelWidth;
                    EditorGUIUtility.fieldWidth = oldFieldWidth;

                    position.y += position.height;
                    propHeight -= position.height;
                }
            }

            position.height = propHeight;
            if (propertyDrawer != null)
            {
                // Remember widths
                oldLabelWidth = EditorGUIUtility.labelWidth;
                oldFieldWidth = EditorGUIUtility.fieldWidth;
                // Draw with custom drawer
                propertyDrawer.OnGUISafe(position, property.Copy(), label ?? EditorGUIUtility.TempContent(property.localizedDisplayName));
                // Restore widths
                EditorGUIUtility.labelWidth = oldLabelWidth;
                EditorGUIUtility.fieldWidth = oldFieldWidth;

                return(false);
            }
            else
            {
                if (!includeChildren)
                {
                    return(EditorGUI.DefaultPropertyField(position, property, label));
                }

                // Remember state
                Vector2 oldIconSize = EditorGUIUtility.GetIconSize();
                bool    wasEnabled  = GUI.enabled;
                int     origIndent  = EditorGUI.indentLevel;

                int relIndent = origIndent - property.depth;

                SerializedProperty prop = property.Copy();

                position.height = EditorGUI.GetSinglePropertyHeight(prop, label);

                // First property with custom label
                EditorGUI.indentLevel = prop.depth + relIndent;
                bool childrenAreExpanded = EditorGUI.DefaultPropertyField(position, prop, label) && EditorGUI.HasVisibleChildFields(prop);
                position.y += position.height + EditorGUI.kControlVerticalSpacing;

                // Loop through all child properties
                if (childrenAreExpanded)
                {
                    SerializedProperty endProperty = prop.GetEndProperty();
                    while (prop.NextVisible(childrenAreExpanded) && !SerializedProperty.EqualContents(prop, endProperty))
                    {
                        var handler = ScriptAttributeUtility.GetHandler(prop);
                        EditorGUI.indentLevel = prop.depth + relIndent;
                        position.height       = handler.GetHeight(prop, null, false);

                        if (position.Overlaps(visibleArea))
                        {
                            EditorGUI.BeginChangeCheck();
                            childrenAreExpanded = handler.OnGUI(position, prop, null, false) && EditorGUI.HasVisibleChildFields(prop);
                            // Changing child properties (like array size) may invalidate the iterator,
                            // so stop now, or we may get errors.
                            if (EditorGUI.EndChangeCheck())
                            {
                                break;
                            }
                        }

                        position.y += position.height + EditorGUI.kControlVerticalSpacing;
                    }
                }

                // Restore state
                GUI.enabled = wasEnabled;
                EditorGUIUtility.SetIconSize(oldIconSize);
                EditorGUI.indentLevel = origIndent;

                return(false);
            }
        }
Esempio n. 8
0
        internal override bool GetOptimizedGUIBlock(bool isDirty, bool isVisible, out float height)
        {
            height = -1;

            // Don't use optimizedGUI for audio filters
            var behaviour = target as MonoBehaviour;

            if (behaviour != null && AudioUtil.HasAudioCallback(behaviour) && AudioUtil.GetCustomFilterChannelCount(behaviour) > 0)
            {
                return(false);
            }

            if (ObjectIsMonoBehaviourOrScriptableObject(target))
            {
                return(false);
            }

            if (isDirty)
            {
                ResetOptimizedBlock();
            }

            if (!isVisible)
            {
                height = 0;
                return(true);
            }

            // Return cached result if any.
            if (m_OptimizedBlockState != OptimizedBlockState.CheckOptimizedBlock)
            {
                if (m_OptimizedBlockState == OptimizedBlockState.NoOptimizedBlock)
                {
                    return(false);
                }
                height = m_LastHeight;
                return(true);
            }

            // Update serialized object representation
            if (m_SerializedObject == null)
            {
                m_SerializedObject = new SerializedObject(targets, m_Context)
                {
                    inspectorMode = inspectorMode
                }
            }
            ;
            else
            {
                m_SerializedObject.Update();
                m_SerializedObject.inspectorMode = inspectorMode;
            }

            height = 0;
            SerializedProperty property = m_SerializedObject.GetIterator();
            bool childrenAreExpanded    = true;

            while (property.NextVisible(childrenAreExpanded))
            {
                var handler = ScriptAttributeUtility.GetHandler(property);
                height += handler.GetHeight(property, null, false) + EditorGUI.kControlVerticalSpacing;

                childrenAreExpanded = property.isExpanded && EditorGUI.HasVisibleChildFields(property);
            }

            m_LastHeight          = height;
            m_OptimizedBlockState = OptimizedBlockState.HasOptimizedBlock;

            return(true);
        }
Esempio n. 9
0
        public float GetHeight(SerializedProperty property, GUIContent label, bool includeChildren)
        {
            float height = 0;

            if (m_DecoratorDrawers != null && !isCurrentlyNested)
            {
                foreach (DecoratorDrawer drawer in m_DecoratorDrawers)
                {
                    height += drawer.GetHeight();
                }
            }


            if (propertyDrawer != null)
            {
                // Retrieve drawer BEFORE increasing nesting.
                PropertyDrawer drawer = propertyDrawer;
                using (var nestingContext = IncrementNestingContext())
                {
                    height += drawer.GetPropertyHeightSafe(property.Copy(), label ?? EditorGUIUtility.TempContent(property.localizedDisplayName, tooltip));
                }
            }
            else if (!includeChildren)
            {
                height += EditorGUI.GetSinglePropertyHeight(property, label);
            }
            else if (UseReorderabelListControl(property))
            {
                ReorderableListWrapper reorderableList;
                string key = ReorderableListWrapper.GetPropertyIdentifier(property);

                // If collection doesn't have a ReorderableList assigned to it, create one and assign it
                if (!s_reorderableLists.TryGetValue(key, out reorderableList))
                {
                    reorderableList         = new ReorderableListWrapper(property, label, true);
                    s_reorderableLists[key] = reorderableList;
                }

                reorderableList.Property = property;
                height += s_reorderableLists[key].GetHeight();
                return(height);
            }
            else
            {
                property = property.Copy();

                // First property with custom label
                height += EditorGUI.GetSinglePropertyHeight(property, label);
                bool childrenAreExpanded = property.isExpanded && EditorGUI.HasVisibleChildFields(property);

                // Loop through all child properties
                var tc = EditorGUIUtility.TempContent(property.localizedDisplayName, tooltip);
                if (childrenAreExpanded)
                {
                    SerializedProperty endProperty = property.GetEndProperty();
                    while (property.NextVisible(childrenAreExpanded) && !SerializedProperty.EqualContents(property, endProperty))
                    {
                        height += ScriptAttributeUtility.GetHandler(property).GetHeight(property, tc, true);
                        childrenAreExpanded = false;
                        height += EditorGUI.kControlVerticalSpacing;
                    }
                }
            }

            return(height);
        }
Esempio n. 10
0
        internal bool OnGUI(Rect position, SerializedProperty property, GUIContent label, bool includeChildren, Rect visibleArea)
        {
            TestInvalidateCache();

            float oldLabelWidth, oldFieldWidth;

            float propHeight = position.height;

            position.height = 0;
            if (m_DecoratorDrawers != null && !isCurrentlyNested)
            {
                foreach (DecoratorDrawer decorator in m_DecoratorDrawers)
                {
                    position.height = decorator.GetHeight();

                    oldLabelWidth = EditorGUIUtility.labelWidth;
                    oldFieldWidth = EditorGUIUtility.fieldWidth;
                    decorator.OnGUI(position);
                    EditorGUIUtility.labelWidth = oldLabelWidth;
                    EditorGUIUtility.fieldWidth = oldFieldWidth;

                    position.y += position.height;
                    propHeight -= position.height;
                }
            }

            position.height = propHeight;
            if (propertyDrawer != null)
            {
                // Remember widths
                oldLabelWidth = EditorGUIUtility.labelWidth;
                oldFieldWidth = EditorGUIUtility.fieldWidth;
                // Draw with custom drawer - retrieve it BEFORE increasing nesting.
                PropertyDrawer drawer = propertyDrawer;

                using (var nestingContext = IncrementNestingContext())
                {
                    drawer.OnGUISafe(position, property.Copy(), label ?? EditorGUIUtility.TempContent(property.localizedDisplayName, tooltip));
                }

                // Restore widths
                EditorGUIUtility.labelWidth = oldLabelWidth;
                EditorGUIUtility.fieldWidth = oldFieldWidth;

                return(false);
            }
            else
            {
                if (!includeChildren)
                {
                    return(EditorGUI.DefaultPropertyField(position, property, label));
                }

                if (UseReorderabelListControl(property))
                {
                    ReorderableListWrapper reorderableList;
                    string key = ReorderableListWrapper.GetPropertyIdentifier(property);

                    if (!s_reorderableLists.TryGetValue(key, out reorderableList))
                    {
                        // Manual layout controls don't call GetHeight() method so we need to have a way to initialized list as we prepare to render it here
                        reorderableList         = new ReorderableListWrapper(property, label, true);
                        s_reorderableLists[key] = reorderableList;
                    }

                    // Calculate visibility rect specifically for reorderable list as when applied for the whole serialized object,
                    // it causes collapsed out of sight array elements appear thus messing up scroll-bar experience
                    var screenPos = GUIUtility.GUIToScreenPoint(position.position);

                    screenPos.y = Mathf.Clamp(screenPos.y,
                                              GUIView.current?.screenPosition.yMin ?? 0,
                                              GUIView.current?.screenPosition.yMax ?? Screen.height);

                    Rect listVisibility = new Rect(screenPos.x, screenPos.y,
                                                   GUIView.current?.screenPosition.width ?? Screen.width,
                                                   GUIView.current?.screenPosition.height ?? Screen.height);

                    listVisibility = GUIUtility.ScreenToGUIRect(listVisibility);

                    reorderableList.Property = property;
                    reorderableList.Draw(label, position, listVisibility, tooltip, includeChildren);
                    return(!includeChildren && property.isExpanded);
                }

                // Remember state
                Vector2 oldIconSize = EditorGUIUtility.GetIconSize();
                bool    wasEnabled  = GUI.enabled;
                int     origIndent  = EditorGUI.indentLevel;

                int relIndent = origIndent - property.depth;

                SerializedProperty prop = property.Copy();

                position.height = EditorGUI.GetSinglePropertyHeight(prop, label);

                // First property with custom label
                EditorGUI.indentLevel = prop.depth + relIndent;
                bool childrenAreExpanded = EditorGUI.DefaultPropertyField(position, prop, label) && EditorGUI.HasVisibleChildFields(prop);
                position.y += position.height + EditorGUI.kControlVerticalSpacing;

                // Loop through all child properties
                if (childrenAreExpanded)
                {
                    SerializedProperty endProperty = prop.GetEndProperty();
                    while (prop.NextVisible(childrenAreExpanded) && !SerializedProperty.EqualContents(prop, endProperty))
                    {
                        var handler = ScriptAttributeUtility.GetHandler(prop);
                        EditorGUI.indentLevel = prop.depth + relIndent;
                        position.height       = handler.GetHeight(prop, null, UseReorderabelListControl(prop) && includeChildren);

                        if (position.Overlaps(visibleArea))
                        {
                            EditorGUI.BeginChangeCheck();
                            childrenAreExpanded = handler.OnGUI(position, prop, null, UseReorderabelListControl(prop)) && EditorGUI.HasVisibleChildFields(prop);
                            // Changing child properties (like array size) may invalidate the iterator,
                            // so stop now, or we may get errors.
                            if (EditorGUI.EndChangeCheck())
                            {
                                break;
                            }
                        }

                        position.y += position.height + EditorGUI.kControlVerticalSpacing;
                    }
                }

                // Restore state
                GUI.enabled = wasEnabled;
                EditorGUIUtility.SetIconSize(oldIconSize);
                EditorGUI.indentLevel = origIndent;

                return(false);
            }
        }
Esempio n. 11
0
        public bool OnGUI(Rect position, SerializedProperty property, GUIContent label, bool includeChildren)
        {
            float num = position.height;

            position.height = 0f;
            if (this.m_DecoratorDrawers != null && !this.isCurrentlyNested)
            {
                foreach (DecoratorDrawer current in this.m_DecoratorDrawers)
                {
                    position.height = current.GetHeight();
                    float labelWidth = EditorGUIUtility.labelWidth;
                    float fieldWidth = EditorGUIUtility.fieldWidth;
                    current.OnGUI(position);
                    EditorGUIUtility.labelWidth = labelWidth;
                    EditorGUIUtility.fieldWidth = fieldWidth;
                    position.y += position.height;
                    num        -= position.height;
                }
            }
            position.height = num;
            if (this.propertyDrawer != null)
            {
                float labelWidth = EditorGUIUtility.labelWidth;
                float fieldWidth = EditorGUIUtility.fieldWidth;
                this.propertyDrawer.OnGUISafe(position, property.Copy(), label ?? EditorGUIUtility.TempContent(property.displayName));
                EditorGUIUtility.labelWidth = labelWidth;
                EditorGUIUtility.fieldWidth = fieldWidth;
                return(false);
            }
            if (!includeChildren)
            {
                return(EditorGUI.DefaultPropertyField(position, property, label));
            }
            Vector2            iconSize           = EditorGUIUtility.GetIconSize();
            bool               enabled            = GUI.enabled;
            int                indentLevel        = EditorGUI.indentLevel;
            int                num2               = indentLevel - property.depth;
            SerializedProperty serializedProperty = property.Copy();
            SerializedProperty endProperty        = serializedProperty.GetEndProperty();

            position.height       = EditorGUI.GetSinglePropertyHeight(serializedProperty, label);
            EditorGUI.indentLevel = serializedProperty.depth + num2;
            bool enterChildren = EditorGUI.DefaultPropertyField(position, serializedProperty, label) && EditorGUI.HasVisibleChildFields(serializedProperty);

            position.y += position.height + 2f;
            while (serializedProperty.NextVisible(enterChildren) && !SerializedProperty.EqualContents(serializedProperty, endProperty))
            {
                EditorGUI.indentLevel = serializedProperty.depth + num2;
                position.height       = EditorGUI.GetPropertyHeight(serializedProperty, null, false);
                EditorGUI.BeginChangeCheck();
                enterChildren = (ScriptAttributeUtility.GetHandler(serializedProperty).OnGUI(position, serializedProperty, null, false) && EditorGUI.HasVisibleChildFields(serializedProperty));
                if (EditorGUI.EndChangeCheck())
                {
                    break;
                }
                position.y += position.height + 2f;
            }
            GUI.enabled = enabled;
            EditorGUIUtility.SetIconSize(iconSize);
            EditorGUI.indentLevel = indentLevel;
            return(false);
        }
Esempio n. 12
0
        // returns true if children needs to be drawn separately
        public bool OnGUI(Rect position, SerializedProperty property, GUIContent label, bool includeChildren)
        {
            // We can consider making controlIDs robust to support culling optimizations.
            // Works well - downside is that you can't use PrefixLabel before a PropertyField,
            // but PropertyField has build-in label argument anyway.
            //if (m_Hash == 0)
            //  m_Hash = property.serializedObject.targetObject.GetInstanceID () ^ property.propertyPath.GetHashCode ();
            //EditorGUIUtility.GetControlID (m_Hash, FocusType.Passive);

            float oldLabelWidth, oldFieldWidth;

            float propHeight = position.height;

            position.height = 0;
            if (m_DecoratorDrawers != null && !isCurrentlyNested)
            {
                foreach (DecoratorDrawer decorator in m_DecoratorDrawers)
                {
                    position.height = decorator.GetHeight();

                    oldLabelWidth = EditorGUIUtility.labelWidth;
                    oldFieldWidth = EditorGUIUtility.fieldWidth;
                    decorator.OnGUI(position);
                    EditorGUIUtility.labelWidth = oldLabelWidth;
                    EditorGUIUtility.fieldWidth = oldFieldWidth;

                    position.y += position.height;
                    propHeight -= position.height;
                }
            }

            position.height = propHeight;
            if (propertyDrawer != null)
            {
                // Remember widths
                oldLabelWidth = EditorGUIUtility.labelWidth;
                oldFieldWidth = EditorGUIUtility.fieldWidth;
                // Draw with custom drawer
                propertyDrawer.OnGUISafe(position, property.Copy(), label ?? EditorGUIUtility.TempContent(property.localizedDisplayName));
                // Restore widths
                EditorGUIUtility.labelWidth = oldLabelWidth;
                EditorGUIUtility.fieldWidth = oldFieldWidth;

                return(false);
            }
            else
            {
                if (!includeChildren)
                {
                    return(EditorGUI.DefaultPropertyField(position, property, label));
                }

                // Remember state
                Vector2 oldIconSize = EditorGUIUtility.GetIconSize();
                bool    wasEnabled  = GUI.enabled;
                int     origIndent  = EditorGUI.indentLevel;

                int relIndent = origIndent - property.depth;

                SerializedProperty prop        = property.Copy();
                SerializedProperty endProperty = prop.GetEndProperty();

                position.height = EditorGUI.GetSinglePropertyHeight(prop, label);

                // First property with custom label
                EditorGUI.indentLevel = prop.depth + relIndent;
                bool childrenAreExpanded = EditorGUI.DefaultPropertyField(position, prop, label) && EditorGUI.HasVisibleChildFields(prop);
                position.y += position.height + EditorGUI.kControlVerticalSpacing;

                // Loop through all child properties
                while (prop.NextVisible(childrenAreExpanded) && !SerializedProperty.EqualContents(prop, endProperty))
                {
                    EditorGUI.indentLevel = prop.depth + relIndent;
                    position.height       = EditorGUI.GetPropertyHeight(prop, null, false);
                    EditorGUI.BeginChangeCheck();
                    childrenAreExpanded = ScriptAttributeUtility.GetHandler(prop).OnGUI(position, prop, null, false) && EditorGUI.HasVisibleChildFields(prop);
                    // Changing child properties (like array size) may invalidate the iterator,
                    // so stop now, or we may get errors.
                    if (EditorGUI.EndChangeCheck())
                    {
                        break;
                    }

                    position.y += position.height + EditorGUI.kControlVerticalSpacing;
                }

                // Restore state
                GUI.enabled = wasEnabled;
                EditorGUIUtility.SetIconSize(oldIconSize);
                EditorGUI.indentLevel = origIndent;

                return(false);
            }
        }
Esempio n. 13
0
        internal override bool OnOptimizedInspectorGUI(Rect contentRect)
        {
            m_SerializedObject.UpdateIfRequiredOrScript();

            bool childrenAreExpanded = true;
            bool wasEnabled          = GUI.enabled;
            var  visibleRect         = GUIClip.visibleRect;
            var  contentOffset       = contentRect.y;

            // In some specific cases (e.g. when the inspector field has a dropdown behavior - case 1335344) we need to
            // apply the padding values so it behaves properly. By checking that xMin is zero when we do the assignments,
            // we avoid applying the padding more than once (because this is called more than once in some cases and
            // can lead to wrong indentation - case 1114055).
            if (contentRect.xMin == 0)
            {
                contentRect.xMin  = EditorStyles.kInspectorPaddingLeft;
                contentRect.xMax -= EditorStyles.kInspectorPaddingRight;
            }

            if (Event.current.type != EventType.Repaint)
            {
                visibleRect = m_LastVisibleRect;
            }

            // Release keyboard focus before scrolling so that the virtual scrolling focus wrong control.
            if (Event.current.type == EventType.ScrollWheel)
            {
                GUIUtility.keyboardControl = 0;
            }

            var  behaviour             = target as MonoBehaviour;
            var  property              = m_SerializedObject.GetIterator();
            bool isInspectorModeNormal = inspectorMode == InspectorMode.Normal;
            bool isInPrefabInstance    = PrefabUtility.GetPrefabInstanceHandle(behaviour) != null;
            bool isMultiSelection      = m_SerializedObject.targetObjectsCount > 1;

            using (new LocalizationGroup(behaviour))
            {
                while (property.NextVisible(childrenAreExpanded))
                {
                    var handler           = ScriptAttributeUtility.GetHandler(property);
                    var hasPropertyDrawer = handler.propertyDrawer != null;
                    childrenAreExpanded = !hasPropertyDrawer && property.isExpanded && EditorGUI.HasVisibleChildFields(property);
                    contentRect.height  = handler.GetHeight(property, null, hasPropertyDrawer || PropertyHandler.UseReorderabelListControl(property));

                    if (contentRect.Overlaps(visibleRect))
                    {
                        EditorGUI.indentLevel = property.depth;
                        using (new EditorGUI.DisabledScope((isInspectorModeNormal || isInPrefabInstance || isMultiSelection) && string.Equals("m_Script", property.propertyPath, System.StringComparison.Ordinal)))
                            childrenAreExpanded &= handler.OnGUI(contentRect, property, GetPropertyLabel(property), PropertyHandler.UseReorderabelListControl(property), visibleRect);
                    }

                    if (contentRect.height > 0)
                    {
                        contentRect.y += contentRect.height + EditorGUI.kControlVerticalSpacing;
                    }
                }
            }

            // Fix new height
            if (Event.current.type == EventType.Repaint)
            {
                m_LastVisibleRect = visibleRect;
                var newHeight = contentRect.y - contentOffset;
                if (newHeight != m_LastHeight)
                {
                    m_LastHeight = contentRect.y - contentOffset;
                    Repaint();
                }
            }

            GUI.enabled = wasEnabled;
            return(m_SerializedObject.ApplyModifiedProperties());
        }
        internal override bool GetOptimizedGUIBlock(bool isDirty, bool isVisible, out OptimizedGUIBlock block, out float height)
        {
            block = null; height = -1;

            // Don't use optimizedGUI for audio filters
            var behaviour = target as MonoBehaviour;

            if (behaviour != null && AudioUtil.HasAudioCallback(behaviour) && AudioUtil.GetCustomFilterChannelCount(behaviour) > 0)
            {
                return(false);
            }

            if (IsMissingMonoBehaviourTarget())
            {
                return(false);
            }

            if (isDirty && m_OptimizedBlock != null)
            {
                ResetOptimizedBlock();
            }

            if (!isVisible)
            {
                if (m_OptimizedBlock == null)
                {
                    m_OptimizedBlock = new OptimizedGUIBlock();
                }

                height = 0;
                block  = m_OptimizedBlock;
                return(true);
            }

            // Return cached result if any.
            if (m_OptimizedBlockState != OptimizedBlockState.CheckOptimizedBlock)
            {
                if (m_OptimizedBlockState == OptimizedBlockState.NoOptimizedBlock)
                {
                    return(false);
                }
                height = m_LastHeight;
                block  = m_LastOptimizedBlock;
                return(true);
            }

            // Update serialized object representation
            if (m_SerializedObject == null)
            {
                m_SerializedObject = new SerializedObject(targets, m_Context)
                {
                    inspectorMode = m_InspectorMode
                }
            }
            ;
            else
            {
                m_SerializedObject.Update();
                m_SerializedObject.inspectorMode = m_InspectorMode;
            }

            height = 0;
            SerializedProperty property = m_SerializedObject.GetIterator();

            while (property.NextVisible(height <= 0))
            {
                var handler = ScriptAttributeUtility.GetHandler(property);
                if (!handler.CanCacheInspectorGUI(property))
                {
                    return(ResetOptimizedBlock(OptimizedBlockState.NoOptimizedBlock));
                }

                // Allocate height for control plus spacing below it
                height += handler.GetHeight(property, null, true) + EditorGUI.kControlVerticalSpacing;
            }

            // Allocate height for spacing above first control
            if (height > 0)
            {
                height += EditorGUI.kControlVerticalSpacing;
            }

            if (m_OptimizedBlock == null)
            {
                m_OptimizedBlock = new OptimizedGUIBlock();
            }

            m_LastHeight          = height;
            m_LastOptimizedBlock  = block = m_OptimizedBlock;
            m_OptimizedBlockState = OptimizedBlockState.HasOptimizedBlock;
            return(true);
        }