Ejemplo n.º 1
0
        internal static void EndProperty()
        {
            if (s_PropertyStack.Count == 0)
            {
                Debug.LogError("MaterialProperty stack is empty");
                return;
            }
            var data = s_PropertyStack[s_PropertyStack.Count - 1];

            if (data.targets == null)
            {
                s_PropertyStack.RemoveAt(s_PropertyStack.Count - 1);
                return;
            }

            Rect position = data.position;

            if (data.startY != -1)
            {
                position       = GUILayoutUtility.GetLastRect();
                position.yMin  = data.startY;
                position.x     = 1;
                position.width = EditorGUIUtility.labelWidth;
            }

            bool mouseOnLock = false;

            if (position != Rect.zero)
            {
                // Display override rect
                if (data.isOverriden)
                {
                    EditorGUI.DrawMarginLineForRect(position, Styles.overrideLineColor);
                }

                Rect lockRegion = position;
                lockRegion.width  = 14;
                lockRegion.height = 14;
                lockRegion.x      = 11;
                lockRegion.y     += (position.height - lockRegion.height) * 0.5f;
                mouseOnLock       = lockRegion.Contains(Event.current.mousePosition);

                // Display lock icon
                Rect lockRect = position;
                lockRect.width  = 32;
                lockRect.height = Mathf.Max(lockRect.height, 20.0f);
                lockRect.x      = 8;
                lockRect.y     += (position.height - lockRect.height) * 0.5f;

                if (data.isLockedByAncestor)
                {
                    // Make sure we draw the lock only once
                    bool isLastLockInStack = true;
                    for (int i = 0; i < s_PropertyStack.Count - 1; i++)
                    {
                        if (s_PropertyStack[i].isLockedByAncestor)
                        {
                            isLastLockInStack = false;
                            break;
                        }
                    }

                    if (isLastLockInStack)
                    {
                        GUI.Label(lockRect, Styles.lockedByAncestorContent, Styles.centered);
                    }
                }
                else if (data.isLockedInChildren)
                {
                    GUI.Label(lockRect, Styles.lockInChildrenContent, Styles.centered);
                }
                else if (GUI.enabled)
                {
                    GUIView.current?.MarkHotRegion(GUIClip.UnclipToWindow(lockRegion));
                    if (mouseOnLock)
                    {
                        EditorGUI.BeginDisabledGroup(true);
                        GUI.Label(lockRect, Styles.lockInChildrenContent, Styles.centered);
                        EditorGUI.EndDisabledGroup();
                    }
                }
            }

            // Restore state
            EditorGUI.showMixedValue = false;

            EditorGUIUtility.SetBoldDefaultFont(data.wasBoldDefaultFont);

            if (data.isLockedByAncestor)
            {
                EditorGUI.EndDisabledGroup();
            }

            // Context menu
            if (Event.current.rawType == EventType.ContextClick && (position.Contains(Event.current.mousePosition) || mouseOnLock))
            {
                PropertyData.DoPropertyContextMenu(mouseOnLock, data.targets);
            }
            else if (Event.current.type == EventType.MouseUp && Event.current.button == 0 && mouseOnLock)
            {
                PropertyData.DoLockAction(data.targets);
            }

            s_PropertyStack.RemoveAt(s_PropertyStack.Count - 1);
        }