Example #1
0
        private static void     SceneAddSelection(MenuCommand menuCommand)
        {
            if (NGFavWindow.avoidMultiAdd == true)
            {
                return;
            }

            NGFavWindow.avoidMultiAdd = true;

            NGFavWindow fav = EditorWindow.GetWindow <NGFavWindow>(NGFavWindow.Title);

            fav.CreateSelection(Selection.objects);
        }
Example #2
0
 private static void     GoToFav2()
 {
     NGFavWindow.SelectFav(1);
 }
Example #3
0
 private static void     GoToFav1()
 {
     NGFavWindow.SelectFav(0);
 }
Example #4
0
        private static void     AssetAddSelection(MenuCommand menuCommand)
        {
            NGFavWindow fav = EditorWindow.GetWindow <NGFavWindow>(NGFavWindow.Title);

            fav.CreateSelection(Selection.GetFiltered(typeof(Object), SelectionMode.Unfiltered));
        }
Example #5
0
        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();
            }
        }
Example #6
0
        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");
            }
        }
Example #7
0
 private static void     GoToFav8()
 {
     NGFavWindow.SelectFav(7);
 }
Example #8
0
 private static void     GoToFav9()
 {
     NGFavWindow.SelectFav(8);
 }
Example #9
0
 private static void     GoToFav7()
 {
     NGFavWindow.SelectFav(6);
 }
Example #10
0
 private static void     GoToFav6()
 {
     NGFavWindow.SelectFav(5);
 }
Example #11
0
 private static void     GoToFav5()
 {
     NGFavWindow.SelectFav(4);
 }
Example #12
0
 private static void     GoToFav4()
 {
     NGFavWindow.SelectFav(3);
 }
Example #13
0
 private static void     GoToFav3()
 {
     NGFavWindow.SelectFav(2);
 }