protected virtual void OnGUI() { FreeLicenseOverlay.First(this, NGAssemblyInfo.Name + " Pro", NGShaderFinderWindow.FreeAdContent); Rect r = this.position; r.x = 0F; r.y = 0F; r.height = NGShaderFinderWindow.SearchButtonHeight; EditorGUI.BeginDisabledGroup(this.isSearching); { r.height = Constants.SingleLineHeight; using (LabelWidthRestorer.Get(100F)) { r.width = this.position.width - NGShaderFinderWindow.FindButtonWidth - NGShaderFinderWindow.FindButtonLeftSpacing; EditorGUI.BeginChangeCheck(); Shader newTarget = EditorGUI.ObjectField(r, "Find Shader", this.targetShader, typeof(Shader), false) as Shader; if (EditorGUI.EndChangeCheck() == true) { this.targetShader = newTarget; } } r.y += r.height + NGShaderFinderWindow.Spacing; r.width = NGShaderFinderWindow.TargetReplaceLabelWidth; this.canReplace = GUI.Toggle(r, this.canReplace, "Replace With"); r.x += r.width; EditorGUI.BeginDisabledGroup(!this.canReplace); { r.width = this.position.width - r.x - NGShaderFinderWindow.SwitchShaderButtonWidth - NGShaderFinderWindow.FindButtonWidth - NGShaderFinderWindow.FindButtonLeftSpacing; this.replaceShader = EditorGUI.ObjectField(r, this.replaceShader, typeof(Shader), false) as Shader; } EditorGUI.EndDisabledGroup(); r.x += r.width; r.width = NGShaderFinderWindow.SwitchShaderButtonWidth; if (GUI.Button(r, "⇅", GeneralStyles.BigFontToolbarButton) == true) { Shader tmp = this.replaceShader; this.replaceShader = this.targetShader; this.targetShader = tmp; } r.yMin -= r.height + NGShaderFinderWindow.Spacing; r.width = NGShaderFinderWindow.FindButtonWidth; r.x = this.position.width - NGShaderFinderWindow.FindButtonWidth; EditorGUI.BeginDisabledGroup(this.targetShader == null || this.isSearching == true); { using (BgColorContentRestorer.Get(GeneralStyles.HighlightActionButton)) { if (GUI.Button(r, "Find") == true) { this.FindReferences(); } } } EditorGUI.EndDisabledGroup(); r.y += r.height + NGShaderFinderWindow.Spacing; } EditorGUI.EndDisabledGroup(); if (this.canReplace == true) { EditorGUI.BeginDisabledGroup(this.isSearching == true || this.hasResult == false); { using (BgColorContentRestorer.Get(GeneralStyles.HighlightActionButton)) { r.x = 0F; r.width = this.position.width * .5F; if (GUI.Button(r, "Replace") == true) { this.ReplaceReferences(true); } r.x += r.width; if (GUI.Button(r, "Set all") == true) { this.ReplaceReferences(false); } r.y += r.height + NGShaderFinderWindow.Spacing + NGShaderFinderWindow.Spacing; } } EditorGUI.EndDisabledGroup(); } r.x = 0F; r.width = this.position.width; if (this.hasResult == true) { r.height = Constants.SingleLineHeight; GUI.Box(r, string.Empty, GeneralStyles.Toolbar); GUI.Label(r, this.resultsHeaderLabel); using (BgColorContentRestorer.Get(GeneralStyles.HighlightResultButton)) { r.xMin = r.xMax - NGShaderFinderWindow.ClearButtonWidth; if (GUI.Button(r, "Clear", GeneralStyles.ToolbarButton) == true) { this.ClearResults(); } } r.y += r.height + NGShaderFinderWindow.Spacing; r.x = 0F; r.width = this.position.width; Rect bodyRect = r; bodyRect.height = this.position.height - r.y; Rect viewRect = new Rect(0F, 0F, 0F, (Constants.SingleLineHeight + NGShaderFinderWindow.Spacing) * this.results.Count - NGShaderFinderWindow.Spacing); this.scrollPosition = GUI.BeginScrollView(bodyRect, this.scrollPosition, viewRect); { float w = r.width - (viewRect.height > bodyRect.height ? 16F : 0F); r.y = 0F; r.height = Constants.SingleLineHeight; for (int i = 0; i < this.results.Count; i++) { if (r.y + r.height + NGShaderFinderWindow.Spacing <= this.scrollPosition.y) { r.y += r.height + NGShaderFinderWindow.Spacing; continue; } r.x = 0F; r.width = w - NGShaderFinderWindow.PingButtonWidth; EditorGUI.BeginChangeCheck(); Shader o = EditorGUI.ObjectField(r, this.resultsName[i], this.results[i].shader, typeof(Shader), false) as Shader; if (EditorGUI.EndChangeCheck() == true) { Undo.RecordObject(this.results[i], "Replace Material shader"); this.results[i].shader = o; EditorUtility.SetDirty(this.results[i]); } r.x += r.width; r.width = NGShaderFinderWindow.PingButtonWidth; NGEditorGUILayout.PingObject(r, LC.G("Ping"), this.results[i]); r.y += r.height + NGShaderFinderWindow.Spacing; if (r.y - this.scrollPosition.y > bodyRect.height) { break; } } } GUI.EndScrollView(); } FreeLicenseOverlay.Last(NGAssemblyInfo.Name + " Pro"); }
protected virtual void OnGUI() { if (HQ.Settings == null) { GUILayout.Label(string.Format(LC.G("RequiringConfigurationFile"), NGFavWindow.Title)); if (GUILayout.Button(LC.G("ShowPreferencesWindow")) == true) { Utility.ShowPreferencesWindowAt(Constants.PreferenceTitle); } return; } FreeLicenseOverlay.First(this, NGAssemblyInfo.Name + " Pro", NGFavWindow.FreeAdContent); FavSettings settings = HQ.Settings.Get <FavSettings>(); // Guarantee there is always one in the list. if (settings.favorites.Count == 0) { settings.favorites.Add(new Favorites() { name = "default" }); } this.currentSave = Mathf.Clamp(this.currentSave, 0, settings.favorites.Count - 1); Favorites fav = settings.favorites[this.currentSave]; this.list.list = fav.favorites; EditorGUILayout.BeginHorizontal(GeneralStyles.Toolbar); { if (GUILayout.Button("", GeneralStyles.ToolbarDropDown, GUILayoutOptionPool.Width(20F)) == true) { GenericMenu menu = new GenericMenu(); for (int i = 0; i < settings.favorites.Count; i++) { menu.AddItem(new GUIContent((i + 1) + " - " + settings.favorites[i].name), i == this.currentSave, this.SwitchFavorite, i); } menu.AddSeparator(""); menu.AddItem(new GUIContent(LC.G("Add")), false, this.AddFavorite); Rect r = GUILayoutUtility.GetLastRect(); r.y += 16F; menu.DropDown(r); GUI.FocusControl(null); } EditorGUI.BeginChangeCheck(); fav.name = EditorGUILayout.TextField(fav.name, GeneralStyles.ToolbarTextField, GUILayoutOptionPool.ExpandWidthTrue); if (EditorGUI.EndChangeCheck() == true) { HQ.InvalidateSettings(); } if (GUILayout.Button(LC.G("Clear"), GeneralStyles.ToolbarButton) == true && ((Event.current.modifiers & Constants.ByPassPromptModifier) != 0 || EditorUtility.DisplayDialog(LC.G("NGFav_ClearSave"), string.Format(LC.G("NGFav_ClearSaveQuestion"), fav.name), LC.G("Yes"), LC.G("No")) == true)) { Undo.RecordObject(settings, "Clear favorite"); fav.favorites.Clear(); HQ.InvalidateSettings(); this.Focus(); return; } EditorGUI.BeginDisabledGroup(settings.favorites.Count <= 1); if (GUILayout.Button(LC.G("Erase"), GeneralStyles.ToolbarButton) == true && ((Event.current.modifiers & Constants.ByPassPromptModifier) != 0 || EditorUtility.DisplayDialog(LC.G("NGFav_EraseSave"), string.Format(LC.G("NGFav_EraseSaveQuestion"), fav.name), LC.G("Yes"), LC.G("No")) == true)) { Undo.RecordObject(settings, "Erase favorite"); settings.favorites.RemoveAt(this.currentSave); this.currentSave = Mathf.Clamp(this.currentSave, 0, settings.favorites.Count - 1); this.list.list = fav.favorites; HQ.InvalidateSettings(); this.Focus(); return; } EditorGUI.EndDisabledGroup(); Rect r2 = GUILayoutUtility.GetRect(40F, 16F); r2.x += 5F; this.backgroundColor = EditorGUI.ColorField(r2, this.backgroundColor); } EditorGUILayout.EndHorizontal(); Rect overallDropZone = this.position; overallDropZone.x = 0F; overallDropZone.y = 0F; if (Event.current.type == EventType.Repaint && this.backgroundColor.a > 0F) { overallDropZone.y = 16F; overallDropZone.height -= 16F; EditorGUI.DrawRect(overallDropZone, this.backgroundColor); overallDropZone.y = 0; } overallDropZone.height = 16F; // Drop zone to add a new selection. if (Event.current.type == EventType.Repaint && DragAndDrop.objectReferences.Length > 0) { Utility.DropZone(overallDropZone, "Create new selection"); this.Repaint(); } else if (Event.current.type == EventType.DragUpdated && overallDropZone.Contains(Event.current.mousePosition) == true) { if (DragAndDrop.objectReferences.Length > 0) { DragAndDrop.visualMode = DragAndDropVisualMode.Copy; } else { DragAndDrop.visualMode = DragAndDropVisualMode.Rejected; } } else if (Event.current.type == EventType.DragPerform && overallDropZone.Contains(Event.current.mousePosition) == true) { DragAndDrop.AcceptDrag(); this.CreateSelection(DragAndDrop.objectReferences); DragAndDrop.PrepareStartDrag(); Event.current.Use(); } this.errorPopup.OnGUILayout(); if (this.currentSave >= 0) { this.scrollPosition = EditorGUILayout.BeginScrollView(this.scrollPosition); { try { while (this.horizontalScrolls.Count < fav.favorites.Count) { this.horizontalScrolls.Add(new HorizontalScrollbar(0F, 0F, this.position.width, 4F, 0F)); } this.list.DoLayoutList(); } catch (Exception ex) { this.errorPopup.exception = ex; InternalNGDebug.LogFileException(ex); } finally { Utility.content.tooltip = string.Empty; } } EditorGUILayout.EndScrollView(); if (this.delayToDelete != -1) { Undo.RecordObject(settings, "Delete favorite"); fav.favorites.RemoveAt(this.delayToDelete); HQ.InvalidateSettings(); this.delayToDelete = -1; } } if (Event.current.type == EventType.MouseDown) { DragAndDrop.PrepareStartDrag(); this.dragOriginPosition = Vector2.zero; } FreeLicenseOverlay.Last(NGAssemblyInfo.Name + " Pro"); }