public void CloseAndSwitch() { if (!instance) { return; } var guid = GetSelectedGUID(); Close(); DestroyImmediate(this); FGCodeWindow.OpenAssetInTab(guid); instance = null; }
public static bool OnGUIGlobal() { if (instance) { instance.OnGUI(); return(true); } else if (Event.current.type == EventType.KeyDown && Event.current.keyCode == KeyCode.Tab) { var isOSX = Application.platform == RuntimePlatform.OSXEditor; if (isOSX) { if (Event.current.alt && !EditorGUI.actionKey) { instance = Create(!Event.current.shift); } return(true); } if (!Event.current.alt && EditorGUI.actionKey) { EditorApplication.update -= DelayedCreateWithShiftKey; EditorApplication.update -= DelayedCreateNoShiftKey; var isShift = Event.current.shift; if (isShift) { EditorApplication.update += DelayedCreateWithShiftKey; } else { EditorApplication.update += DelayedCreateNoShiftKey; } return(true); } } return(false); }
private static void DelayedCreateNoShiftKey() { EditorApplication.update -= DelayedCreateNoShiftKey; instance = Create(true); }
private static void DelayedCreateWithShiftKey() { EditorApplication.update -= DelayedCreateWithShiftKey; instance = Create(false); }
protected void OnGUI() { if (Event.current.isKey && TabSwitcher.OnGUIGlobal()) { return; } EditorWindow console = consoleWindowField.GetValue(null) as EditorWindow; if (console == null) { EditorGUILayout.HelpBox(@"Script Inspector Console can only work when the Console tab is also open. Click the button below to open the Console window...", MessageType.Info); EditorGUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); if (GUILayout.Button("Open Console Widnow")) { GetWindow(consoleWindowType); Focus(); Repaint(); } GUILayout.FlexibleSpace(); EditorGUILayout.EndHorizontal(); return; } Rect oldPosition = console.position; editorWindowPosField.SetValue(console, position); try { bool contextClick = Event.current.type == EventType.ContextClick || Event.current.type == EventType.MouseUp && Event.current.button == 1 && Application.platform == RuntimePlatform.OSXEditor; if (contextClick && GUIUtility.hotControl == 0 && Event.current.mousePosition.y > EditorStyles.toolbar.fixedHeight) { int lvHeight = (int)consoleLVHeightField.GetValue(console); if (lvHeight > Event.current.mousePosition.y - EditorStyles.toolbar.fixedHeight) { Event.current.type = EventType.MouseDown; Event.current.button = 0; Event.current.clickCount = 1; try { consoleOnGUIMethod.Invoke(console, null); } catch { } GUIUtility.hotControl = 0; DoPopupMenu(console); } } else if (Event.current.type == EventType.MouseDown && Event.current.clickCount == 2 && Event.current.mousePosition.y > EditorStyles.toolbar.fixedHeight || Event.current.type == EventType.KeyDown && Event.current.keyCode == KeyCode.Return) { OpenLogEntry(console); GUIUtility.hotControl = 0; GUIUtility.ExitGUI(); } try { consoleOnGUIMethod.Invoke(console, null); } catch { } #if UNITY_2019_3_OR_NEWER var rc = new Rect(413f, -1f, 160f, 18f); #elif UNITY_2017_1_OR_NEWER var rc = new Rect(355f, -1f, 144f, 18f); #else var rc = new Rect(254f, -1f, 144f, 18f); #endif var autoFocusText = SISettings.autoFocusConsole == 0 ? "Auto-Focus: Never" : SISettings.autoFocusConsole == 1 ? "Auto-Focus: On Error" : "Auto-Focus: On Compile"; if (GUI.Button(rc, autoFocusText, EditorStyles.toolbarDropDown)) { var menu = new GenericMenu(); menu.AddItem(new GUIContent("Never"), SISettings.autoFocusConsole == 0, () => { SISettings.autoFocusConsole.Value = 0; }); menu.AddItem(new GUIContent("On Compile Error"), SISettings.autoFocusConsole == 1, () => { SISettings.autoFocusConsole.Value = 1; }); menu.AddItem(new GUIContent("On Compile"), SISettings.autoFocusConsole == 2, () => { SISettings.autoFocusConsole.Value = 2; }); menu.DropDown(rc); } #if !UNITY_2019_3_OR_NEWER if (font == null && SISettings.monospacedFontConsole) { font = FGTextEditor.LoadEditorResource <Font>("Smooth Fonts/DejaVu Sans Mono.ttf"); SetConsoleFont(font); } rc.xMin = rc.xMax + 4f; rc.xMax = rc.xMin + 100f; if (SISettings.monospacedFontConsole != GUI.Toggle(rc, SISettings.monospacedFontConsole, "Monospaced Font", EditorStyles.toolbarButton)) { SISettings.monospacedFontConsole.Value = !SISettings.monospacedFontConsole; if (font == null && SISettings.monospacedFontConsole) { font = FGTextEditor.LoadEditorResource <Font>("Smooth Fonts/DejaVu Sans Mono.ttf"); } SetConsoleFont(SISettings.monospacedFontConsole ? font : null); } #endif } finally { editorWindowPosField.SetValue(console, oldPosition); } }
private void OnGUI() { if (Event.current.isKey && TabSwitcher.OnGUIGlobal()) { return; } bool needsRepaint = false; if (Event.current.type == EventType.KeyDown) { var nextItem = currentItem; var results = GroupByFile ? this.results : flatResults; if (Event.current.keyCode == KeyCode.DownArrow) { ++nextItem; if (GroupByFile) { while (nextItem < results.Count && results[nextItem].description != null && collapsedPaths.Contains(results[nextItem].assetPath)) { ++nextItem; } } if (nextItem == results.Count) { nextItem = currentItem; } } else if (Event.current.keyCode == KeyCode.RightArrow && currentItem < results.Count) { if (results[currentItem].description == null && collapsedPaths.Contains(results[currentItem].assetPath)) { collapsedPaths.Remove(results[currentItem].assetPath); needsRepaint = true; } else { ++nextItem; } } else if (Event.current.keyCode == KeyCode.UpArrow) { --nextItem; if (GroupByFile) { while (nextItem > 0 && results[nextItem].description != null && collapsedPaths.Contains(results[nextItem].assetPath)) { --nextItem; } } } else if (Event.current.keyCode == KeyCode.LeftArrow && currentItem < results.Count) { if (results[currentItem].description == null) { collapsedPaths.Add(results[currentItem].assetPath); needsRepaint = true; } else if (GroupByFile) { while (results[nextItem].description != null) { --nextItem; } } else { --nextItem; } } else if (Event.current.keyCode == KeyCode.Home) { nextItem = 0; } else if (Event.current.keyCode == KeyCode.End) { nextItem = results.Count - 1; if (GroupByFile) { while (nextItem > 0 && results[nextItem].description != null && collapsedPaths.Contains(results[nextItem].assetPath)) { --nextItem; } } } nextItem = Mathf.Max(0, Mathf.Min(nextItem, results.Count - 1)); scrollToCurrentItem = scrollToCurrentItem || needsRepaint || nextItem != currentItem; needsRepaint = needsRepaint || nextItem != currentItem; currentItem = nextItem; if (Event.current.keyCode == KeyCode.Return || Event.current.keyCode == KeyCode.KeypadEnter || Event.current.keyCode == KeyCode.Space) { if (currentItem < results.Count) { Event.current.Use(); if (results[currentItem].description != null) { GoToResult(currentItem); } else { var path = results[currentItem].assetPath; if (collapsedPaths.Contains(path)) { collapsedPaths.Remove(path); } else { collapsedPaths.Add(path); } needsRepaint = true; } } } else if (needsRepaint) { Event.current.Use(); } if (needsRepaint) { needsRepaint = false; Repaint(); return; } } //if (Event.current.type == EventType.KeyDown && Event.current.keyCode == KeyCode.Escape) //{ // Close(); // editor.OwnerWindow.Focus(); // return; //} if (evenItemStyle == null) { evenItemStyle = new GUIStyle("PR Label"); evenItemStyle.padding.top = 2; evenItemStyle.padding.bottom = 2; evenItemStyle.padding.left = 2; evenItemStyle.margin.right = 0; evenItemStyle.fixedHeight = 0; evenItemStyle.richText = false; evenItemStyle.stretchWidth = true; evenItemStyle.wordWrap = false; oddItemStyle = new GUIStyle(evenItemStyle); var evenBackground = (GUIStyle)"CN EntryBackEven"; var oddBackground = (GUIStyle)"CN EntryBackodd"; evenItemStyle.normal.background = evenBackground.normal.background; evenItemStyle.focused.background = evenBackground.normal.background; oddItemStyle.normal.background = oddBackground.normal.background; oddItemStyle.focused.background = oddBackground.normal.background; pingStyle = (GUIStyle)"PR Ping"; } var rcToolbar = new Rect(0f, 0f, Screen.width, 20f); GUI.Label(rcToolbar, GUIContent.none, EditorStyles.toolbar); GUILayout.BeginHorizontal(); GUILayout.Label(infoText, GUILayout.Height(20f), GUILayout.MinWidth(0f)); EditorGUILayout.Space(); GUILayout.Label(resultsCountText, GUILayout.Height(20f)); GUILayout.FlexibleSpace(); var newGroupByFile = GUILayout.Toggle(GroupByFile, "Group by File", EditorStyles.toolbarButton, GUILayout.Height(20f), GUILayout.ExpandHeight(true)); keepResults = GUILayout.Toggle(keepResults, "Keep Results", EditorStyles.toolbarButton, GUILayout.Height(20f), GUILayout.ExpandHeight(true)); EditorGUILayout.Space(); GUILayout.EndHorizontal(); if (newGroupByFile != GroupByFile) { var results = GroupByFile ? this.results : flatResults; GroupByFile = newGroupByFile; var newResults = GroupByFile ? this.results : flatResults; if (currentItem < results.Count) { var currentResult = results[currentItem]; if (currentResult.description == null) { currentResult = results[currentItem + 1]; } currentItem = Mathf.Max(0, newResults.IndexOf(currentResult)); } else { currentItem = 0; } needsRepaint = true; scrollToCurrentItem = true; } listViewHeight = Screen.height - rcToolbar.height - 20f; Vector2 scrollToPosition; try { scrollPosition = GUILayout.BeginScrollView(scrollPosition, GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true)); scrollToPosition = scrollPosition; EditorGUIUtility.SetIconSize(new Vector2(16f, 16f)); //resultsLock.EnterReadLock(); if (foundNoResults) { GUILayout.Label("No Results Found!"); } else { var currentPath = ""; bool isExpanded = true; int drawnItemIndex = 0; var results = GroupByFile ? this.results : flatResults; for (var i = 0; i < results.Count; ++i) { var result = results[i]; var itemStyle = (drawnItemIndex & 1) == 0 ? evenItemStyle : oddItemStyle; if (result.description != null && !isExpanded) { continue; } ++drawnItemIndex; var rc = GUILayoutUtility.GetRect(GUIContent.none, itemStyle, GUILayout.Height(21f), GUILayout.ExpandWidth(true)); if (Event.current.type == EventType.Repaint) { itemStyle.Draw(rc, GUIContent.none, false, false, i == currentItem, this == focusedWindow); } if (result.description == null) { currentPath = result.assetPath; isExpanded = !collapsedPaths.Contains(currentPath); var rcToggle = rc; rcToggle.xMax = 18f; bool expand = GUI.Toggle(rcToggle, isExpanded, GUIContent.none, EditorStyles.foldout); if (expand != isExpanded) { currentItem = i; if (expand && !isExpanded) { collapsedPaths.Remove(currentPath); } else if (!expand && isExpanded) { collapsedPaths.Add(currentPath); } needsRepaint = true; } } if (scrollToCurrentItem && i == currentItem && Event.current.type == EventType.Repaint) { if (rc.yMin < scrollPosition.y) { scrollToPosition.y = rc.yMin; needsRepaint = true; } else if (rc.yMax > scrollPosition.y + listViewHeight) { scrollToPosition.y = rc.yMax - listViewHeight; needsRepaint = true; } } if (rc.yMax < scrollPosition.y || rc.yMin > scrollPosition.y + listViewHeight) { continue; } if (Event.current.type == EventType.MouseDown && rc.Contains(Event.current.mousePosition)) { if (i == currentItem && Event.current.button == 0 && Event.current.clickCount == 2) { if (result.description == null) { if (collapsedPaths.Contains(result.assetPath)) { collapsedPaths.Remove(result.assetPath); } else { collapsedPaths.Add(result.assetPath); } needsRepaint = true; } else { FGCodeWindow.OpenAssetInTab(result.assetGuid, result.line, result.characterIndex, result.length); } } else if (Event.current.button == 1 && result.description == null) { GenericMenu menu = new GenericMenu(); menu.AddItem(new GUIContent("Expand All"), false, () => { collapsedPaths.Clear(); }); menu.AddItem(new GUIContent("Collapse All"), false, () => { foreach (var r in results) { if (r.description == null) { collapsedPaths.Add(r.assetPath); } } }); menu.ShowAsContext(); } currentItem = i; needsRepaint = true; scrollToCurrentItem = true; Event.current.Use(); } GUIContent contentContent; int lineInfoLength = 0; if (result.description == null) { contentContent = new GUIContent(result.assetPath, AssetDatabase.GetCachedIcon(result.assetPath)); rc.xMin = 18f; } else { string lineInfo; if (GroupByFile) { lineInfo = (result.line + 1).ToString() + ": "; } else { lineInfo = System.IO.Path.GetFileName(result.assetPath) + '(' + (result.line + 1).ToString() + "): "; } lineInfoLength = lineInfo.Length; contentContent = new GUIContent(lineInfo + result.description); rc.xMin = 22f; } if (Event.current.type == EventType.Repaint) { if (result.description != null) { var dotContent = new GUIContent("."); var preContent = new GUIContent(contentContent.text.Substring(0, lineInfoLength + result.characterIndex - result.trimOffset) + '.'); var resultContent = new GUIContent('.' + contentContent.text.Substring(0, lineInfoLength + result.characterIndex + result.length - result.trimOffset) + '.'); var dotSize = itemStyle.CalcSize(dotContent); var preSize = itemStyle.CalcSize(preContent); preSize.x -= dotSize.x; var resultSize = itemStyle.CalcSize(resultContent); resultSize.x -= dotSize.x * 2f; var rcHighlight = new Rect(rc.x + preSize.x - 4f, rc.y + 2f, resultSize.x - preSize.x + 14f, rc.height - 4f); GUI.color = new Color(1f, 1f, 1f, 0.4f); pingStyle.Draw(rcHighlight, false, false, false, false); GUI.color = Color.white; } GUI.backgroundColor = Color.clear; itemStyle.Draw(rc, contentContent, false, false, i == currentItem, this == focusedWindow); GUI.backgroundColor = Color.white; } } } GUILayout.FlexibleSpace(); } finally { //resultsLock.ExitReadLock(); GUILayout.EndScrollView(); } if (Event.current.type == EventType.Repaint) { if (needsRepaint) { scrollToCurrentItem = false; scrollPosition = scrollToPosition; Repaint(); } else { scrollToCurrentItem = false; } } }
protected void OnGUI() { if (Event.current.isKey && TabSwitcher.OnGUIGlobal()) { return; } EditorWindow console = consoleWindowField.GetValue(null) as EditorWindow; if (console == null) { EditorGUILayout.HelpBox(@"Script Inspector Console can only work when the Console tab is also open. Click the button below to open the Console window...", MessageType.Info); EditorGUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); if (GUILayout.Button("Open Console Widnow")) { GetWindow(consoleWindowType); Focus(); Repaint(); } GUILayout.FlexibleSpace(); EditorGUILayout.EndHorizontal(); return; } Rect oldPosition = console.position; editorWindowPosField.SetValue(console, position); try { bool contextClick = Event.current.type == EventType.ContextClick || Event.current.type == EventType.MouseUp && Event.current.button == 1 && Application.platform == RuntimePlatform.OSXEditor; if (contextClick && GUIUtility.hotControl == 0 && Event.current.mousePosition.y > EditorStyles.toolbar.fixedHeight) { int lvHeight = (int)consoleLVHeightField.GetValue(console); if (lvHeight > Event.current.mousePosition.y - EditorStyles.toolbar.fixedHeight) { Event.current.type = EventType.MouseDown; Event.current.button = 0; Event.current.clickCount = 1; try { consoleOnGUIMethod.Invoke(console, null); } catch { } GUIUtility.hotControl = 0; DoPopupMenu(console); } } else if (Event.current.type == EventType.MouseDown && Event.current.clickCount == 2 && Event.current.mousePosition.y > EditorStyles.toolbar.fixedHeight || Event.current.type == EventType.KeyDown && Event.current.keyCode == KeyCode.Return) { OpenLogEntry(console); GUIUtility.hotControl = 0; GUIUtility.ExitGUI(); } try { consoleOnGUIMethod.Invoke(console, null); } catch { } var rc = new Rect(254f, -1f, 144f, 18f); var autoFocusText = SISettings.autoFocusConsole == 0 ? "Auto-Focus: Never" : SISettings.autoFocusConsole == 1 ? "Auto-Focus: On Error" : "Auto-Focus: On Compile"; if (GUI.Button(rc, autoFocusText, EditorStyles.toolbarDropDown)) { var menu = new GenericMenu(); menu.AddItem(new GUIContent("Never"), SISettings.autoFocusConsole == 0, () => { SISettings.autoFocusConsole.Value = 0; }); menu.AddItem(new GUIContent("On Compile Error"), SISettings.autoFocusConsole == 1, () => { SISettings.autoFocusConsole.Value = 1; }); menu.AddItem(new GUIContent("On Compile"), SISettings.autoFocusConsole == 2, () => { SISettings.autoFocusConsole.Value = 2; }); menu.DropDown(rc); } } finally { editorWindowPosField.SetValue(console, oldPosition); } }
public static bool OnGUIGlobal() { if (instance) { instance.OnGUI(); return true; } else if (Event.current.type == EventType.KeyDown && Event.current.keyCode == KeyCode.Tab) { var isOSX = Application.platform == RuntimePlatform.OSXEditor; if (isOSX) { if (Event.current.alt && !EditorGUI.actionKey) instance = Create(!Event.current.shift); return true; } if (!Event.current.alt && EditorGUI.actionKey) { EditorApplication.update -= DelayedCreateWithShiftKey; EditorApplication.update -= DelayedCreateNoShiftKey; var isShift = Event.current.shift; if (isShift) EditorApplication.update += DelayedCreateWithShiftKey; else EditorApplication.update += DelayedCreateNoShiftKey; return true; } } return false; }
public void CloseAndSwitch() { if (!instance) return; var guid = GetSelectedGUID(); Close(); DestroyImmediate(this); FGCodeWindow.OpenAssetInTab(guid); instance = null; }
private void OnGUI() { var isOSX = Application.platform == RuntimePlatform.OSXEditor; if (tabSwitcher) { if ((Event.current.modifiers & (isOSX ? EventModifiers.Alt : EventModifiers.Control)) == 0) { tabSwitcher.Close(); addRecentLocationForNextAsset = true; OpenAssetInTab(TabSwitcher.GetSelectedGUID()); } else if (Event.current.isKey)// || Event.current.isMouse) { tabSwitcher.OnGUI(); return; } } switch (Event.current.type) { case EventType.layout: if (IsFloating() && FGTextBuffer.activeEditor == textEditor) defaultPosition = position; break; case EventType.KeyDown: if (!tabSwitcher && Event.current.keyCode == KeyCode.Tab) { if (isOSX ? Event.current.alt && !EditorGUI.actionKey : !Event.current.alt && EditorGUI.actionKey) { var isShift = Event.current.shift; EditorApplication.delayCall += () => { tabSwitcher = TabSwitcher.Create(!isShift); }; } } if ((Event.current.modifiers & ~EventModifiers.FunctionKey) == EventModifiers.Control && (Event.current.keyCode == KeyCode.PageUp || Event.current.keyCode == KeyCode.PageDown)) { SelectAdjacentCodeTab(Event.current.keyCode == KeyCode.PageDown); Event.current.Use(); GUIUtility.ExitGUI(); } else if (Event.current.alt && EditorGUI.actionKey) { if (Event.current.keyCode == KeyCode.RightArrow || Event.current.keyCode == KeyCode.LeftArrow) { if (Event.current.shift) { MoveThisTab(Event.current.keyCode == KeyCode.RightArrow); } else { SelectAdjacentCodeTab(Event.current.keyCode == KeyCode.RightArrow); } Event.current.Use(); GUIUtility.ExitGUI(); } } else if (!Event.current.alt && !Event.current.shift && EditorGUI.actionKey) { if (Event.current.keyCode == KeyCode.W || Event.current.keyCode == KeyCode.F4) { Event.current.Use(); if (!IsMaximized()) Close(); } } else if (Event.current.alt && !Event.current.shift && !EditorGUI.actionKey && Event.current.keyCode == KeyCode.Return) { Event.current.Use(); ToggleMaximized(this); GUIUtility.ExitGUI(); } break; case EventType.DragUpdated: case EventType.DragPerform: if (DragAndDrop.objectReferences.Length > 0) { bool ask = false; HashSet<Object> accepted = new HashSet<Object>(); foreach (Object obj in DragAndDrop.objectReferences) { if (AssetDatabase.GetAssetPath(obj).EndsWith(".dll", System.StringComparison.OrdinalIgnoreCase) || AssetDatabase.GetAssetPath(obj).EndsWith(".exe", System.StringComparison.OrdinalIgnoreCase)) continue; if (obj is MonoScript) accepted.Add(obj); else if (obj is TextAsset || obj is Shader) accepted.Add(obj); else if (obj is Material) { Material material = obj as Material; if (material.shader != null) { int shaderID = material.shader.GetInstanceID(); if (shaderID != 0) { if (!string.IsNullOrEmpty(AssetDatabase.GetAssetPath(shaderID))) accepted.Add(material.shader); } } } else if (obj is GameObject) { GameObject gameObject = obj as GameObject; MonoBehaviour[] monoBehaviours = gameObject.GetComponents<MonoBehaviour>(); foreach (MonoBehaviour mb in monoBehaviours) { MonoScript monoScript = MonoScript.FromMonoBehaviour(mb); if (monoScript != null) { if (!string.IsNullOrEmpty(AssetDatabase.GetAssetPath(monoScript))) { accepted.Add(monoScript); ask = true; } } } } } if (accepted.Count > 0) { DragAndDrop.AcceptDrag(); DragAndDrop.visualMode = DragAndDropVisualMode.Copy; if (Event.current.type == EventType.DragPerform) { Object[] sorted = accepted.OrderBy((x) => x.name, System.StringComparer.OrdinalIgnoreCase).ToArray(); if (ask && sorted.Length > 1) { GenericMenu popupMenu = new GenericMenu(); foreach (Object target in sorted) { Object tempTarget = target; popupMenu.AddItem( new GUIContent("Open " + System.IO.Path.GetFileName(AssetDatabase.GetAssetPath(target))), false, () => { OpenNewWindow(tempTarget, this, true); }); } popupMenu.AddSeparator(""); popupMenu.AddItem( new GUIContent("Open All"), false, () => { foreach (Object target in sorted) OpenNewWindow(target, this, true); }); popupMenu.ShowAsContext(); } else { foreach (Object target in sorted) OpenNewWindow(target, this, true); } } Event.current.Use(); return; } } break; case EventType.ValidateCommand: if (Event.current.commandName == "ScriptInspector.AddTab") { Event.current.Use(); return; } break; case EventType.ExecuteCommand: if (Event.current.commandName == "ScriptInspector.AddTab") { Event.current.Use(); OpenNewWindow(targetAsset, this, false); return; } break; } if (!wantsMouseMove) wantsMouseMove = true; textEditor.OnWindowGUI(this, new RectOffset(0, 0, 19, 1)); }