static NGNavSelectionWindow() { try { if (Application.platform == RuntimePlatform.WindowsEditor) { EditorApplication.update += NGNavSelectionWindow.HandleMouseInputs; } NGEditorApplication.EditorExit += NGNavSelectionWindow.SaveHistoric; HQ.SettingsChanged += NGNavSelectionWindow.OnSettingsChanged; // It must me delayed! Most Object are correctly fetched, except folders and maybe others. EditorApplication.delayCall += () => { // HACK Prevents double call bug. if (NGNavSelectionWindow.historic.Count != 0) { return; } NGNavSelectionWindow.lastHash = NGEditorPrefs.GetInt(NGNavSelectionWindow.LastHashPrefKey, 0); NGNavSelectionWindow.isPlaging = EditorApplication.isPlaying; string autoSave = NGEditorPrefs.GetString(NGNavSelectionWindow.AutoSavePrefKey, string.Empty, true); if (autoSave != string.Empty) { string[] selections = autoSave.Split(','); int lastHash = 0; for (int i = 0; i < selections.Length; i++) { string[] IDs = selections[i].Split(';'); int[] array = new int[IDs.Length]; for (int j = 0; j < IDs.Length; j++) { array[j] = int.Parse(IDs[j]); } AssetsSelection selection = new AssetsSelection(array); if (selection.refs.Count > 0) { int hash = selection.GetSelectionHash(); if (lastHash != hash) { lastHash = hash; NGNavSelectionWindow.historic.Add(selection); } } } } }; } catch { } }
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(); } } }
internal static List <string> ForOperation( AssetList assetList, IAssetStatusCache assetStatusCache, AssetMenuOperations operation) { List <string> selectedPaths = AssetsSelection.GetSelectedPaths(assetList); List <string> result = new List <string>(selectedPaths); foreach (string path in selectedPaths) { if (MetaPath.IsMetaPath(path)) { continue; } string metaPath = MetaPath.GetMetaPath(path); if (!File.Exists(metaPath)) { continue; } if (result.Contains(metaPath)) { continue; } if (!IsApplicableForOperation( metaPath, false, operation, assetStatusCache)) { continue; } result.Add(metaPath); } return(result); }
public override void OnGUI() { if (this.unwrapLabel == null) { this.unwrapLabel = new GUIStyle(GUI.skin.label); this.unwrapLabel.wordWrap = false; this.buttonLeft = new GUIStyle("ButtonLeft"); this.buttonRight = new GUIStyle("ButtonRight"); this.buttonMid = new GUIStyle("ButtonMid"); } for (int i = NGNavSelectionWindow.historic.Count - 1; i >= 0 && i >= NGNavSelectionWindow.historic.Count - this.maxElements; i--) { AssetsSelection selection = NGNavSelectionWindow.historic[i]; Texture2D image = null; string label = string.Empty; if (selection.refs.Count > 0) { if (selection.refs[0].@object == null) { if (selection.refs[0].hierarchy.Count > 0) { label = (string.IsNullOrEmpty(selection.refs[0].resolverAssemblyQualifiedName) == false ? "(R)" : "") + selection.refs[0].hierarchy[selection.refs[0].hierarchy.Count - 1]; } else { label = "Unknown"; } } else { label = selection.refs[0][email protected]; } } if (selection.refs.Count > 1) { label = "(" + selection.refs.Count + ") " + label; } image = Utility.GetIcon(selection.refs[0][email protected]()); float width = this.maxWidth; GUIStyle style; if (i == NGNavSelectionWindow.historic.Count - 1) { style = this.buttonLeft; } else if (i == 0 || i == NGNavSelectionWindow.historic.Count - this.maxElements) { style = this.buttonRight; } else { style = this.buttonMid; } Rect r = GUILayoutUtility.GetRect(GUIContent.none, style, GUILayoutOptionPool.Height(this.hub.height), GUILayoutOptionPool.Width(width)); if (Event.current.type == EventType.MouseDrag && (this.dragOriginPosition - Event.current.mousePosition).sqrMagnitude >= Constants.MinStartDragDistance && i.Equals(DragAndDrop.GetGenericData(Utility.DragObjectDataName)) == true) { DragAndDrop.StartDrag("Drag Object"); Event.current.Use(); } else if (Event.current.type == EventType.MouseDown && r.Contains(Event.current.mousePosition) == true) { this.dragOriginPosition = Event.current.mousePosition; if (Event.current.button == 0) { DragAndDrop.PrepareStartDrag(); DragAndDrop.objectReferences = new UnityEngine.Object[] { selection.refs[0].@object }; DragAndDrop.SetGenericData(Utility.DragObjectDataName, i); DragAndDrop.SetGenericData(NGHubWindow.DragFromNGHub, true); } } if (GUI.Button(r, string.Empty, style) == true) { if (Event.current.button == 1 || this.lastClick + Constants.DoubleClickTime > EditorApplication.timeSinceStartup) { selection.Select(); NGNavSelectionWindow.lastFocusedHistoric = i; Utility.RepaintEditorWindow(typeof(NGNavSelectionWindow)); } else if (Event.current.button == 0) { EditorGUIUtility.PingObject(selection.refs[0].@object); } this.lastClick = EditorApplication.timeSinceStartup; } if (image != null) { width = r.width; r.xMax = r.xMin + 16F; r.x += 2F; GUI.DrawTexture(r, image, ScaleMode.ScaleToFit); r.xMin += r.width; r.width = width - r.width - 20F; } r.y += 3F; Utility.content.text = label; Utility.content.tooltip = label; GUI.Label(r, Utility.content, this.unwrapLabel); } Utility.content.tooltip = null; }
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"); } }
private void DrawSelection(Rect r, AssetsSelection selection, int i) { if (Event.current.type == EventType.Repaint) { if (i == NGNavSelectionWindow.historicCursor || (NGNavSelectionWindow.historicCursor == -1 && i == NGNavSelectionWindow.historic.Count - 1 && Selection.activeObject == NGNavSelectionWindow.historic[NGNavSelectionWindow.historic.Count - 1][0])) { float w = r.width; r.width = NGNavSelectionWindow.HighlightCursorWidth; EditorGUI.DrawRect(r, NGNavSelectionWindow.HighlightCursorBackgroundColor); r.x += r.width; r.width = w - r.width; } if (i == NGNavSelectionWindow.lastFocusedHistoric) { float w = r.width; r.width = NGNavSelectionWindow.HighlightCursorWidth; EditorGUI.DrawRect(r, NGNavSelectionWindow.HighlightFocusedHistoricBackgroundColor); r.x += r.width; r.width = w - r.width; } } if (Event.current.type == EventType.MouseDrag && (this.dragOriginPosition - Event.current.mousePosition).sqrMagnitude >= Constants.MinStartDragDistance && i.Equals(DragAndDrop.GetGenericData(Utility.DragObjectDataName)) == true) { DragAndDrop.StartDrag("Drag Object"); Event.current.Use(); } else if (Event.current.type == EventType.MouseDown && r.Contains(Event.current.mousePosition) == true) { this.dragOriginPosition = Event.current.mousePosition; if (Event.current.button == 0) { DragAndDrop.PrepareStartDrag(); DragAndDrop.objectReferences = new UnityEngine.Object[] { selection.refs[0].@object }; DragAndDrop.SetGenericData(Utility.DragObjectDataName, i); } } if (selection.refs.Count == 1) { Utility.content.text = this.GetHierarchy(selection.refs[0].@object); } else { Utility.content.text = "(" + selection.refs.Count + ") " + this.GetHierarchy(selection.refs[0].@object); } Utility.content.image = Utility.GetIcon(selection.refs[0].instanceID); if (GUI.Button(r, Utility.content, GeneralStyles.ToolbarButtonLeft)) { if (Event.current.button == 1 || this.lastClick + Constants.DoubleClickTime > EditorApplication.timeSinceStartup) { selection.Select(); NGNavSelectionWindow.lastFocusedHistoric = i; } else if (Event.current.button == 0) { EditorGUIUtility.PingObject(selection.refs[0].instanceID); } this.lastClick = EditorApplication.timeSinceStartup; } Utility.content.image = null; }