private void OnRootObjectsChanged() { if (HQ.Settings == null) { return; } FavSettings settings = HQ.Settings.Get <FavSettings>(); if (this.currentSave >= 0 && this.currentSave < settings.favorites.Count) { List <AssetsSelection> fav = settings.favorites[this.currentSave].favorites; for (int i = 0; i < fav.Count; i++) { for (int j = 0; j < fav[i].refs.Count; j++) { if (fav[i].refs[j].@object == null) { fav[i].refs[j].TryReconnect(); } } } this.Repaint(); } }
private void TryReconnectkNullObjects() { if (HQ.Settings == null) { return; } FavSettings settings = HQ.Settings.Get <FavSettings>(); if (this.currentSave >= 0 && this.currentSave < settings.favorites.Count) { List <AssetsSelection> selections = settings.favorites[this.currentSave].favorites; for (int i = 0; i < selections.Count; i++) { for (int j = 0; j < selections[i].refs.Count; j++) { if (selections[i].refs[j].@object == null) { if (selections[i].refs[j].hasObject == true) { selections[i].refs[j].hasObject = false; this.Repaint(); } if (selections[i].refs[j].TryReconnect() == true) { this.Repaint(); } } } } } }
private void Diagnose() { NGDiagnostic.Log(NGFavWindow.Title, "CurrentFav", this.currentSave); FavSettings settings = HQ.Settings.Get <FavSettings>(); for (int i = 0; i < settings.favorites.Count; i++) { NGDiagnostic.Log(NGFavWindow.Title, "Fav[" + i + "]", JsonUtility.ToJson(settings.favorites[i])); } }
private void AddFavorite() { FavSettings settings = HQ.Settings.Get <FavSettings>(); if (this.CheckMaxFavorites(settings.favorites.Count) == true) { Undo.RecordObject(settings, "Add favorite"); settings.favorites.Add(new Favorites() { name = "Favorite " + (settings.favorites.Count + 1) }); this.currentSave = settings.favorites.Count - 1; HQ.InvalidateSettings(); } }
private void CreateSelection(Object[] objects) { AssetsSelection selection = new AssetsSelection(objects); if (selection.refs.Count > 0) { FavSettings settings = HQ.Settings.Get <FavSettings>(); if (this.CheckMaxAssetsPerSelection(selection.refs.Count) == true && this.CheckMaxSelections(settings.favorites[this.currentSave].favorites.Count) == true) { Undo.RecordObject(settings, "Add Selection as favorite"); settings.favorites[this.currentSave].favorites.Add(selection); HQ.InvalidateSettings(); } } }
private void CheckSettings() { this.Repaint(); if (HQ.Settings != null) { 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" }); } } }
private void DrawElement(Rect rect, int index, bool isActive, bool isFocused) { FavSettings settings = HQ.Settings.Get <FavSettings>(); AssetsSelection assetsSelection = settings.favorites[this.currentSave].favorites[index]; float x = rect.x; float width = rect.width; if (rect.Contains(Event.current.mousePosition) == true) { float totalWidth = 0F; for (int i = 0; i < assetsSelection.refs.Count; i++) { SelectionItem selection = assetsSelection.refs[i]; if (selection.@object == null) { if (selection.hierarchy.Count > 0) { Utility.content.text = (string.IsNullOrEmpty(selection.resolverAssemblyQualifiedName) == false ? "(R)" : "") + selection.hierarchy[selection.hierarchy.Count - 1]; } else { Utility.content.text = "Unknown"; } } else { Utility.content.text = [email protected]; if (Utility.GetIcon([email protected]()) != null) { totalWidth += rect.height; } } totalWidth += GUI.skin.label.CalcSize(Utility.content).x + NGFavWindow.FavSpacing; } if (index < 10) { if (index < 9) { totalWidth += 24F; } else { totalWidth += 22F; // Number 10 is centralized. } } if (assetsSelection.refs.Count > 1) { Utility.content.text = "(" + assetsSelection.refs.Count + ")"; totalWidth += GUI.skin.label.CalcSize(Utility.content).x; } this.horizontalScrolls[index].RealWidth = totalWidth; this.horizontalScrolls[index].SetPosition(rect.x, rect.y); this.horizontalScrolls[index].SetSize(rect.width); this.horizontalScrolls[index].OnGUI(); if (Event.current.type == EventType.MouseMove) { this.Repaint(); } rect.width = 20F; rect.x = x + width - rect.width; rect.height -= 4F; if (GUI.Button(rect, "X") == true) { this.delayToDelete = index; return; } rect.height += 4F; rect.x = x; rect.width = width; } rect.x -= this.horizontalScrolls[index].Offset; if (index <= 9) { rect.width = 24F; Utility.content.text = NGFavWindow.CacheIndexes[index]; Utility.content.tooltip = NGFavWindow.CacheTooltips[index]; if (index <= 8) { EditorGUI.LabelField(rect, Utility.content, GeneralStyles.HorizontalCenteredText); } else { rect.width = 27F; rect.x -= 4F; EditorGUI.LabelField(rect, Utility.content, GeneralStyles.HorizontalCenteredText); rect.x += 4F; } Utility.content.tooltip = string.Empty; rect.x += rect.width; rect.width = width - rect.x; } if (assetsSelection.refs.Count >= 2) { Utility.content.text = "(" + assetsSelection.refs.Count + ")"; rect.width = GeneralStyles.HorizontalCenteredText.CalcSize(Utility.content).x; GUI.Label(rect, Utility.content, GeneralStyles.HorizontalCenteredText); rect.x += rect.width; rect.width = width - rect.x; } Rect dropZone = rect; dropZone.xMin = dropZone.xMax - dropZone.width / 3F; for (int i = 0; i < assetsSelection.refs.Count; i++) { SelectionItem selectionItem = assetsSelection.refs[i];; if (selectionItem.@object == null) { selectionItem.TryReconnect(); } Texture icon = null; Utility.content.tooltip = selectionItem.resolverFailedError; EditorGUI.BeginDisabledGroup(selectionItem.@object == null); { if (selectionItem.@object == null) { if (selectionItem.hierarchy.Count > 0) { Utility.content.text = (string.IsNullOrEmpty(selectionItem.resolverAssemblyQualifiedName) == false ? "(R)" : "") + selectionItem.hierarchy[selectionItem.hierarchy.Count - 1]; } else { Utility.content.text = "Unknown"; } } else { Utility.content.text = [email protected]; icon = Utility.GetIcon([email protected]()); } if (icon != null) { rect.width = rect.height; GUI.DrawTexture(rect, icon); rect.x += rect.width; } rect.width = GeneralStyles.HorizontalCenteredText.CalcSize(Utility.content).x; if (string.IsNullOrEmpty(selectionItem.resolverFailedError) == false) { GeneralStyles.HorizontalCenteredText.normal.textColor = Color.red; } GUI.Label(rect, Utility.content, GeneralStyles.HorizontalCenteredText); Utility.content.tooltip = string.Empty; GeneralStyles.HorizontalCenteredText.normal.textColor = EditorStyles.label.normal.textColor; if (icon != null) { rect.xMin -= rect.height; } } EditorGUI.EndDisabledGroup(); if (selectionItem.@object != null) { if (Event.current.type == EventType.MouseDrag && (this.dragOriginPosition - Event.current.mousePosition).sqrMagnitude >= Constants.MinStartDragDistance && DragAndDrop.GetGenericData("t") as Object == selectionItem.@object) { DragAndDrop.StartDrag("Drag favorite"); Event.current.Use(); } else if (Event.current.type == EventType.MouseDown && rect.Contains(Event.current.mousePosition) == true) { this.dragOriginPosition = Event.current.mousePosition; DragAndDrop.PrepareStartDrag(); // Add this data to force drag on this object only because user has click down on it. DragAndDrop.SetGenericData("t", selectionItem.@object); DragAndDrop.objectReferences = new Object[] { selectionItem.@object }; Event.current.Use(); } else if (Event.current.type == EventType.MouseUp && rect.Contains(Event.current.mousePosition) == true) { DragAndDrop.PrepareStartDrag(); if (Event.current.button == 0 && (int)Event.current.modifiers == ((int)settings.deleteModifiers >> 1)) { Undo.RecordObject(settings, "Delete element in favorite"); assetsSelection.refs.RemoveAt(i); if (assetsSelection.refs.Count == 0) { this.delayToDelete = index; } } else if (Event.current.button == 1 || settings.changeSelection == FavSettings.ChangeSelection.SimpleClick || ((settings.changeSelection == FavSettings.ChangeSelection.DoubleClick || settings.changeSelection == FavSettings.ChangeSelection.ModifierOrDoubleClick) && this.lastClick + Constants.DoubleClickTime > EditorApplication.timeSinceStartup) || ((settings.changeSelection == FavSettings.ChangeSelection.Modifier || settings.changeSelection == FavSettings.ChangeSelection.ModifierOrDoubleClick) && // HACK We need to shift the event modifier's value. Bug ref #720211_8cg6m8s7akdbf1r5 (int)Event.current.modifiers == ((int)settings.selectModifiers >> 1))) { NGFavWindow.SelectFav(index); } else { EditorGUIUtility.PingObject(assetsSelection.refs[i].@object); } this.lastClick = EditorApplication.timeSinceStartup; this.list.index = index; this.Repaint(); Event.current.Use(); } } else { // Clean drag on null object, to prevent starting a drag when passing over non-null one without click down. if (Event.current.type == EventType.MouseDown && rect.Contains(Event.current.mousePosition) == true && HQ.Settings != null) { if ((int)Event.current.modifiers == ((int)settings.deleteModifiers >> 1)) { Undo.RecordObject(settings, "Delete element in favorite"); assetsSelection.refs.RemoveAt(i); if (assetsSelection.refs.Count == 0) { this.delayToDelete = index; } Event.current.Use(); } DragAndDrop.PrepareStartDrag(); } } rect.x += rect.width + NGFavWindow.FavSpacing; if (rect.x >= this.position.width) { break; } } rect.x = x; rect.width = width; // Drop zone to append new Object to the current selection. if (Event.current.type == EventType.Repaint && DragAndDrop.objectReferences.Length > 0 && rect.Contains(Event.current.mousePosition) == true) { Utility.DropZone(dropZone, "Add to selection"); } else if (Event.current.type == EventType.DragUpdated && dropZone.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 && dropZone.Contains(Event.current.mousePosition) == true) { DragAndDrop.AcceptDrag(); for (int i = 0; i < DragAndDrop.objectReferences.Length; i++) { int j = 0; for (; j < assetsSelection.refs.Count; j++) { if (assetsSelection.refs[j].@object == DragAndDrop.objectReferences[i]) { break; } } if (j == assetsSelection.refs.Count) { if (this.CheckMaxAssetsPerSelection(assetsSelection.refs.Count) == true) { Undo.RecordObject(settings, "Add to favorite"); assetsSelection.refs.Add(new SelectionItem(DragAndDrop.objectReferences[i])); HQ.InvalidateSettings(); } else { break; } } } DragAndDrop.PrepareStartDrag(); Event.current.Use(); } // Just draw the button in front. if (rect.Contains(Event.current.mousePosition) == true) { rect.width = 20F; rect.x = x + width - rect.width; rect.height -= 4F; GUI.Button(rect, "X"); } }
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"); }
private static void SelectFav(int i) { if (HQ.Settings == null) { return; } NGFavWindow[] favs = Resources.FindObjectsOfTypeAll <NGFavWindow>(); if (favs.Length == 0) { return; } NGFavWindow fav = favs[0]; FavSettings settings = HQ.Settings.Get <FavSettings>(); if (fav.currentSave >= 0 && fav.currentSave < settings.favorites.Count && settings.favorites[fav.currentSave].favorites.Count > i) { List <AssetsSelection> selections = settings.favorites[fav.currentSave].favorites; for (int j = 0; j < selections[i].refs.Count; j++) { if (selections[i].refs[j].@object == null) { selections[i].refs[j].TryReconnect(); } } List <Object> list = new List <Object>(); for (int j = 0; j < selections[i].refs.Count; j++) { if (selections[i].refs[j].@object != null) { list.Add(selections[i].refs[j].@object); } } if (list.Count > 0) { Selection.objects = list.ToArray(); if (Selection.activeGameObject != null) { EditorGUIUtility.PingObject(Selection.activeGameObject); if (SceneView.lastActiveSceneView != null) { PrefabType type = PrefabUtility.GetPrefabType(Selection.activeGameObject); if (type != PrefabType.ModelPrefab && type != PrefabType.Prefab) { SceneView.lastActiveSceneView.FrameSelected(); } } } } fav.list.index = i; fav.Repaint(); } }