Пример #1
0
        private void HistoryButton(GUIContent content, List <SelectionInfo> stack, List <SelectionInfo> otherStack)
        {
            GUI.enabled = (stack.Count > 0);
            SidekickEditorGUI.ButtonWithOptions(content, out bool mainPressed, out bool optionsPressed);

            if (mainPressed)
            {
                SwapStackElements(stack, otherStack);
            }

            if (optionsPressed)
            {
                GenericMenu genericMenu = new GenericMenu();

                for (var index = 0; index < stack.Count; index++)
                {
                    SelectionInfo selectionInfo = stack[index];
                    genericMenu.AddItem(new GUIContent($"{index} - {selectionInfo.GetDisplayName()}"), false, userData =>
                    {
                        SwapStackElements(stack, otherStack, 1 + (int)userData);
                    }, index);
                }

                genericMenu.DropDown(new Rect(Event.current.mousePosition, Vector2.zero));
            }
        }
Пример #2
0
        public void SetSelection(Type newSelection)
        {
            if (!activeSelection.IsEmpty && !backStack.FirstOrDefault().Equals(activeSelection))
            {
                backStack.Insert(0, activeSelection);
                if (backStack.Count > BACK_STACK_LIMIT)
                {
                    backStack.RemoveAt(backStack.Count - 1);
                }
            }
            forwardStack.Clear();

            activeSelection = new SelectionInfo(newSelection);
        }
Пример #3
0
        void SwapStackElements(List <SelectionInfo> stack, List <SelectionInfo> otherStack, int count = 1)
        {
            SelectionInfo stackPeek = stack[count - 1];

            otherStack.Insert(0, activeSelection);

            for (int i = 0; i < count; i++)
            {
                var temp = stack[0];
                stack.RemoveAt(0);
                if (i < count - 1)
                {
                    otherStack.Insert(0, temp);
                }
            }

            activeSelection = stackPeek;

            if (stackPeek.Object is Object unityObject)
            {
                suppressNextSelectionDetection = true;
                Selection.activeObject         = unityObject;
            }
        }