/// <summary> /// Write settings to EditorPrefs. /// </summary> public static void Write() { // Debug.Log("Write"); // Save to editor Prefs EditorPrefs.SetBool(Prefix("ShowNavigationUI"), ShowNavigationUI); EditorPrefs.SetBool(Prefix("ShowViewNavigationUI"), ShowViewNavigationUI); EditorPrefs.SetBool(Prefix("FocusOnMouseMove"), FocusOnMouseMove); EditorPrefs.SetInt(Prefix("RotationSnap"), RotationSnap); EditorPrefs.SetInt(Prefix("ZoomSnap"), ZoomSnap); EditorPrefs.SetBool(Prefix("AroundSelectedObject"), AroundSelectedObject); // Loop the shortcut dictionary and save foreach (KeyValuePair <Action, Shortcut> item in Shortcuts) { Shortcut sc = item.Value; EditorPrefs.SetString(Prefix(sc.action.ToString()), sc.name); } RebuildKeymaps(); }
public static void OnGUI() { // Setup Styles _smallTextStyle = new GUIStyle(GUI.skin.label); _smallTextStyle.fontSize = 9; _smallTextStyle.margin = new RectOffset(0, 0, 0, 0); _smallTextStyle.padding = new RectOffset(0, 5, 0, 0); _smallTextStyle.alignment = TextAnchor.UpperRight; _smallTextStyle.active.background = Texture2D.blackTexture; //new Texture2D(8,8); _titleTextStyle = new GUIStyle(GUI.skin.box); _titleTextStyle.alignment = TextAnchor.MiddleCenter; _titleTextStyle.fontSize = 14; _titleTextStyle.fontStyle = FontStyle.Bold; GUIStyle logoStyle = new GUIStyle(GUI.skin.box); logoStyle.margin = new RectOffset(0, 0, 0, 0); logoStyle.padding = new RectOffset(0, 0, 0, 0); // Check if last shortcut changed if (_lastChangedShortcut != null) { KeyCode currentKey = Event.current.keyCode; // Debug.Log("key code " + currentKey); _lastChangedShortcut.keyCode = currentKey; _lastChangedShortcut = null; } _scrollPos = GUILayout.BeginScrollView(_scrollPos); GUILayout.BeginVertical("box"); /// Title /// Color savedColor = GUI.backgroundColor; GUI.backgroundColor = Color.black; GUILayout.Box(_logoTexture, logoStyle, GUILayout.ExpandWidth(true), GUILayout.Height(70)); GUILayout.Label("\nversion " + SceneNavigator.Version + "\n", _smallTextStyle, GUILayout.ExpandWidth(true)); GUI.backgroundColor = savedColor; /// -- Start of settings UI GUILayout.Box("General Settings", _titleTextStyle, GUILayout.ExpandWidth(true)); GUILayout.Space(10); ShowNavigationUI = GUILayout.Toggle(ShowNavigationUI, "Show Navigation UI"); ShowViewNavigationUI = GUILayout.Toggle(ShowViewNavigationUI, "Show View Navigation Toolbar"); AroundSelectedObject = GUILayout.Toggle(AroundSelectedObject, "Local Transform Mode"); FocusOnMouseMove = GUILayout.Toggle(FocusOnMouseMove, "Focus Keyboard on Mousemove"); GUILayout.Label("Rotation Steps: " + RotationSnap.ToString()); RotationSnap = (int)GUILayout.HorizontalSlider((int)RotationSnap, 1, 90); GUILayout.Label("Zoom Steps: " + ZoomSnap.ToString()); ZoomSnap = (int)GUILayout.HorizontalSlider((int)ZoomSnap, 1, 5); // GUILayout.EndVertical(); #region - Shortcuts - GUILayout.Space(10); GUILayout.Box("Keyboard Shortcuts", _titleTextStyle, GUILayout.ExpandWidth(true)); // header GUILayout.BeginHorizontal(); GUIStyle style = new GUIStyle(GUI.skin.label); style.margin = new RectOffset(3, 10, 10, 3); style.fontStyle = FontStyle.Bold; GUILayout.Label("Shortcut", style, GUILayout.Height(29)); GUILayout.Box(_headerTexture, GUI.skin.label, GUILayout.Width(66), GUILayout.Height(29)); GUILayout.Label("Key", style, GUILayout.Width(70)); GUILayout.EndHorizontal(); GUILayout.Space(5); foreach (KeyValuePair <Action, Shortcut> item in Shortcuts) { string tempKeyString; Shortcut sc = item.Value; GUILayout.BeginHorizontal(); GUILayout.Label(sc.label); sc.command = GUILayout.Toggle(sc.command, "", GUILayout.Width(12)); sc.alt = GUILayout.Toggle(sc.alt, "", GUILayout.Width(12)); sc.control = GUILayout.Toggle(sc.control, "", GUILayout.Width(12)); sc.shift = GUILayout.Toggle(sc.shift, "", GUILayout.Width(12)); tempKeyString = GUILayout.TextField(sc.keyCode.ToString(), GUILayout.Width(80)); GUILayout.EndHorizontal(); if (tempKeyString != sc.keyCode.ToString()) { if (tempKeyString == KeyCode.Escape.ToString() || tempKeyString == KeyCode.Tab.ToString() || tempKeyString == KeyCode.Space.ToString() || tempKeyString == KeyCode.RightShift.ToString() || tempKeyString == KeyCode.LeftShift.ToString() || tempKeyString == KeyCode.RightAlt.ToString() || tempKeyString == KeyCode.LeftAlt.ToString() || tempKeyString == KeyCode.Backspace.ToString() || tempKeyString == KeyCode.Delete.ToString()) { // Do Nothing } else { sc.keyCode = Event.current.keyCode; _lastChangedShortcut = sc; // Debug.Log("key code G" + " new " + Event.current.keyCode); } } } if (GUILayout.Button("Reset Default")) { ResetShortcuts(); } #endregion - Shortcuts - GUILayout.EndVertical(); GUILayout.EndScrollView(); }
public string GetName() { return(Shortcut.GetName(keyCode, command, control, alt, shift)); }
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(); } } }