예제 #1
0
        /// <summary>
        /// Triggered when the user presses a virtual button.
        /// </summary>
        /// <param name="btn">Button that was pressed.</param>
        /// <param name="deviceIdx">Index of the device it was pressed on. </param>
        private void OnButtonUp(VirtualButton btn, int deviceIdx)
        {
            if (!HasFocus)
            {
                return;
            }

            IGlobalShortcuts shortcuts = this;

            if (btn == EditorApplication.CopyKey)
            {
                shortcuts.OnCopyPressed();
            }
            else if (btn == EditorApplication.CutKey)
            {
                shortcuts.OnCutPressed();
            }
            else if (btn == EditorApplication.PasteKey)
            {
                shortcuts.OnPastePressed();
            }
            else if (btn == EditorApplication.DuplicateKey)
            {
                shortcuts.OnDuplicatePressed();
            }
            else if (btn == EditorApplication.RenameKey)
            {
                shortcuts.OnRenamePressed();
            }
            else if (btn == EditorApplication.DeleteKey)
            {
                shortcuts.OnDeletePressed();
            }
            else if (btn == EditorApplication.PasteKey)
            {
                shortcuts.OnPastePressed();
            }
        }
예제 #2
0
        /// <summary>
        /// Manually triggers a global shortcut.
        /// </summary>
        /// <param name="btn">Button for the shortcut. If this doesn't correspond to any shortcut, it is ignored.</param>
        internal static void TriggerGlobalShortcut(VirtualButton btn)
        {
            IGlobalShortcuts window = null;

            if (btn != PasteKey)
            {
                // The system ensures elsewhere that only either a resource or a scene object is selected, but not both
                if (Selection.ResourcePaths.Length > 0)
                {
                    window = EditorWindow.GetWindow <LibraryWindow>();
                }
                else if (Selection.SceneObjects.Length > 0)
                {
                    window = EditorWindow.GetWindow <HierarchyWindow>();
                    if (window == null)
                    {
                        window = EditorWindow.GetWindow <SceneWindow>();
                    }
                }

                if (window != null)
                {
                    if (btn == CopyKey)
                    {
                        window.OnCopyPressed();
                    }
                    else if (btn == CutKey)
                    {
                        window.OnCutPressed();
                    }
                    else if (btn == PasteKey)
                    {
                        window.OnPastePressed();
                    }
                    else if (btn == DuplicateKey)
                    {
                        window.OnDuplicatePressed();
                    }
                    else if (btn == RenameKey)
                    {
                        window.OnRenamePressed();
                    }
                    else if (btn == DeleteKey)
                    {
                        window.OnDeletePressed();
                    }
                }
            }
            else
            {
                HierarchyWindow hierarchy = EditorWindow.GetWindow <HierarchyWindow>();
                if (hierarchy != null && hierarchy.HasFocus)
                {
                    window = hierarchy;
                }
                else
                {
                    LibraryWindow library = EditorWindow.GetWindow <LibraryWindow>();
                    if (library != null && library.HasFocus)
                    {
                        window = library;
                    }
                }

                if (window != null)
                {
                    window.OnPastePressed();
                }
            }
        }