示例#1
0
        public override void DrawOverlay()
        {
            if (LudiqCore.Configuration.developerMode && LudiqGraphs.Configuration.debug)
            {
                LudiqGUI.DrawEmptyRect(outerPosition, Color.yellow.WithAlpha(0.5f));
                LudiqGUI.DrawEmptyRect(edgePosition, Color.yellow.WithAlpha(0.5f));
                LudiqGUI.DrawEmptyRect(innerPosition, Color.yellow.WithAlpha(0.5f));
            }

            base.DrawOverlay();
        }
示例#2
0
        public static bool EndBlock(Accessor accessor)
        {
            if (blockStack.Count == 0)
            {
                Debug.LogWarning("Ending unstarted inspector block.");
                return(false);
            }

            var block = blockStack.Pop();

            if (block.accessor != accessor)
            {
                Debug.LogWarning($"Inspector block accessor mismatch.\nStarted {block.accessor}, ended {accessor}.");

                if (LudiqCore.Configuration.developerMode && LudiqCore.Configuration.debugInspectorGUI && e.type == EventType.Repaint)
                {
                    LudiqGUI.DrawEmptyRect(block.position, Color.red);
                }
            }
            else
            {
                if (e.type == EventType.ContextClick && block.position.Contains(e.mousePosition))
                {
                    if (block.accessor.isRevertibleToPrefab)
                    {
                        var menu = new GenericMenu();

                        menu.AddItem(new GUIContent($"Revert {block.accessor.label.text} to Prefab"), false, () => { block.accessor.RevertToPrefab(); });

                        menu.ShowAsContext();
                    }

                    e.Use();
                }

                if (LudiqCore.Configuration.developerMode && LudiqCore.Configuration.debugInspectorGUI && e.type == EventType.Repaint)
                {
                    LudiqGUI.DrawEmptyRect(block.position, Color.yellow.WithAlpha(0.5f));
                }
            }

            if (block.bolded)
            {
                LudiqGUIUtility.editorHasBoldFont = false;
            }

            EditorGUI.EndDisabledGroup();
            return(EditorGUI.EndChangeCheck());
        }
            protected override void OnGUI()
            {
                base.OnGUI();

                GUILayout.BeginHorizontal();
                GUILayout.Space(-3);
                GUILayout.BeginVertical();
                GUILayout.Space(-3);
                EditorGUILayout.HelpBox("Components that are only on some of the selected objects cannot be multi-edited.", MessageType.Info);
                GUILayout.Space(-3);
                GUILayout.EndVertical();
                GUILayout.Space(-5);
                GUILayout.EndHorizontal();

                if (e.type == EventType.Repaint)
                {
                    LudiqGUI.DrawEmptyRect(new Rect(Vector2.zero, position.size), ColorPalette.unityBackgroundDark);
                }
            }
示例#4
0
        protected override void OnGUI()
        {
            base.OnGUI();

            if (!Validate())
            {
                return;
            }

            if (e.type == EventType.KeyDown &&
                e.modifiers == EventModifiers.None &&
                e.keyCode == KeyCode.Escape)
            {
                Close();
                return;
            }

            var position = this.position;

            position.x = position.y = 0;
            var height          = 0f;
            var calculateHeight = isPopup;
            var applyHeight     = calculateHeight && e.type == EventType.Repaint;

            var editable = editor.targets.None(t => t.HasHideFlag(HideFlags.NotEditable));

            EditorGUI.BeginChangeCheck();

            GUILayout.BeginVertical(Styles.background, GUILayout.ExpandHeight(true));

            var largeHeader = editor.targets.Any(t => !(t is Component));

            EditorGUIUtility.wideMode = position.width >= 330;

            EditorGUIUtility.hierarchyMode = false;

            GUILayout.BeginHorizontal();

            EditorGUI.BeginDisabledGroup(!editable);

            if (largeHeader)
            {
                GUILayout.BeginVertical();
                GUILayout.Space(0);                 // Fix to stick to top
                editor.DrawHeader();
                GUILayout.EndVertical();
            }
            else
            {
                GUILayout.BeginVertical(Styles.smallHeader);
                GUILayout.Space(EditorGUIUtility.isProSkin && !LudiqGUIUtility.isFlatSkin ? -3 : -4);
                GUILayout.BeginHorizontal();
                GUILayout.Space(-12);
                EditorGUILayout.InspectorTitlebar(true, editor.targets, false);
                GUILayout.EndHorizontal();

                if (LudiqGUIUtility.isFlatSkin)
                {
                    GUILayout.Space(-5);
                }

                GUILayout.EndVertical();
            }

            GUILayout.BeginVertical(Styles.smallHeaderExtra, GUILayout.ExpandHeight(true));

            if (largeHeader)
            {
                GUILayout.Space(6);
            }
            else
            {
                if (LudiqGUIUtility.isFlatSkin)
                {
                    GUILayout.Space(5);
                }
                else
                {
                    if (EditorGUIUtility.isProSkin)
                    {
                        var topBorderRect = GUILayoutUtility.GetRect(GUIContent.none, GUIStyle.none, GUILayout.Width(16), GUILayout.Height(1));
                        topBorderRect.y += 1;
                        EditorGUI.DrawRect(topBorderRect, Color.Lerp(ColorPalette.unityBackgroundLighter, ColorPalette.unityForegroundDim, 0.25f));
                        GUILayout.Space(2);
                    }
                    else
                    {
                        GUILayout.Space(2);
                    }
                }
            }

            EditorGUI.EndDisabledGroup();

            var wantsPin = GUILayout.Toggle(isPinned, GUIContent.none, PeekStyles.pinButton);

            EditorGUI.BeginDisabledGroup(!editable);

            if (isPinned != wantsPin)
            {
                if (wantsPin)
                {
                    Pin();
                }
                else
                {
                    Close();
                }

                GUIUtility.ExitGUI();
            }

            GUILayout.EndVertical();

            if (largeHeader)
            {
                GUILayout.Space(2);
            }

            GUILayout.EndHorizontal();

            if (editor.targets.Length == 1 && editor.targets[0] is GameObject go)
            {
                GUILayout.Space(-1);

                GUILayout.BeginHorizontal(Styles.prefabTools);

                if (PrefabUtility.IsPartOfAnyPrefab(go))
                {
                    GUILayout.Label("Unpack", GUILayout.ExpandWidth(false));

                    if (GUILayout.Button("Root", EditorStyles.miniButtonLeft, GUILayout.ExpandWidth(true)))
                    {
                        PrefabUtility.UnpackPrefabInstance(go, PrefabUnpackMode.OutermostRoot, InteractionMode.UserAction);
                    }

                    if (GUILayout.Button("Completely", EditorStyles.miniButtonRight, GUILayout.ExpandWidth(true)))
                    {
                        PrefabUtility.UnpackPrefabInstance(go, PrefabUnpackMode.Completely, InteractionMode.UserAction);
                    }

                    GUILayout.Space(2);
                    GUILayout.Label("Create", GUILayout.ExpandWidth(false));

                    if (GUILayout.Button("Prefab", EditorStyles.miniButtonLeft, GUILayout.ExpandWidth(true)))
                    {
                        GameObjectOperations.CreateOriginalPrefab(go);
                    }

                    if (GUILayout.Button("Variant", EditorStyles.miniButtonRight, GUILayout.ExpandWidth(true)))
                    {
                        GameObjectOperations.CreatePrefabVariant(go);
                    }
                }
                else
                {
                    GUILayout.Space(LudiqGUIUtility.isFlatSkin ? 4 : 9);
                    GUILayout.Label("Prefab", GUILayout.ExpandWidth(false));

                    if (GUILayout.Button("Create Prefab", EditorStyles.miniButton))
                    {
                        GameObjectOperations.CreatePrefab(go);
                    }
                }

                GUILayout.Space(14);

                GUILayout.EndHorizontal();

                if (LudiqGUIUtility.isFlatSkin)
                {
                    GUILayout.Space(-1);
                }
            }

            if (calculateHeight)
            {
                height += GUILayoutUtility.GetRect(GUIContent.none, GUIStyle.none, GUILayout.Height(0)).yMin;
            }

            EditorGUI.EndDisabledGroup();

            scroll = EditorGUILayout.BeginScrollView(scroll);

            if (!largeHeader)
            {
                GUILayout.Space(3);
            }

            GUILayout.BeginVertical(Styles.inspectorBackground);
            EditorGUIUtility.hierarchyMode = true;
            EditorGUI.BeginDisabledGroup(!editable);
            editor.OnInspectorGUI();
            EditorGUI.EndDisabledGroup();
            GUILayout.EndVertical();

            if (isPinned)
            {
                GUILayout.FlexibleSpace();
            }

            if (HasPreview())
            {
                var previewArea = GUILayoutUtility.GetRect(GUIContent.none, GUIStyle.none, GUILayout.Height(120));
                editor.DrawPreview(previewArea);
            }
            else
            {
                GUILayout.Space(2);
            }

            if (calculateHeight)
            {
                height += GUILayoutUtility.GetRect(GUIContent.none, GUIStyle.none, GUILayout.Height(0)).yMin;
            }

            GUILayout.EndVertical();

            GUILayout.EndScrollView();

            if (applyHeight)
            {
                autoHeight = height;
            }

            if (EditorGUI.EndChangeCheck())
            {
            }

            if (e.type == EventType.KeyDown &&
                e.keyCode == KeyCode.Space)
            {
                if (isPopup)
                {
                    Pin();
                }
                else
                {
                    Close();
                }

                e.Use();
                return;
            }

            if (e.type == EventType.Repaint)
            {
                LudiqGUI.DrawEmptyRect(new Rect(Vector2.zero, this.position.size), ColorPalette.unityBackgroundVeryDark);
            }

            if (editor.RequiresConstantRepaint())
            {
                Repaint();
            }
        }
示例#5
0
        protected override void OnGUI()
        {
            base.OnGUI();

            // Reloaded from serialization
            if (treeView == null)
            {
                Close();
                GUIUtility.ExitGUI();
            }

            // Close on Escape
            if (e.type == EventType.KeyDown && e.modifiers == EventModifiers.None && e.keyCode == KeyCode.Escape)
            {
                Close();
                GUIUtility.ExitGUI();
            }

            var innerPosition = new Rect(0, 0, position.width, position.height);

            // Draw Background
            EditorGUI.DrawRect(innerPosition, ColorPalette.unityBackgroundMid);

            GUILayout.BeginVertical();

            // Draw Search
            GUILayout.BeginHorizontal(LudiqStyles.searchFieldBackground, GUILayout.Height(LudiqStyles.searchFieldOuterHeight), GUILayout.ExpandWidth(true));

            EditorGUI.BeginChangeCheck();

            GUI.SetNextControlName(searchFieldName);

            // Special keyboard controls  while search field is selected
            if (GUI.GetNameOfFocusedControl() == searchFieldName && e.type == EventType.KeyDown)
            {
                // Pass arrow events to tree view
                if (e.keyCode == KeyCode.DownArrow || e.keyCode == KeyCode.UpArrow || !treeView.hasSearch && (e.keyCode == KeyCode.LeftArrow || e.keyCode == KeyCode.RightArrow))
                {
                    var selection = treeView.GetSelection();
                    treeView.SetFocus();
                    treeView.SetSelection(selection);
                }
                // Confirm search with enter
                else if (e.keyCode == KeyCode.Return)
                {
                    if (treeView.SelectActive())
                    {
                        Close();
                        GUIUtility.ExitGUI();
                    }
                    else
                    {
                        e.Use();
                    }
                }
                // Close if pressing space again without search
                else if (e.keyCode == KeyCode.Space && !treeView.hasSearch)
                {
                    Close();
                    GUIUtility.ExitGUI();
                }
            }

            treeView.searchString = EditorGUILayout.TextField(treeView.searchString, LudiqStyles.searchField);

            // Focus on Search
            if (focusSearch && e.type == EventType.Repaint)
            {
                GUI.FocusControl(searchFieldName);
                focusSearch = false;
            }

            // Reload Tree View on Search
            if (EditorGUI.EndChangeCheck())
            {
                treeView.Reload();
            }

            // Search Cancel Button
            if (GUILayout.Button(GUIContent.none, treeView.hasSearch ? LudiqStyles.searchFieldCancelButton : LudiqStyles.searchFieldCancelButtonEmpty) && treeView.hasSearch)
            {
                treeView.searchString = string.Empty;
                treeView.Reload();
                GUIUtility.keyboardControl = 0;
            }

            GUILayout.EndHorizontal();

            // Horizontal Separator
            GUILayout.Box(GUIContent.none, LudiqStyles.horizontalSeparator);

            // Handle special keyboard strokes in tree view
            if (treeView.HasFocus() && e.type == EventType.KeyDown)
            {
                // Select current item
                if (e.keyCode == KeyCode.Space)
                {
                    if (treeView.SelectActive())
                    {
                        Close();
                        GUIUtility.ExitGUI();
                    }
                    else
                    {
                        e.Use();
                    }
                }
                // Move back up to search field
                else if (e.keyCode == KeyCode.UpArrow)
                {
                    if (treeView.GetSelection().FirstOrDefault() == treeView.GetRows().FirstOrDefault()?.id)
                    {
                        focusSearch = true;
                        e.Use();
                    }
                }
                // Delete character from search
                else if (e.keyCode == KeyCode.Backspace)
                {
                    treeView.searchString = treeView.searchString.Substring(0, Mathf.Max(0, treeView.searchString.Length - 1));

                    e.Use();
                }
                // Append characters to search
                else if (e.modifiers == EventModifiers.None && !char.IsWhiteSpace(e.character) && !char.IsControl(e.character))
                {
                    treeView.searchString += e.character;

                    e.Use();
                }
                // Focus search
                else if (e.keyCode == KeyCode.F && e.CtrlOrCmd())
                {
                    focusSearch = true;
                    e.Use();
                }
            }

            // Draw Tree View
            var treeViewPosition = GUILayoutUtility.GetRect(GUIContent.none, GUIStyle.none, GUILayout.ExpandHeight(true), GUILayout.ExpandWidth(true));

            treeView.OnGUI(treeViewPosition);

            // Draw Preview
            previewEditorTargets.Clear();
            previewEditorTargets.AddRange(treeView.GetActiveGameObjects());

            if ((previewEditor == null && previewEditorTargets.Count > 0) ||
                (previewEditor != null && !previewEditorTargets.SequenceEqual(previewEditor.targets)))
            {
                if (previewEditor != null)
                {
                    DestroyImmediate(previewEditor);
                    previewEditor = null;
                }

                previewEditor = UEditor.CreateEditor(previewEditorTargets.ToArray(), null);
            }

            if (previewEditor != null && (previewEditor.HasPreviewGUI() || previewEditorTargets.Any(PreviewUtility.HasPreview)))
            {
                GUILayout.Box(GUIContent.none, LudiqStyles.horizontalSeparator);
                var previewPosition = GUILayoutUtility.GetRect(GUIContent.none, GUIStyle.none, GUILayout.Height(Styles.previewHeight), GUILayout.ExpandWidth(true));
                previewEditor.DrawPreview(previewPosition);
            }

            GUILayout.EndVertical();

            // Draw Border
            if (e.type == EventType.Repaint)
            {
                LudiqGUI.DrawEmptyRect(new Rect(Vector2.zero, position.size), ColorPalette.unityBackgroundVeryDark);
            }

            // Repaint on hover
            if (innerPosition.Contains(e.mousePosition))
            {
                Repaint();
            }
        }
示例#6
0
        private void Draw()
        {
            if (Event.current.type == EventType.Layout)
            {
                UpdateDrawnElements();
            }

            LudiqGUI.BeginVertical(Styles.background);

            LudiqGUI.BeginHorizontal(Styles.tipArea, GUILayout.Height(Styles.tipHeight));

            LudiqGUI.BeginVertical();
            LudiqGUI.FlexibleSpace();
            LudiqGUI.LoaderLayout();
            LudiqGUI.FlexibleSpace();
            LudiqGUI.EndVertical();

            if (drawnTip != null)
            {
                LudiqGUI.Space(Styles.spaceBetweenSpinnerAndTip);

                LudiqGUI.BeginVertical();
                LudiqGUI.FlexibleSpace();
                GUILayout.Label("<b>Tip:</b> " + drawnTip, Styles.tip);
                LudiqGUI.FlexibleSpace();
                LudiqGUI.EndVertical();
            }

            LudiqGUI.EndHorizontal();

            if (drawnTasks.Count > 0)
            {
                var first = true;

                foreach (var task in drawnTasks)
                {
                    if (!first)
                    {
                        GUILayout.Space(Styles.spaceBetweenTasks);
                    }

                    if (Event.current.type == EventType.Layout)
                    {
                        task.animatedRatio = Mathf.MoveTowards(task.animatedRatio, task.ratio, progressAnimationSpeed * repaintDeltaTime);
                    }

                    LudiqGUI.BeginVertical(Styles.task);

                    GUILayout.Label(task.title + $" <color=#{ColorPalette.unityForegroundDim.ToHexString()}>({task.elapsed.TotalSeconds:###0.0} seconds)</color>", Styles.taskTitle);

                    var progressBarPosition = EditorGUILayout.GetControlRect();

                    EditorGUI.ProgressBar(progressBarPosition, task.animatedRatio, null);

                    if (task.stepsHaveStarted)
                    {
                        var currentItemPosition = new Rect
                                                  (
                            progressBarPosition.x + (int)(task.animatedRatio * progressBarPosition.width) - 1,
                            progressBarPosition.y,
                            Mathf.Max(3, Mathf.CeilToInt((1f / task.totalSteps) * (progressBarPosition.width)) + 1),
                            progressBarPosition.height
                                                  );

                        if (Event.current.type == EventType.Repaint)
                        {
                            var opacity = Mathf.Lerp(0.25f, 0.25f, (Mathf.Sin((float)EditorApplication.timeSinceStartup * 3) + 1) / 2);

                            using (LudiqGUI.color.Override(LudiqGUI.color.value.WithAlphaMultiplied(opacity)))
                            {
                                Styles.currentItemFill.Draw(currentItemPosition, false, false, false, false);
                            }
                        }

                        LudiqGUI.DrawEmptyRect(currentItemPosition, Styles.currentItemBorder);

                        if (Event.current.type == EventType.Repaint)
                        {
                            Styles.currentItemText.Draw(progressBarPosition, new GUIContent(task.currentStepLabel), false, false, false, false);
                        }
                    }

                    LudiqGUI.EndVertical();

                    first = false;
                }
            }

            LudiqGUI.EndVertical();
        }
示例#7
0
        private static Rect PrefixLabel(Rect position, GUIContent label, GUIStyle labelStyle, float width, bool wide, bool expandTooltip)
        {
            if (label == GUIContent.none)
            {
                return(position);
            }

            var y = position.y;

            var labelPosition = new Rect
                                (
                position.x,
                position.y,
                width,
                labelStyle.CalcHeight(label, width)
                                );

            y = labelPosition.yMax + 2;

            if (expandTooltip && !string.IsNullOrEmpty(label.tooltip))
            {
                EditorGUI.LabelField(labelPosition, LabelWithoutTooltip(label), labelStyle);

                var tooltip = new GUIContent(label.tooltip);

                var tooltipPosition = new Rect
                                      (
                    position.x,
                    y - 2,
                    width,
                    LudiqStyles.expandedTooltip.CalcHeight(tooltip, width)
                                      );

                EditorGUI.LabelField(tooltipPosition, tooltip, LudiqStyles.expandedTooltip);

                if (LudiqCore.Configuration.developerMode && LudiqCore.Configuration.debugInspectorGUI)
                {
                    LudiqGUI.DrawEmptyRect(tooltipPosition, Color.green.WithAlpha(0.5f));
                }

                y = tooltipPosition.yMax - 4;
            }
            else
            {
                EditorGUI.LabelField(labelPosition, label, labelStyle);
            }

            if (LudiqCore.Configuration.developerMode && LudiqCore.Configuration.debugInspectorGUI)
            {
                LudiqGUI.DrawEmptyRect(labelPosition, Color.cyan.WithAlpha(0.5f));
            }

            Rect remainingPosition;

            if (wide)
            {
                remainingPosition = new Rect
                                    (
                    position.x,
                    y,
                    position.width,
                    position.height - labelPosition.height
                                    );
            }
            else
            {
                remainingPosition = new Rect
                                    (
                    labelPosition.xMax,
                    position.y,
                    position.width - labelPosition.width,
                    position.height
                                    );
            }

            return(remainingPosition);
        }