예제 #1
0
        private static void     UpdateSelection()
        {
            int hash = NGNavSelectionWindow.GetCurrentSelectionHash();

            if (NGNavSelectionWindow.lastHash == hash || hash == 0)
            {
                return;
            }

            if (Selection.objects.Length > 0)
            {
                // Prevent adding a new selection if the user just selected it through NG Nav Selection.
                if (0 <= NGNavSelectionWindow.lastFocusedHistoric && NGNavSelectionWindow.lastFocusedHistoric < NGNavSelectionWindow.historic.Count && NGNavSelectionWindow.historic[NGNavSelectionWindow.lastFocusedHistoric].GetSelectionHash() == hash)
                {
                    return;
                }

                NGNavSelectionWindow.hasChanged = true;

                // Add a new selection or update the last one.
                if (NGNavSelectionWindow.historicCursor != -1)
                {
                    NGNavSelectionWindow.historic.RemoveRange(NGNavSelectionWindow.historicCursor + 1, NGNavSelectionWindow.historic.Count - NGNavSelectionWindow.historicCursor - 1);
                    NGNavSelectionWindow.historicCursor = -1;
                }

                // Detect a change in the selection only if user selects ONE Object.
                if (Selection.objects.Length == 1)
                {
                    NGNavSelectionWindow.historic.Add(new AssetsSelection(Selection.objects, Selection.instanceIDs));
                }
                else if (NGNavSelectionWindow.historic.Count >= 1)
                {
                    NGNavSelectionWindow.historic[NGNavSelectionWindow.historic.Count - 1] = new AssetsSelection(Selection.objects, Selection.instanceIDs);
                }

                NavSettings settings = HQ.Settings.Get <NavSettings>();

                if (settings.maxHistoric > 0 && NGNavSelectionWindow.historic.Count > settings.maxHistoric)
                {
                    NGNavSelectionWindow.historic.RemoveRange(0, NGNavSelectionWindow.historic.Count - settings.maxHistoric);
                }
            }
            else
            {
                NGNavSelectionWindow.historicCursor = -1;
            }

            NGNavSelectionWindow.lastFocusedHistoric = -1;

            NGNavSelectionWindow.lastHash = hash;
            if (NGNavSelectionWindow.SelectionChanged != null)
            {
                NGNavSelectionWindow.SelectionChanged();
            }
        }
예제 #2
0
        private string  GetHierarchy(Object obj)
        {
            if (obj == null)
            {
                return("NULL");
            }

            NavSettings settings = HQ.Settings.Get <NavSettings>();

            if (settings.maxDisplayHierarchy == 0)
            {
                return(obj.name);
            }

            GameObject go = obj as GameObject;

            if (go != null)
            {
                StringBuilder buffer    = Utility.GetBuffer();
                Transform     transform = go.transform;

                buffer.Insert(0, transform.gameObject.name);
                buffer.Insert(0, '/');
                transform = transform.parent;

                for (int i = 0; (settings.maxDisplayHierarchy == -1 || i < settings.maxDisplayHierarchy) && transform != null; i++)
                {
                    buffer.Insert(0, transform.gameObject.name);
                    buffer.Insert(0, '/');
                    transform = transform.parent;
                }

                buffer.Remove(0, 1);

                return(Utility.ReturnBuffer(buffer));
            }
            else
            {
                string path = AssetDatabase.GetAssetPath(obj);

                if (string.IsNullOrEmpty(path) == false)
                {
                    if (settings.maxDisplayHierarchy == -1)
                    {
                        return(path);
                    }

                    for (int i = path.Length - 1, j = 0; i >= 0; --i)
                    {
                        if (path[i] == '/')
                        {
                            ++j;

                            if (j - 1 == settings.maxDisplayHierarchy)
                            {
                                return(path.Substring(i + 1));
                            }
                        }
                    }

                    return(path);
                }
            }

            return(obj.name);
        }
예제 #3
0
        private static void     OnGUISettings()
        {
            if (HQ.Settings == null)
            {
                return;
            }

            NavSettings settings = HQ.Settings.Get <NavSettings>();

            if (Application.platform != RuntimePlatform.WindowsEditor)
            {
                EditorGUILayout.LabelField(LC.G("NGNavSelection_OnlyAvailableOnWindows"), GeneralStyles.WrapLabel);
            }

            EditorGUI.BeginChangeCheck();
            EditorGUILayout.Space();
            using (BgColorContentRestorer.Get(settings.enable == true ? Color.green : Color.red))
            {
                EditorGUILayout.BeginVertical("ButtonLeft");
                {
                    EditorGUILayout.BeginHorizontal();
                    {
                        settings.enable = NGEditorGUILayout.Switch(LC.G("Enable"), settings.enable);
                    }
                    EditorGUILayout.EndHorizontal();
                    EditorGUILayout.LabelField(LC.G("NGNavSelection_EnableDescription"), GeneralStyles.WrapLabel);
                }
                EditorGUILayout.EndVertical();
            }

            if (EditorGUI.EndChangeCheck() == true)
            {
                if (settings.enable == false)
                {
                    Selection.selectionChanged -= NGNavSelectionWindow.UpdateSelection;
#if !UNITY_2017_2_OR_NEWER
                    EditorApplication.playmodeStateChanged -= NGNavSelectionWindow.OnPlayStateChanged;
#else
                    EditorApplication.playModeStateChanged -= NGNavSelectionWindow.OnPlayStateChanged;
#endif
                }
                else
                {
                    Selection.selectionChanged += NGNavSelectionWindow.UpdateSelection;
#if !UNITY_2017_2_OR_NEWER
                    EditorApplication.playmodeStateChanged += NGNavSelectionWindow.OnPlayStateChanged;
#else
                    EditorApplication.playModeStateChanged += NGNavSelectionWindow.OnPlayStateChanged;
#endif
                }
                HQ.InvalidateSettings();
            }

            EditorGUI.BeginChangeCheck();
            EditorGUILayout.Space();
            EditorGUILayout.LabelField(LC.G("NGNavSelection_MaxHistoricDescription"), GeneralStyles.WrapLabel);
            settings.maxHistoric = EditorGUILayout.IntField(LC.G("NGNavSelection_MaxHistoric"), settings.maxHistoric);
            if (EditorGUI.EndChangeCheck() == true)
            {
                settings.maxHistoric = Mathf.Clamp(settings.maxHistoric, 1, NGNavSelectionWindow.MaxHistoric);
                HQ.InvalidateSettings();
            }

            EditorGUI.BeginChangeCheck();
            EditorGUILayout.Space();
            EditorGUILayout.LabelField(LC.G("NGNavSelection_MaxDisplayHierarchyDescription"), GeneralStyles.WrapLabel);
            settings.maxDisplayHierarchy = EditorGUILayout.IntField(LC.G("NGNavSelection_MaxDisplayHierarchy"), settings.maxDisplayHierarchy);
            if (EditorGUI.EndChangeCheck() == true)
            {
                if (settings.maxDisplayHierarchy < -1)
                {
                    settings.maxDisplayHierarchy = -1;
                }
                HQ.InvalidateSettings();
            }
        }