Exemplo n.º 1
0
        public Shortcut(string label, KeyCode key, bool command = false, bool control = false, bool alt = false, bool shift = false)
        {
            this.label   = label;
            this.keyCode = key;
            this.command = command;
            this.control = control;
            this.alt     = alt;
            this.shift   = shift;

            name = Shortcut.GetName(key, command, control, alt, shift);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Rebuilds the keymaps.
        /// </summary>
        private static void RebuildKeymaps()
        {
            // Loop the shortcut dictionary and build Keymaps
            Keymaps = new Dictionary <string, Action>();
            foreach (KeyValuePair <Action, Shortcut> item in Shortcuts)
            {
                Shortcut sc = item.Value;
                sc.name   = sc.GetName();
                sc.action = item.Key;
//				Debug.Log("Shortcut name: " + sc.name);
                if (!Keymaps.ContainsKey(sc.name))
                {
                    Keymaps.Add(sc.name, item.Key);
                }
            }
        }
Exemplo n.º 3
0
 public string GetName()
 {
     return(Shortcut.GetName(keyCode, command, control, alt, shift));
 }
Exemplo n.º 4
0
        private static void OnSceneGUI(SceneView sceneView)
        {
            // Set the text
            _viewportMode        = sceneView.in2DMode?"2D":"3D";
            _viewportPerspective = sceneView.orthographic?"Orthographic":"Perspective";

            // Selected Object
            if (SceneNavigatorSettings.AroundSelectedObject)
            {
                if (Selection.gameObjects.Length > 1)
                {
                    _viewportName = " < local >";
                    //				GUILayout.Label("< multiple object >");
                }
                else if (Selection.activeGameObject)
                {
//					_viewportName = " < "+Selection.activeGameObject.name+" >";
                    _viewportName = " < local >";
                    //				GUILayout.Label("< "+Selection.activeGameObject.name+" >");
                }
                else
                {
                    _viewportName = " < global >";
                    //				GUILayout.Label("< free >");
                };
            }
            else
            {
                _viewportName = " < global >";
            }

            // Begin drawing UI
            Handles.BeginGUI();
            GUILayout.BeginVertical();
            GUILayout.FlexibleSpace();

            ///-- Navigation UI

            if (SceneNavigatorSettings.ShowNavigationUI)
            {
                GUILayout.BeginHorizontal();
                GUILayout.FlexibleSpace();

                GUILayout.BeginHorizontal(GUILayout.Width(100));

                if (GUILayout.Button(_zoomInTexture, GUI.skin.label, GUILayout.Width(30), GUILayout.Height(30)))
                {
                    PerformAction(Action.ZOOM_IN, sceneView);
                }
                if (GUILayout.Button(_zoomOutTexture, GUI.skin.label, GUILayout.Width(30), GUILayout.Height(30)))
                {
                    PerformAction(Action.ZOOM_OUT, sceneView);
                }
                if (GUILayout.Button(_centerTexture, GUI.skin.label, GUILayout.Width(30), GUILayout.Height(30)))
                {
                    Center(sceneView, Vector3.zero);
                }
                GUILayout.EndHorizontal();
                GUILayout.EndHorizontal();
            }

            /// View Mode Buttons

            GUILayout.BeginHorizontal();

            // View Mode
            //			GUILayout.Label(_viewportMode + " / " + _viewportName + " (" + _viewportPerspective + ")");
            GUILayout.Label(_viewportMode + " / " + _viewportPerspective + _viewportName);
            // space
            GUILayout.FlexibleSpace();
            ///-- View Navigation UI
            if (SceneNavigatorSettings.ShowViewNavigationUI)
            {
                int tempViewportNameIndex = GUILayout.Toolbar(_viewportNameIndex, _viewportNameString);

                if (_viewportNameIndex != tempViewportNameIndex)
                {
                    switch (tempViewportNameIndex)
                    {
                    case 0: PerformAction(Action.VIEW_FRONT, sceneView); break;

                    case 1: PerformAction(Action.VIEW_BACK, sceneView); break;

                    case 2: PerformAction(Action.VIEW_TOP, sceneView); break;

                    case 3: PerformAction(Action.VIEW_BOTTOM, sceneView); break;

                    case 4: PerformAction(Action.VIEW_LEFT, sceneView); break;

                    case 5: PerformAction(Action.VIEW_RIGHT, sceneView); break;
                    }
                }
            }

            /// Save/Restore View
            ///
            if (GUILayout.Button("Save"))
            {
                PerformAction(Action.SAVE_CURRENT_VIEW, sceneView);
            }
            GUI.enabled = _hasSavedPosition;
            if (GUILayout.Button("Restore"))
            {
                PerformAction(Action.RESTORE_SAVED_VIEW, sceneView);
            }
            GUI.enabled = true;

            GUILayout.EndHorizontal();            // end bottom panel

            GUILayout.Space(25);
            GUILayout.EndVertical();
            Handles.EndGUI();


            // Process Events

            Event e = Event.current;

            if (e != null)
            {
//				Debug.Log("Event: " + e.type);
                if (e.type == EventType.KeyDown && e.isKey)
                {
                    // Ignore invalid keycode
                    if (e.keyCode == KeyCode.None)
                    {
                        _lastShortcutName = null;

//						Debug.Log("Keycode none");
//						Debug.Log("Camera " + SceneView.lastActiveSceneView.camera.transform.position + " Rotation " + SceneView.lastActiveSceneView.camera.transform.rotation +
//							" Pivot " + SceneView.lastActiveSceneView.pivot + " Rotation " + SceneView.lastActiveSceneView.rotation);
                    }
                    else
                    {
//						Debug.Log("Key " + e.keyCode);
                        string shortcutName = Shortcut.GetName(e.keyCode, e.command, e.control, e.alt, e.shift);

                        // Check if already pressed key
                        if (shortcutName != _lastShortcutName)
                        {
                            _lastShortcutName = shortcutName;
                            if (SceneNavigatorSettings.Keymaps.ContainsKey(shortcutName))
                            {
//								Debug.Log("Key pressed in editor: " + e.keyCode + " name: " + _lastShortcutName + " action: " + SceneNavigatorSettings.Keymaps[shortcutName]);
                                PerformAction(SceneNavigatorSettings.Keymaps[shortcutName], sceneView);
                            }
                        }
                    }
                }
                else if (e.type == EventType.MouseMove && SceneNavigatorSettings.FocusOnMouseMove)
                {
                    sceneView.Focus();
                }
            }
        }