protected override void CommandEventHandling()
        {
            base.CommandEventHandling();

            if (e.type != EventType.ExecuteCommand && e.type != EventType.ValidateCommand)
            {
                return;
            }

            var execute = e.type == EventType.ExecuteCommand;

            if (e.commandName == "Delete" || e.commandName == "SoftDelete")
            {
                if (execute)
                {
                    GameObjectOperations.Delete(selectedGameObjects);
                }

                e.Use();
                GUIUtility.ExitGUI();
            }
            else if (e.commandName == "Duplicate")
            {
                if (execute)
                {
                    GameObjectOperations.Duplicate(selectedGameObjects);
                    Reload();
                    selectedGameObjects = Selection.gameObjects;
                }

                e.Use();
                GUIUtility.ExitGUI();
            }
            else if (e.commandName == "Copy")
            {
                if (execute)
                {
                    GameObjectOperations.Copy(selectedGameObjects);
                }

                e.Use();
                GUIUtility.ExitGUI();
            }
            else if (e.commandName == "Paste")
            {
                if (execute)
                {
                    GameObjectOperations.Paste(selectedGameObjects);
                }

                e.Use();
                GUIUtility.ExitGUI();
            }
        }
            public GameObjectItem(GameObject gameObject)
            {
                Ensure.That(nameof(gameObject)).IsNotNull(gameObject);
                this.gameObject = gameObject;
                id          = gameObject.GetInstanceID();
                displayName = gameObject.name;
                icon        = gameObject.gameObject.Icon()?[IconSize.Small];
                style       = HierarchyStyles.Label(PrefabUtility.IsPartOfPrefabInstance(gameObject), PrefabUtility.IsPrefabAssetMissing(gameObject), !gameObject.activeInHierarchy);

                if (PrefabUtility.IsAddedGameObjectOverride(gameObject))
                {
                    overlay = PeekPlugin.Icons.prefabOverlayAdded?[IconSize.Small];
                }

                canOpenPrefab = GameObjectOperations.CanOpenPrefab(gameObject);
            }
Exemple #3
0
        private static void Replace(MenuCommand menuCommand)
        {
            var targets = GetTargets(menuCommand);

            if (enqueuedMultiTargetsCommand)
            {
                return;
            }

            enqueuedMultiTargetsCommand = true;

            GuiCallback.Enqueue(() =>
            {
                GameObjectOperations.Replace(targets, activatorPosition);
                enqueuedMultiTargetsCommand = false;
            });
        }
Exemple #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();
            }
        }
Exemple #5
0
        private static void CreateChild(MenuCommand menuCommand)
        {
            var target = GetTarget(menuCommand);

            GuiCallback.Enqueue(() => { GameObjectOperations.CreateChild(target, activatorPosition); });
        }
Exemple #6
0
        private static void CreatePrefab(MenuCommand menuCommand)
        {
            var target = GetTarget(menuCommand);

            GuiCallback.Enqueue(() => { GameObjectOperations.CreatePrefab(target); });
        }
Exemple #7
0
        private static void Replace(MenuCommand menuCommand)
        {
            var targets = GetTargets(menuCommand);

            GuiCallback.Enqueue(() => { GameObjectOperations.Replace(targets, activatorPosition); });
        }
        private void GameObjectRowContentGUI(Rect rowPosition, Rect contentPosition, GameObjectItem item, RowGUIArgs args)
        {
            var openPrefabButtonPosition = new Rect
                                           (
                rowPosition.xMax - HierarchyStyles.openPrefabButton.fixedWidth - HierarchyStyles.openPrefabButton.margin.right,
                rowPosition.y,
                HierarchyStyles.openPrefabButton.fixedWidth,
                HierarchyStyles.openPrefabButton.fixedHeight
                                           );

            if (item.canOpenPrefab)
            {
                if (GUI.Button(openPrefabButtonPosition, GUIContent.none, HierarchyStyles.openPrefabButton))
                {
                    GameObjectOperations.OpenPrefab(item.gameObject);
                    parentWindow?.Close();
                    GUIUtility.ExitGUI();
                    return;
                }
            }

            contentPosition.xMax = openPrefabButtonPosition.xMin;

            var iconPosition = new Rect
                               (
                contentPosition.x,
                contentPosition.y,
                IconSize.Small,
                IconSize.Small
                               );

            if (PeekPlugin.Configuration.enablePreviewIcons && PreviewUtility.TryGetPreview(item.gameObject, out var preview) && preview != null)
            {
                GUI.DrawTexture(iconPosition, preview);
            }
            else if (item.icon != null)
            {
                GUI.DrawTexture(iconPosition, item.icon);
            }

            if (item.overlay != null)
            {
                GUI.DrawTexture(iconPosition, item.overlay);
            }

            var labelPosition = contentPosition;

            labelPosition.xMin += iconPosition.width;
            labelPosition.xMin += 2;

            var label = item.displayName;

            if (hasSearch)
            {
                label = SearchUtility.HighlightQuery(label, searchString);
            }

            if (e.type == EventType.Repaint)
            {
                item.style.Draw(labelPosition, label, false, false, args.selected, args.focused);
            }

            var target = item.gameObject;

            if (target == null)
            {
                return;
            }

            Object[] targets;

            if (args.selected)
            {
                targets = GetSelection().Where(i => FindItem(i, rootItem) is GameObjectItem).Select(i => FindGameObjectItem(i).gameObject).ToArray();
            }
            else
            {
                targets = new[] { target.gameObject };
            }

            TreeViewToolbars.Draw(false, toolbarControlProvider, target, targets, args.selected, args.label, contentPosition, rowPosition, HasFocus());
        }