Пример #1
0
        static float drawCustomTagIcon(GameObject gameObject, Rect rect)
        {
            bool fixedIconWidth = QHierarchySettings.getSetting <bool>(QHierarchySetting.FixedIconWidth);

            rect.x    -= 18;
            rect.width = 18;

            string      gameObjectTag = gameObject.tag;
            QTagTexture tagTexture    = QHierarchySettings.getSetting <List <QTagTexture> >(QHierarchySetting.CustomTagIcon).Find(t => t.tag == gameObjectTag);

            if (tagTexture != null)
            {
                EditorGUI.DrawRect(rect, backgroundColor);
                rect.width = 16;
                GUI.DrawTexture(rect, tagTexture.texture, ScaleMode.ScaleToFit, true);
                return(18);
            }
            else if (fixedIconWidth)
            {
                if (!QHierarchySettings.getSetting <bool>(QHierarchySetting.CustomTagIconReplace))
                {
                    EditorGUI.DrawRect(rect, backgroundColor);
                }
                return(18);
            }
            return(0);
        }
Пример #2
0
        private static void PlayModeChanged()
        {
            if (QHierarchySettings.getSetting <bool>(QHierarchySetting.ShowVisibilityButton) && objectList != null)
            {
                if (!EditorApplication.isPlaying && EditorApplication.isPlayingOrWillChangePlaymode)
                {
                    foreach (GameObject gameObject in objectList.editModeVisibileObjects)
                    {
                        gameObject.SetActive(false);
                    }

                    foreach (GameObject gameObject in objectList.editModeInvisibleObjects)
                    {
                        gameObject.SetActive(true);
                    }
                }
                else if (EditorApplication.isPlaying && !EditorApplication.isPlayingOrWillChangePlaymode)
                {
                    foreach (GameObject gameObject in objectList.editModeVisibileObjects)
                    {
                        gameObject.SetActive(true);
                    }

                    foreach (GameObject gameObject in objectList.editModeInvisibleObjects)
                    {
                        gameObject.SetActive(false);
                    }
                }
            }
        }
Пример #3
0
        static void Update()
        {
            try
            {
                if (!inited)
                {
                    init();
                }
                if (objectListDictionary.Count == 0 || checkSceneChanged())
                {
                    updateObjectListDictionary();
                }

                HideFlags hideFlag = QHierarchySettings.getSetting <bool>(QHierarchySetting.ShowHiddenQHierarchyObjectList) ? HideFlags.None : HideFlags.HideInHierarchy;
                foreach (KeyValuePair <Scene, QObjectList> objectListKeyValue in objectListDictionary)
                {
                    QObjectList objectList = objectListKeyValue.Value;
                    if (objectList.gameObject.hideFlags != hideFlag)
                    {
                        objectList.gameObject.hideFlags = hideFlag;
                        EditorApplication.DirtyHierarchyWindowSorting();
                    }
                }

                if (checkSelectionChanged())
                {
                    if (QHierarchySettings.getSetting <bool>(QHierarchySetting.ShowLockButton) &&
                        QHierarchySettings.getSetting <bool>(QHierarchySetting.PreventSelectionOfLockedObjects))
                    {
                        GameObject[]      selections = Selection.gameObjects;
                        List <GameObject> actual     = new List <GameObject>();
                        bool found = false;
                        for (int i = 0; i < selections.Length; i++)
                        {
                            GameObject selectedGameObject = selections[i];
                            if (objectListDictionary.ContainsKey(selectedGameObject.scene))
                            {
                                bool isLock = objectListDictionary[selectedGameObject.scene].lockedObjects.Contains(selections[i]);
                                if (!isLock)
                                {
                                    actual.Add(selections[i]);
                                }
                                else
                                {
                                    found = true;
                                }
                            }
                        }
                        if (found)
                        {
                            Selection.objects = actual.ToArray();
                        }
                    }
                }
            }
            catch
            {
                updateObjectListDictionary();
            }
        }
Пример #4
0
        static float drawLockButton(GameObject gameObject, Rect rect)
        {
            rect.x    -= 13;
            rect.width = 13;

            bool isLock = objectList == null ? false : objectList.lockedObjects.Contains(gameObject);

            if (isLock == true && (gameObject.hideFlags & HideFlags.NotEditable) != HideFlags.NotEditable)
            {
                gameObject.hideFlags |= HideFlags.NotEditable;
                EditorUtility.SetDirty(gameObject);
            }
            else if (isLock == false && (gameObject.hideFlags & HideFlags.NotEditable) == HideFlags.NotEditable)
            {
                gameObject.hideFlags ^= HideFlags.NotEditable;
                EditorUtility.SetDirty(gameObject);
            }

            if (GUI.Button(rect, isLock ? QHierarchyResource.getTexture(QHierarchyTexture.ButtonLockOn) : QHierarchyResource.getTexture(QHierarchyTexture.ButtonLockOff), guiStyle))
            {
                Undo.RecordObject(getObjectList(), "Change GameObject Lock");

                bool showWarning = QHierarchySettings.getSetting <bool>(QHierarchySetting.ShowModifierWarning);
                if (Event.current.shift)
                {
                    if (!showWarning || EditorUtility.DisplayDialog("Change locking",
                                                                    "Are you sure you want to " + (isLock ? "unlock" : "lock") + " this GameObject and all its children?",
                                                                    "Yes",
                                                                    "Cancel"))
                    {
                        setLockRecursive(gameObject.transform, !isLock);
                    }
                }
                else if (Event.current.alt)
                {
                    if (!showWarning || EditorUtility.DisplayDialog("Change locking",
                                                                    "Are you sure you want to " + (isLock ? "unlock" : "lock") + " this GameObject and its siblings?",
                                                                    "Yes",
                                                                    "Cancel"))
                    {
                        setLockRecursive(gameObject.transform, !isLock, 1);
                    }
                }
                else
                {
                    setLockRecursive(gameObject.transform, !isLock, 0);
                }

                EditorUtility.SetDirty(objectList);
                if (Selection.activeGameObject != null)
                {
                    EditorUtility.SetDirty(Selection.activeGameObject);
                }
            }
            return(rect.width);
        }
Пример #5
0
        static void drawTreeMap(GameObject gameObject, Rect selectionRect)
        {
            Transform gameObjectTransform = gameObject.transform;

            bool hasChild = false;

            hasChild = gameObjectTransform.childCount > 0;

            bool foundCustomComponent = false;

            if (QHierarchySettings.getSetting <bool>(QHierarchySetting.IgnoreUnityMonobehaviour))
            {
                Component[] components = gameObject.GetComponents <MonoBehaviour>();

                for (int i = 0; i < components.Length; i++)
                {
                    if (components[i] != null)
                    {
                        string fullName = components[i].GetType().FullName;
                        if (fullName.Contains("UnityEngine"))
                        {
                            continue;
                        }
                        foundCustomComponent = true;
                        break;
                    }
                }
            }
            else
            {
                foundCustomComponent = gameObject.GetComponent <MonoBehaviour>() != null;
            }

            Rect treeMapRect = new Rect(selectionRect);

            treeMapRect.width = treeMapRect.x + 28;
            treeMapRect.x     = 0;

            int ident = Mathf.FloorToInt(treeMapRect.width / 14) - 1;

            treeMapRect.width = (ident) * 14;
            float stepX  = 1.0f / (896.0f / 14.0f);
            float rectX  = (hasChild ? 1.0f : 0.5f) - ident * stepX;
            float scaleX = ident * stepX;

            bool showMonoBehaviourIcon = QHierarchySettings.getSetting <bool>(QHierarchySetting.ShowMonoBehaviourIcon);

            float stepY = 1.0f / (64.0f / 16.0f);
            float rectY = 1.0f - stepY * (QHierarchySettings.getSetting <bool>(QHierarchySetting.ShowTreeMap) ?
                                          (showMonoBehaviourIcon ? (foundCustomComponent == false ? 1 : 2) : 1) :
                                          (showMonoBehaviourIcon ? (foundCustomComponent == false ? 3 : 4) : 3));
            float scaleY = 0.25f;

            GUI.DrawTextureWithTexCoords(treeMapRect, QHierarchyResource.getTexture(QHierarchyTexture.BackgroundTreeMap), new Rect(rectX, rectY, scaleX, scaleY));
        }
Пример #6
0
        static void Update()
        {
            if (!inited)
            {
                init();
            }

            if (objectList == null)
            {
                objectList = getObjectList(false);
                if (objectList == null)
                {
                    return;
                }
            }

            HideFlags hideFlag = QHierarchySettings.getSetting <bool>(QHierarchySetting.ShowHiddenQHierarchyObjectList) ? HideFlags.None : HideFlags.HideInHierarchy;

            #if !UNITY_4_6
            hideFlag = hideFlag | HideFlags.DontSaveInBuild;
            #endif

            if (objectList.gameObject.hideFlags != hideFlag)
            {
                objectList.gameObject.hideFlags = hideFlag;
            }

            if (QHierarchySettings.getSetting <bool>(QHierarchySetting.ShowLockButton) &&
                QHierarchySettings.getSetting <bool>(QHierarchySetting.PreventSelectionOfLockedObjects))
            {
                GameObject[]      selections = Selection.gameObjects;
                List <GameObject> actual     = new List <GameObject>();
                bool found = false;
                for (int i = 0; i < selections.Length; i++)
                {
                    bool isLock = objectList.lockedObjects.Contains(selections[i]);
                    if (!isLock)
                    {
                        actual.Add(selections[i]);
                    }
                    else
                    {
                        found = true;
                    }
                }
                if (found)
                {
                    Selection.objects = actual.ToArray();
                }
            }
        }
Пример #7
0
        static float drawStaticIcon(GameObject gameObject, Rect rect)
        {
            rect.x    -= 14;
            rect.width = 14;

            bool isStatic = gameObject.isStatic;
            StaticEditorFlags staticFlags = GameObjectUtility.GetStaticEditorFlags(gameObject);

            Texture2D buttonTexture = isStatic ?
                                      ((int)staticFlags == -1 ?
                                       QHierarchyResource.getTexture(QHierarchyTexture.ButtonStaticOn)
                    : QHierarchyResource.getTexture(QHierarchyTexture.ButtonStaticHalf))
                : QHierarchyResource.getTexture(QHierarchyTexture.ButtonStaticOff);

            if (GUI.Button(rect, buttonTexture, guiStyle))
            {
                Undo.RecordObject(gameObject, "Change GameObject Static");

                bool showWarning = QHierarchySettings.getSetting <bool>(QHierarchySetting.ShowModifierWarning);
                if (Event.current.shift)
                {
                    if (!showWarning || EditorUtility.DisplayDialog("Change static",
                                                                    "Are you sure you want to " + (isStatic ? "disable" : "enable") + " Static of this GameObject and all its children?",
                                                                    "Yes",
                                                                    "Cancel"))
                    {
                        setStaticRecursive(gameObject.transform, !isStatic);
                    }
                }
                else if (Event.current.alt)
                {
                    if (!showWarning || EditorUtility.DisplayDialog("Change static",
                                                                    "Are you sure you want to " + (isStatic ? "disable" : "enable") + " Static of this GameObject and all its siblings?",
                                                                    "Yes",
                                                                    "Cancel"))
                    {
                        setStaticRecursive(gameObject.transform, !isStatic, 1);
                    }
                }
                else
                {
                    setStaticRecursive(gameObject.transform, !isStatic, 0);
                }
            }
            return(rect.width);
        }
Пример #8
0
        static float drawGameObjectIcon(GameObject gameObject, Rect rect)
        {
            bool      fixedIconWidth = QHierarchySettings.getSetting <bool>(QHierarchySetting.FixedIconWidth);
            Texture2D icon           = (Texture2D)GetIconForObject.Invoke(null, new object[] { gameObject });

            rect.x    -= 18;
            rect.width = 18;
            if (icon != null)
            {
                EditorGUI.DrawRect(rect, backgroundColor);
                rect.width = 16;
                GUI.DrawTexture(rect, icon, ScaleMode.ScaleToFit, true);
                return(18);
            }
            else if (fixedIconWidth)
            {
                EditorGUI.DrawRect(rect, backgroundColor);
                return(18);
            }
            return(0);
        }
Пример #9
0
        private bool drawTitle(QHierarchySetting foldoutSetting, string title)
        {
            bool foldout = QHierarchySettings.getSetting <bool>(foldoutSetting);

            GUILayout.Space(5);
            Rect rect = EditorGUILayout.GetControlRect(GUILayout.ExpandWidth(true), GUILayout.Height(24));

            rect.width += rect.x * 2 + 1;
            rect.x      = 0;
            GUI.Box(rect, "");
            GUILayout.Space(5);

            rect.x  = 5;
            rect.y += 4;
            bool newFoldout = EditorGUI.Foldout(rect, foldout, title);

            if (newFoldout != foldout)
            {
                QHierarchySettings.setSetting(foldoutSetting, newFoldout);
            }
            return(newFoldout);
        }
Пример #10
0
        private void drawTagTextureList()
        {
            bool changed = false;

            List <QTagTexture> tagTextureList = QHierarchySettings.getSetting <List <QTagTexture> >(QHierarchySetting.CustomTagIcon);

            for (int i = 0; i < UnityEditorInternal.InternalEditorUtility.tags.Length; i++)
            {
                string      tag        = UnityEditorInternal.InternalEditorUtility.tags[i];
                QTagTexture tagTexture = tagTextureList.Find(t => t.tag == tag);
                Texture2D   newTexture = (Texture2D)EditorGUILayout.ObjectField(tag, tagTexture == null ? null : tagTexture.texture, typeof(Texture2D), false, GUILayout.MaxHeight(16));
                if (newTexture != null && tagTexture == null)
                {
                    QTagTexture newTagTexture = new QTagTexture(tag, newTexture);
                    tagTextureList.Add(newTagTexture);

                    changed = true;
                }
                else if (newTexture == null && tagTexture != null)
                {
                    tagTextureList.Remove(tagTexture);

                    changed = true;
                }
                else if (tagTexture != null && tagTexture.texture != newTexture)
                {
                    tagTexture.texture = newTexture;
                    changed            = true;
                }
            }

            if (changed)
            {
                QHierarchySettings.setSetting(QHierarchySetting.CustomTagIcon, tagTextureList);
                EditorApplication.RepaintHierarchyWindow();
            }
        }
Пример #11
0
        static float drawErrorIcon(GameObject gameObject, Rect rect)
        {
            bool fixedIconWidth = QHierarchySettings.getSetting <bool>(QHierarchySetting.FixedIconWidth);
            bool errorFound     = findError(gameObject.GetComponents <MonoBehaviour>());

            if (errorFound)
            {
                rect.x    -= 16;
                rect.width = 16;
                EditorGUI.DrawRect(rect, backgroundColor);
                GUI.DrawTexture(rect, QHierarchyResource.getTexture(QHierarchyTexture.IconError));
            }
            else if (fixedIconWidth)
            {
                rect.x    -= 16;
                rect.width = 16;
                EditorGUI.DrawRect(rect, backgroundColor);
                rect.x += 16;
            }

            if (QHierarchySettings.getSetting <bool>(QHierarchySetting.ShowErrorIconParent) && !errorFound)
            {
                bool childErrorFound = findError(gameObject.GetComponentsInChildren <MonoBehaviour>(true));
                if (childErrorFound)
                {
                    rect.x    -= 16;
                    rect.width = 16;
                    GUI.DrawTexture(rect, QHierarchyResource.getTexture(QHierarchyTexture.IconErrorChild));
                }
                return(childErrorFound ? 16 : (fixedIconWidth ? 16 : 0));
            }
            else
            {
                return(errorFound ? 16 : (fixedIconWidth ? 16 : 0));
            }
        }
Пример #12
0
        static float drawStaticIcon(GameObject gameObject, Rect rect)
        {
            rect.x    -= 14;
            rect.width = 14;

            bool isStatic = gameObject.isStatic;
            StaticEditorFlags staticFlags = GameObjectUtility.GetStaticEditorFlags(gameObject);

            Texture2D buttonTexture = isStatic ?
                                      ((int)staticFlags == -1 ?
                                       QHierarchyResource.getTexture(QHierarchyTexture.ButtonStaticOn)
                    : QHierarchyResource.getTexture(QHierarchyTexture.ButtonStaticHalf))
                : QHierarchyResource.getTexture(QHierarchyTexture.ButtonStaticOff);

            GUI.DrawTexture(rect, buttonTexture);

            if (Event.current.isMouse && Event.current.button == 0 && rect.Contains(Event.current.mousePosition))
            {
                if (Event.current.type == EventType.MouseDown)
                {
                    targetStaticState = ((!isStatic) == true ? 1 : 0);
                }
                else if (Event.current.type == EventType.MouseDrag && targetStaticState != -1)
                {
                    if (targetStaticState == (isStatic == true ? 1 : 0))
                    {
                        return(rect.width);
                    }
                }
                else
                {
                    targetStaticState = -1;
                    return(rect.width);
                }

                Event.current.Use();

                Undo.RecordObject(gameObject, "Change GameObject Static");

                bool showWarning = QHierarchySettings.getSetting <bool>(QHierarchySetting.ShowModifierWarning);
                if (Event.current.shift)
                {
                    if (!showWarning || EditorUtility.DisplayDialog("Change static",
                                                                    "Are you sure you want to " + (isStatic ? "disable" : "enable") + " Static of this GameObject and all its children? (You can disable this warning in the settings)",
                                                                    "Yes",
                                                                    "Cancel"))
                    {
                        setStaticRecursive(gameObject.transform, !isStatic);
                    }
                }
                else if (Event.current.alt)
                {
                    if (!showWarning || EditorUtility.DisplayDialog("Change static",
                                                                    "Are you sure you want to " + (isStatic ? "disable" : "enable") + " Static of this GameObject and all its siblings? (You can disable this warning in the settings)",
                                                                    "Yes",
                                                                    "Cancel"))
                    {
                        setStaticRecursive(gameObject.transform, !isStatic, 1);
                    }
                }
                else
                {
                    setStaticRecursive(gameObject.transform, !isStatic, 0);
                }
            }
            return(rect.width);
        }
Пример #13
0
        void OnGUI()
        {
            bool fixedIconWidth        = QHierarchySettings.getSetting <bool>(QHierarchySetting.FixedIconWidth);
            bool showErrorIcon         = QHierarchySettings.getSetting <bool>(QHierarchySetting.ShowErrorIcon);
            bool showGameObjectIcon    = QHierarchySettings.getSetting <bool>(QHierarchySetting.ShowGameObjectIcon);
            bool showTagAndLayerText   = QHierarchySettings.getSetting <bool>(QHierarchySetting.ShowTagAndLayerText);
            bool showCustomTagIcon     = QHierarchySettings.getSetting <bool>(QHierarchySetting.ShowCustomTagIcon);
            bool showLockButton        = QHierarchySettings.getSetting <bool>(QHierarchySetting.ShowLockButton);
            bool showStaticIcon        = QHierarchySettings.getSetting <bool>(QHierarchySetting.ShowStaticIcon);
            bool showMonoBehaviourIcon = QHierarchySettings.getSetting <bool>(QHierarchySetting.ShowMonoBehaviourIcon);

            scrollPosition = EditorGUILayout.BeginScrollView(scrollPosition);
            {
                GUILayout.Space(5);

                if (drawTitle(QHierarchySetting.GeneralSettingsFoldout, " General Settings"))
                {
                    bool showVisibilityButton = QHierarchySettings.getSetting <bool>(QHierarchySetting.ShowVisibilityButton);
                    if (EditorGUILayout.ToggleLeft(" Show Visibility Button", showVisibilityButton) != showVisibilityButton)
                    {
                        QHierarchySettings.setSetting(QHierarchySetting.ShowVisibilityButton, !showVisibilityButton);
                    }

                    if (EditorGUILayout.ToggleLeft(" Show Lock Button", showLockButton) != showLockButton)
                    {
                        QHierarchySettings.setSetting(QHierarchySetting.ShowLockButton, !showLockButton);
                        if (showLockButton)
                        {
                            QHierarchy.unlockAll();
                        }
                    }

                    bool showMeshButton = QHierarchySettings.getSetting <bool>(QHierarchySetting.ShowMeshButton);
                    if (EditorGUILayout.ToggleLeft(" Show Renderer Button", showMeshButton) != showMeshButton)
                    {
                        QHierarchySettings.setSetting(QHierarchySetting.ShowMeshButton, !showMeshButton);
                    }

                    if (EditorGUILayout.ToggleLeft(" Show MonoBehavior Icon", showMonoBehaviourIcon) != showMonoBehaviourIcon)
                    {
                        QHierarchySettings.setSetting(QHierarchySetting.ShowMonoBehaviourIcon, !showMonoBehaviourIcon);
                    }

                    if (EditorGUILayout.ToggleLeft(" Show Error Icon", showErrorIcon) != showErrorIcon)
                    {
                        QHierarchySettings.setSetting(QHierarchySetting.ShowErrorIcon, !showErrorIcon);
                    }

                    if (EditorGUILayout.ToggleLeft(" Show Game Object icon", showGameObjectIcon) != showGameObjectIcon)
                    {
                        QHierarchySettings.setSetting(QHierarchySetting.ShowGameObjectIcon, !showGameObjectIcon);
                    }

                    if (EditorGUILayout.ToggleLeft(" Show Tag And Layer", showTagAndLayerText) != showTagAndLayerText)
                    {
                        QHierarchySettings.setSetting(QHierarchySetting.ShowTagAndLayerText, !showTagAndLayerText);
                    }

                    if (EditorGUILayout.ToggleLeft(" Show Custom Tag Icon", showCustomTagIcon) != showCustomTagIcon)
                    {
                        QHierarchySettings.setSetting(QHierarchySetting.ShowCustomTagIcon, !showCustomTagIcon);
                    }

                    if (EditorGUILayout.ToggleLeft(" Show Static Button", showStaticIcon) != showStaticIcon)
                    {
                        QHierarchySettings.setSetting(QHierarchySetting.ShowStaticIcon, !showStaticIcon);
                    }
                }

                if (drawTitle(QHierarchySetting.AppearanceSettingsFoldout, " Appearance Settings"))
                {
                    bool showTreeMap = QHierarchySettings.getSetting <bool>(QHierarchySetting.ShowTreeMap);
                    if (EditorGUILayout.ToggleLeft(" Show Hierarchy Tree", showTreeMap) != showTreeMap)
                    {
                        QHierarchySettings.setSetting(QHierarchySetting.ShowTreeMap, !showTreeMap);
                    }

                    bool showHiddenObjectList = QHierarchySettings.getSetting <bool>(QHierarchySetting.ShowHiddenQHierarchyObjectList);
                    if (EditorGUILayout.ToggleLeft(" Show QHierarchy GameObject", showHiddenObjectList) != showHiddenObjectList)
                    {
                        QHierarchySettings.setSetting(QHierarchySetting.ShowHiddenQHierarchyObjectList, !showHiddenObjectList);
                    }

                    bool showModifierWarning = QHierarchySettings.getSetting <bool>(QHierarchySetting.ShowModifierWarning);
                    if (EditorGUILayout.ToggleLeft(" Show Warning When Using Modifier + Click", showModifierWarning) != showModifierWarning)
                    {
                        QHierarchySettings.setSetting(QHierarchySetting.ShowModifierWarning, !showModifierWarning);
                    }

                    if (EditorGUILayout.ToggleLeft(" Fixed Icons Width", fixedIconWidth) != fixedIconWidth)
                    {
                        fixedIconWidth = !fixedIconWidth;
                        QHierarchySettings.setSetting(QHierarchySetting.FixedIconWidth, fixedIconWidth);
                        if (fixedIconWidth)
                        {
                            QHierarchySettings.setSetting(QHierarchySetting.TagAndLayerSizeType, (int)QHierarchyTagAndLayerSizeType.Fixed);
                        }
                    }

                    int identation    = QHierarchySettings.getSetting <int>(QHierarchySetting.Identation);
                    int newIdentation = EditorGUILayout.IntSlider("    Indentation", identation, 0, 200);
                    if (newIdentation != identation)
                    {
                        QHierarchySettings.setSetting(QHierarchySetting.Identation, newIdentation);
                    }
                }

                if (drawTitle(QHierarchySetting.OrderSettingsFoldout, " Order Settings"))
                {
                    List <QHierarchyIconType> iconOrder = QHierarchySettings.getSetting <List <QHierarchyIconType> >(QHierarchySetting.IconOrder);
                    for (int i = 0; i < iconOrder.Count; i++)
                    {
                        QHierarchyIconType type = iconOrder[i];
                        EditorGUILayout.BeginHorizontal();
                        {
                            EditorGUILayout.LabelField((i + 1).ToString() + ".", GUILayout.Width(15));
                            Rect rect = EditorGUILayout.GetControlRect(GUILayout.Width(14), GUILayout.Height(14));

                            if (i > 0)
                            {
                                if (GUI.Button(rect, QHierarchyResource.getTexture(QHierarchyTexture.ButtonUp), GUIStyle.none))
                                {
                                    List <QHierarchyIconType> newIconOrder = new List <QHierarchyIconType>();
                                    for (int j = 0; j < iconOrder.Count; j++)
                                    {
                                        if (j == i - 1)
                                        {
                                            newIconOrder.Add(iconOrder[i]);
                                        }
                                        else if (j == i)
                                        {
                                            newIconOrder.Add(iconOrder[i - 1]);
                                        }
                                        else
                                        {
                                            newIconOrder.Add(iconOrder[j]);
                                        }
                                    }
                                    QHierarchySettings.setSetting(QHierarchySetting.IconOrder, newIconOrder);
                                }
                            }

                            rect.x += 18;

                            if (i < iconOrder.Count - 1)
                            {
                                if (GUI.Button(rect, QHierarchyResource.getTexture(QHierarchyTexture.ButtonDown), GUIStyle.none))
                                {
                                    List <QHierarchyIconType> newIconOrder = new List <QHierarchyIconType>();
                                    for (int j = 0; j < iconOrder.Count; j++)
                                    {
                                        if (j == i)
                                        {
                                            newIconOrder.Add(iconOrder[i + 1]);
                                        }
                                        else if (j == i + 1)
                                        {
                                            newIconOrder.Add(iconOrder[i]);
                                        }
                                        else
                                        {
                                            newIconOrder.Add(iconOrder[j]);
                                        }
                                    }
                                    QHierarchySettings.setSetting(QHierarchySetting.IconOrder, newIconOrder);
                                }
                            }

                            rect.x     += 16;
                            rect.width  = 200;
                            rect.height = 20;
                            GUI.Label(rect, addSpaces(type.ToString()));
                        }
                        EditorGUILayout.EndHorizontal();
                    }
                }

                if (showLockButton)
                {
                    if (drawTitle(QHierarchySetting.LockSettingsFoldout, " Lock Settings"))
                    {
                        bool blockLockSelection = QHierarchySettings.getSetting <bool>(QHierarchySetting.PreventSelectionOfLockedObjects);
                        if (EditorGUILayout.ToggleLeft(" Prevent selection of locked objects", blockLockSelection) != blockLockSelection)
                        {
                            QHierarchySettings.setSetting(QHierarchySetting.PreventSelectionOfLockedObjects, !blockLockSelection);
                        }
                    }
                }

                if (showMonoBehaviourIcon)
                {
                    if (drawTitle(QHierarchySetting.MonoBehaviourIconFoldout, " MonoBehaviour Icon Settings"))
                    {
                        bool ignoreUnityMonobehaviour = QHierarchySettings.getSetting <bool>(QHierarchySetting.IgnoreUnityMonobehaviour);
                        if (EditorGUILayout.ToggleLeft(" Ignore UnityEngine MonoBehaviours", ignoreUnityMonobehaviour) != ignoreUnityMonobehaviour)
                        {
                            QHierarchySettings.setSetting(QHierarchySetting.IgnoreUnityMonobehaviour, !ignoreUnityMonobehaviour);
                        }
                    }
                }

                if (showErrorIcon)
                {
                    if (drawTitle(QHierarchySetting.ErrorIconSettingsFoldout, " Error Icon Settings"))
                    {
                        bool showErrorIconParent = QHierarchySettings.getSetting <bool>(QHierarchySetting.ShowErrorIconParent);
                        if (EditorGUILayout.ToggleLeft(" Show error icon on parent game object", showErrorIconParent) != showErrorIconParent)
                        {
                            QHierarchySettings.setSetting(QHierarchySetting.ShowErrorIconParent, !showErrorIconParent);
                        }

                        bool showErrorForDisabledComponents = QHierarchySettings.getSetting <bool>(QHierarchySetting.ShowErrorForDisabledComponents);
                        if (EditorGUILayout.ToggleLeft(" Show error for disabled components", showErrorForDisabledComponents) != showErrorForDisabledComponents)
                        {
                            QHierarchySettings.setSetting(QHierarchySetting.ShowErrorForDisabledComponents, !showErrorForDisabledComponents);
                        }

                        EditorGUILayout.Space();

                        EditorGUILayout.LabelField("Show the following error types:");
                        bool showErrorIconTypeScriptMissing = QHierarchySettings.getSetting <bool>(QHierarchySetting.ShowErrorIconScriptIsMissing);
                        if (EditorGUILayout.ToggleLeft(" Script is missing", showErrorIconTypeScriptMissing) != showErrorIconTypeScriptMissing)
                        {
                            QHierarchySettings.setSetting(QHierarchySetting.ShowErrorIconScriptIsMissing, !showErrorIconTypeScriptMissing);
                        }

                        bool showErrorIconTypeReferenceIsNull = QHierarchySettings.getSetting <bool>(QHierarchySetting.ShowErrorIconReferenceIsNull);
                        if (EditorGUILayout.ToggleLeft(" Reference is null", showErrorIconTypeReferenceIsNull) != showErrorIconTypeReferenceIsNull)
                        {
                            QHierarchySettings.setSetting(QHierarchySetting.ShowErrorIconReferenceIsNull, !showErrorIconTypeReferenceIsNull);
                        }

                        bool showErrorIconTypeStringIsEmpty = QHierarchySettings.getSetting <bool>(QHierarchySetting.ShowErrorIconStringIsEmpty);
                        if (EditorGUILayout.ToggleLeft(" String is empty", showErrorIconTypeStringIsEmpty) != showErrorIconTypeStringIsEmpty)
                        {
                            QHierarchySettings.setSetting(QHierarchySetting.ShowErrorIconStringIsEmpty, !showErrorIconTypeStringIsEmpty);
                        }
                    }
                }

                if (showTagAndLayerText)
                {
                    if (drawTitle(QHierarchySetting.TagAndLayerSettingsFoldout, " Tag And Layer Settings"))
                    {
                        QHierarchyTagAndLayerType tagAndLayerType = (QHierarchyTagAndLayerType)QHierarchySettings.getSetting <int>(QHierarchySetting.TagAndLayerType);
                        QHierarchyTagAndLayerType newTagAndLayerType;
                        if ((newTagAndLayerType = (QHierarchyTagAndLayerType)EditorGUILayout.EnumPopup("Show", tagAndLayerType)) != tagAndLayerType)
                        {
                            QHierarchySettings.setSetting(QHierarchySetting.TagAndLayerType, (int)newTagAndLayerType);
                        }

                        if (fixedIconWidth)
                        {
                            GUI.enabled = false;
                        }

                        QHierarchyTagAndLayerSizeType tagAndLayerSizeType = (QHierarchyTagAndLayerSizeType)QHierarchySettings.getSetting <int>(QHierarchySetting.TagAndLayerSizeType);
                        QHierarchyTagAndLayerSizeType newTagAndLayerSizeType;
                        if ((newTagAndLayerSizeType = (QHierarchyTagAndLayerSizeType)EditorGUILayout.EnumPopup("Layout", tagAndLayerSizeType)) != tagAndLayerSizeType)
                        {
                            QHierarchySettings.setSetting(QHierarchySetting.TagAndLayerSizeType, (int)newTagAndLayerSizeType);
                        }

                        if (fixedIconWidth)
                        {
                            GUI.enabled = true;
                        }

                        if (newTagAndLayerSizeType != QHierarchyTagAndLayerSizeType.Float)
                        {
                            QHierarchyTagAndLayerSizeValueType tagAndLayerSizeValueType = (QHierarchyTagAndLayerSizeValueType)QHierarchySettings.getSetting <int>(QHierarchySetting.TagAndLayerSizeValueType);
                            QHierarchyTagAndLayerSizeValueType newTagAndLayerSizeValueType;
                            if ((newTagAndLayerSizeValueType = (QHierarchyTagAndLayerSizeValueType)EditorGUILayout.EnumPopup("Type", tagAndLayerSizeValueType)) != tagAndLayerSizeValueType)
                            {
                                QHierarchySettings.setSetting(QHierarchySetting.TagAndLayerSizeValueType, (int)newTagAndLayerSizeValueType);
                            }

                            if (newTagAndLayerSizeValueType == QHierarchyTagAndLayerSizeValueType.Pixel)
                            {
                                int tagAndLayerSizeValue = QHierarchySettings.getSetting <int>(QHierarchySetting.TagAndLayerSizeValue);
                                int newLayerSizeValue    = EditorGUILayout.IntSlider("Pixel Width", tagAndLayerSizeValue, 1, 250);
                                if (newLayerSizeValue != tagAndLayerSizeValue)
                                {
                                    QHierarchySettings.setSetting(QHierarchySetting.TagAndLayerSizeValue, newLayerSizeValue);
                                }
                            }
                            else
                            {
                                float tagAndLayerSizeValuePercent    = QHierarchySettings.getSetting <float>(QHierarchySetting.TagAndLayerSizeValuePercent);
                                float newtagAndLayerSizeValuePercent = EditorGUILayout.Slider("Percent Width", tagAndLayerSizeValuePercent, 0, 0.5f);
                                if (tagAndLayerSizeValuePercent != newtagAndLayerSizeValuePercent)
                                {
                                    QHierarchySettings.setSetting(QHierarchySetting.TagAndLayerSizeValuePercent, newtagAndLayerSizeValuePercent);
                                }
                            }

                            QHierarchyTagAndLayerAligment tagAndLayerAligment = (QHierarchyTagAndLayerAligment)QHierarchySettings.getSetting <int>(QHierarchySetting.TagAndLayerAligment);
                            QHierarchyTagAndLayerAligment newTagAndLayerAligment;
                            if ((newTagAndLayerAligment = (QHierarchyTagAndLayerAligment)EditorGUILayout.EnumPopup("Alignment", tagAndLayerAligment)) != tagAndLayerAligment)
                            {
                                QHierarchySettings.setSetting(QHierarchySetting.TagAndLayerAligment, (int)newTagAndLayerAligment);
                            }
                        }
                    }
                }

                if (showCustomTagIcon)
                {
                    if (drawTitle(QHierarchySetting.CustomTagIconFoldout, " Custom Tag Icon"))
                    {
                        bool replaceGameObjectIcon = QHierarchySettings.getSetting <bool>(QHierarchySetting.CustomTagIconReplace);
                        if (EditorGUILayout.ToggleLeft(" Replace Game Object Icon", replaceGameObjectIcon) != replaceGameObjectIcon)
                        {
                            QHierarchySettings.setSetting(QHierarchySetting.CustomTagIconReplace, !replaceGameObjectIcon);
                        }

                        bool customTagIconTextureListFoldout    = QHierarchySettings.getSetting <bool>(QHierarchySetting.CustomTagIconTextureListFoldout);
                        bool customTagIconTextureListFoldoutNew = EditorGUILayout.Foldout(customTagIconTextureListFoldout, " Custom Tag Icon Texture List");

                        if (customTagIconTextureListFoldoutNew != customTagIconTextureListFoldout)
                        {
                            QHierarchySettings.setSetting(QHierarchySetting.CustomTagIconTextureListFoldout, customTagIconTextureListFoldoutNew);
                        }

                        if (customTagIconTextureListFoldoutNew)
                        {
                            EditorGUI.indentLevel++;
                            drawTagTextureList();
                            EditorGUI.indentLevel--;
                        }
                    }
                }
                EditorGUILayout.Space();
            }
            EditorGUILayout.EndScrollView();
        }
Пример #14
0
        static float drawLockButton(GameObject gameObject, Rect rect)
        {
            rect.x    -= 13;
            rect.width = 13;

            bool isLock = objectList == null ? false : objectList.lockedObjects.Contains(gameObject);

            if (isLock == true && (gameObject.hideFlags & HideFlags.NotEditable) != HideFlags.NotEditable)
            {
                gameObject.hideFlags |= HideFlags.NotEditable;
                EditorUtility.SetDirty(gameObject);
            }
            else if (isLock == false && (gameObject.hideFlags & HideFlags.NotEditable) == HideFlags.NotEditable)
            {
                gameObject.hideFlags ^= HideFlags.NotEditable;
                EditorUtility.SetDirty(gameObject);
            }

            GUI.DrawTexture(rect, isLock ? QHierarchyResource.getTexture(QHierarchyTexture.ButtonLockOn) : QHierarchyResource.getTexture(QHierarchyTexture.ButtonLockOff));

            if (Event.current.isMouse && Event.current.button == 0 && rect.Contains(Event.current.mousePosition))
            {
                if (Event.current.type == EventType.MouseDown)
                {
                    targetLockState = ((!isLock) == true ? 1 : 0);
                }
                else if (Event.current.type == EventType.MouseDrag && targetLockState != -1)
                {
                    if (targetLockState == (isLock == true ? 1 : 0))
                    {
                        return(rect.width);
                    }
                }
                else
                {
                    targetLockState = -1;
                    return(rect.width);
                }

                Event.current.Use();

                Undo.RecordObject(getObjectList(), "Change GameObject Lock");

                bool showWarning = QHierarchySettings.getSetting <bool>(QHierarchySetting.ShowModifierWarning);
                if (Event.current.shift)
                {
                    if (!showWarning || EditorUtility.DisplayDialog("Change locking",
                                                                    "Are you sure you want to " + (isLock ? "unlock" : "lock") + " this GameObject and all its children? (You can disable this warning in the settings)",
                                                                    "Yes",
                                                                    "Cancel"))
                    {
                        setLockRecursive(gameObject.transform, !isLock);
                    }
                }
                else if (Event.current.alt)
                {
                    if (!showWarning || EditorUtility.DisplayDialog("Change locking",
                                                                    "Are you sure you want to " + (isLock ? "unlock" : "lock") + " this GameObject and its siblings? (You can disable this warning in the settings)",
                                                                    "Yes",
                                                                    "Cancel"))
                    {
                        setLockRecursive(gameObject.transform, !isLock, 1);
                    }
                }
                else
                {
                    setLockRecursive(gameObject.transform, !isLock, 0);
                }

                EditorUtility.SetDirty(objectList);
                if (Selection.activeGameObject != null)
                {
                    EditorUtility.SetDirty(Selection.activeGameObject);
                }
            }
            return(rect.width);
        }
Пример #15
0
        static float drawMeshButton(GameObject gameObject, Rect rect)
        {
            Renderer renderer = gameObject.GetComponent <Renderer>();

            if (renderer != null)
            {
                bool wireframeHiddenObjectsContains = objectList == null ? false : objectList.wireframeHiddenObjects.Contains(gameObject);

                rect.x    -= 14;
                rect.width = 14;
                GUI.DrawTexture(rect, wireframeHiddenObjectsContains ? QHierarchyResource.getTexture(QHierarchyTexture.ButtonMeshWireframe) :
                                (renderer.enabled ?
                                 QHierarchyResource.getTexture(QHierarchyTexture.ButtonMeshOn) :
                                 QHierarchyResource.getTexture(QHierarchyTexture.ButtonMeshOff)));

                if (Event.current.isMouse && Event.current.button == 0 && rect.Contains(Event.current.mousePosition))
                {
                    bool isEnabled = renderer.enabled;

                    if (Event.current.type == EventType.MouseDown)
                    {
                        targetMeshState = ((!isEnabled) == true ? 1 : 0);
                    }
                    else if (Event.current.type == EventType.MouseDrag && targetMeshState != -1)
                    {
                        if (targetMeshState == (isEnabled == true ? 1 : 0))
                        {
                            return(rect.width);
                        }
                    }
                    else
                    {
                        targetMeshState = -1;
                        return(rect.width);
                    }

                    Event.current.Use();

                    Undo.RecordObject(renderer, "Change GameObject Mesh Enable");

                    if (Event.current.control || Event.current.command)
                    {
                        if (!wireframeHiddenObjectsContains)
                        {
                            EditorUtility.SetSelectedWireframeHidden(renderer, true);
                            objectList.wireframeHiddenObjects.Add(gameObject);
                            SceneView.RepaintAll();
                        }
                    }
                    else
                    {
                        if (wireframeHiddenObjectsContains)
                        {
                            EditorUtility.SetSelectedWireframeHidden(renderer, false);
                            objectList.wireframeHiddenObjects.Remove(gameObject);
                            SceneView.RepaintAll();
                        }
                        else
                        {
                            renderer.enabled = !isEnabled;
                        }
                    }
                }
                return(rect.width);
            }
            else
            {
                bool fixedIconWidth = QHierarchySettings.getSetting <bool>(QHierarchySetting.FixedIconWidth);
                if (fixedIconWidth)
                {
                    rect.x    -= 14;
                    rect.width = 14;
                    EditorGUI.DrawRect(rect, backgroundColor);
                    return(rect.width);
                }
            }
            return(0);
        }
Пример #16
0
        static float drawVisibilityButton(GameObject gameObject, Rect rect)
        {
            rect.x    -= 18;
            rect.width = 18;

            int visibility = gameObject.activeSelf ? 1 : 0;

            bool editModeVisibleObjectsContains   = objectList == null ? false : objectList.editModeVisibileObjects.Contains(gameObject);
            bool editModeInvisibleObjectsContains = objectList == null ? false : objectList.editModeInvisibleObjects.Contains(gameObject);

            if (!EditorApplication.isPlayingOrWillChangePlaymode &&
                ((!gameObject.activeSelf && editModeVisibleObjectsContains) ||
                 (gameObject.activeSelf && editModeInvisibleObjectsContains)))
            {
                gameObject.SetActive(!gameObject.activeSelf);
            }

            if (visibility == 1)
            {
                Transform transform = gameObject.transform;
                while (transform.parent != null)
                {
                    transform = transform.parent;
                    if (!transform.gameObject.activeSelf)
                    {
                        visibility = 2;
                        break;
                    }
                }
            }

            Texture2D visibilityIcon;

            if (!EditorApplication.isPlayingOrWillChangePlaymode && (editModeVisibleObjectsContains || editModeInvisibleObjectsContains))
            {
                visibilityIcon = visibility == 0 ? QHierarchyResource.getTexture(QHierarchyTexture.ButtonVisibilityOffEdit) : visibility == 1 ? QHierarchyResource.getTexture(QHierarchyTexture.ButtonVisibilityOnEdit) : QHierarchyResource.getTexture(QHierarchyTexture.ButtonVisibilityOffParentEdit);
            }
            else
            {
                visibilityIcon = visibility == 0 ? QHierarchyResource.getTexture(QHierarchyTexture.ButtonVisibilityOff) : visibility == 1 ? QHierarchyResource.getTexture(QHierarchyTexture.ButtonVisibilityOn) : QHierarchyResource.getTexture(QHierarchyTexture.ButtonVisibilityOffParent);
            }

            if (GUI.Button(rect, visibilityIcon, guiStyle))
            {
                Undo.RecordObject(gameObject, "Change GameObject Visibility");

                if (Event.current.control || Event.current.command)
                {
                    if (gameObject.activeSelf)
                    {
                        if (editModeVisibleObjectsContains)
                        {
                            objectList.editModeVisibileObjects.Remove(gameObject);
                        }

                        getObjectList().editModeInvisibleObjects.Add(gameObject);
                    }
                    else
                    {
                        if (editModeInvisibleObjectsContains)
                        {
                            objectList.editModeInvisibleObjects.Remove(gameObject);
                        }

                        getObjectList().editModeVisibileObjects.Add(gameObject);
                    }
                }
                else
                {
                    if (editModeVisibleObjectsContains)
                    {
                        objectList.editModeVisibileObjects.Remove(gameObject);
                    }

                    if (editModeInvisibleObjectsContains)
                    {
                        objectList.editModeInvisibleObjects.Remove(gameObject);
                    }
                }

                bool showWarning = QHierarchySettings.getSetting <bool>(QHierarchySetting.ShowModifierWarning);
                if (Event.current.shift)
                {
                    if (!showWarning || EditorUtility.DisplayDialog("Change visibility",
                                                                    "Are you sure you want to turn " + (gameObject.activeSelf ? "off" : "on") + " the visibility of this GameObject and all its children?",
                                                                    "Yes",
                                                                    "Cancel"))
                    {
                        setVisibilityRecursive(gameObject.transform, !gameObject.activeSelf);
                    }
                }
                else if (Event.current.alt)
                {
                    if (!showWarning || EditorUtility.DisplayDialog("Change visibility",
                                                                    "Are you sure you want to turn " + (gameObject.activeSelf ? "off" : "on") + " the visibility this GameObject and its siblings?",
                                                                    "Yes",
                                                                    "Cancel"))
                    {
                        setVisibilityRecursive(gameObject.transform, !gameObject.activeSelf, 1);
                    }
                }
                else if (Event.current.control || Event.current.command)
                {
                    gameObject.SetActive(!gameObject.activeSelf);
                }
                else
                {
                    setVisibilityRecursive(gameObject.transform, !gameObject.activeSelf, 0);
                }
            }

            return(rect.width);
        }
Пример #17
0
        static void DrawHierarchyItemIcon(int instanceId, Rect selectionRect)
        {
            GameObject itemGameObject = (GameObject)EditorUtility.InstanceIDToObject(instanceId);

            if (itemGameObject == null)
            {
                return;
            }

            if (QHierarchySettings.getSetting <bool>(QHierarchySetting.ShowTreeMap) ||
                QHierarchySettings.getSetting <bool>(QHierarchySetting.ShowMonoBehaviourIcon))
            {
                drawTreeMap(itemGameObject, selectionRect);
            }

            Rect rect = new Rect(selectionRect);

            rect.width = 16;
            rect.x    += selectionRect.width - QHierarchySettings.getSetting <int>(QHierarchySetting.Identation);

            List <QHierarchyIconType> iconOrder = QHierarchySettings.getSetting <List <QHierarchyIconType> >(QHierarchySetting.IconOrder);

            for (int i = iconOrder.Count - 1; i >= 0; i--)
            {
                switch (iconOrder[i])
                {
                case QHierarchyIconType.LockButton:
                {
                    if (QHierarchySettings.getSetting <bool>(QHierarchySetting.ShowLockButton))
                    {
                        rect.x -= drawLockButton(itemGameObject, rect);
                    }
                    break;
                }

                case QHierarchyIconType.VisibilityButton:
                {
                    if (QHierarchySettings.getSetting <bool>(QHierarchySetting.ShowVisibilityButton))
                    {
                        rect.x -= drawVisibilityButton(itemGameObject, rect);
                    }
                    break;
                }

                case QHierarchyIconType.MeshButton:
                {
                    if (QHierarchySettings.getSetting <bool>(QHierarchySetting.ShowMeshButton))
                    {
                        rect.x -= drawMeshButton(itemGameObject, rect);
                    }
                    break;
                }

                case QHierarchyIconType.TagAndLayer:
                {
                    if (QHierarchySettings.getSetting <bool>(QHierarchySetting.ShowTagAndLayerText))
                    {
                        rect.x -= drawTagLayerText(itemGameObject, rect);
                    }
                    break;
                }

                case QHierarchyIconType.ErrorIcon:
                {
                    if (QHierarchySettings.getSetting <bool>(QHierarchySetting.ShowErrorIcon))
                    {
                        rect.x -= drawErrorIcon(itemGameObject, rect);
                    }
                    break;
                }

                case QHierarchyIconType.GameObjectIcon:
                {
                    if (QHierarchySettings.getSetting <bool>(QHierarchySetting.ShowGameObjectIcon))
                    {
                        float offset = drawGameObjectIcon(itemGameObject, rect);

                        if (QHierarchySettings.getSetting <bool>(QHierarchySetting.CustomTagIconReplace))
                        {
                            drawCustomTagIcon(itemGameObject, rect);
                        }

                        rect.x -= offset;
                    }
                    break;
                }

                case QHierarchyIconType.CustomTagIcon:
                {
                    if (QHierarchySettings.getSetting <bool>(QHierarchySetting.ShowCustomTagIcon) &&
                        !QHierarchySettings.getSetting <bool>(QHierarchySetting.CustomTagIconReplace))
                    {
                        rect.x -= drawCustomTagIcon(itemGameObject, rect);
                    }
                    break;
                }

                case QHierarchyIconType.StaticIcon:
                {
                    if (QHierarchySettings.getSetting <bool>(QHierarchySetting.ShowStaticIcon))
                    {
                        rect.x -= drawStaticIcon(itemGameObject, rect);
                    }
                    break;
                }
                }
            }
        }
Пример #18
0
        private static float drawTagLayerText(GameObject gameObject, Rect rect)
        {
            string tag   = gameObject.tag;
            int    layer = gameObject.layer;

            bool showAlways = (QHierarchySettings.getSetting <int>(QHierarchySetting.TagAndLayerType) == (int)QHierarchyTagAndLayerType.Always);

            float textWidth = 0;

            if (QHierarchySettings.getSetting <int>(QHierarchySetting.TagAndLayerSizeValueType) == (int)QHierarchyTagAndLayerSizeValueType.Pixel)
            {
                textWidth = QHierarchySettings.getSetting <int>(QHierarchySetting.TagAndLayerSizeValue);
            }
            else
            {
                textWidth = QHierarchySettings.getSetting <float>(QHierarchySetting.TagAndLayerSizeValuePercent) * rect.x;
            }

            if (!showAlways && tag == "Untagged" && layer == 0)
            {
                if (QHierarchySettings.getSetting <int>(QHierarchySetting.TagAndLayerSizeType) == (int)QHierarchyTagAndLayerSizeType.Fixed)
                {
                    rect.width = 4 + textWidth;
                    rect.x    -= rect.width;
                    EditorGUI.DrawRect(rect, backgroundColor);
                    rect.x += rect.width;
                }
                else
                {
                    rect.width = 0;
                }

                return(rect.width);
            }
            else
            {
                string layerName = LayerMask.LayerToName(layer);

                if (QHierarchySettings.getSetting <int>(QHierarchySetting.TagAndLayerSizeType) == (int)QHierarchyTagAndLayerSizeType.Float)
                {
                    float tagWidth   = (tag == "Untagged" && !showAlways ? 0 : smallLabelStyle.CalcSize(new GUIContent(tag)).x);
                    float layerWidth = (layer == 0 && !showAlways ? 0 : smallLabelStyle.CalcSize(new GUIContent(layerName)).x);
                    rect.width = tagWidth > layerWidth ? tagWidth : layerWidth;
                }
                else
                {
                    rect.width = textWidth;
                }

                rect.width += 4;
                rect.x     -= rect.width;
                rect.height = 17;
                EditorGUI.DrawRect(rect, backgroundColor);
                rect.y     -= 1;
                rect.width -= 4;
                rect.x     += 2;

                int aligment = QHierarchySettings.getSetting <int>(QHierarchySetting.TagAndLayerAligment);
                if (aligment == (int)QHierarchyTagAndLayerAligment.Left)
                {
                    smallLabelStyle.alignment = TextAnchor.UpperLeft;
                }
                else if (aligment == (int)QHierarchyTagAndLayerAligment.Center)
                {
                    smallLabelStyle.alignment = TextAnchor.UpperCenter;
                }
                else if (aligment == (int)QHierarchyTagAndLayerAligment.Right)
                {
                    smallLabelStyle.alignment = TextAnchor.UpperRight;
                }

                if (layer == 0 && tag != "Untagged" && !showAlways)
                {
                    rect.y += 4;
                    smallLabelStyle.normal.textColor = greyLightColor;
                    EditorGUI.LabelField(rect, tag, smallLabelStyle);
                }
                else if (layer != 0 && tag == "Untagged" && !showAlways)
                {
                    rect.y += 4;
                    smallLabelStyle.normal.textColor = greyColor;
                    EditorGUI.LabelField(rect, layerName, smallLabelStyle);
                }
                else
                {
                    smallLabelStyle.normal.textColor = greyLightColor;
                    EditorGUI.LabelField(rect, tag, smallLabelStyle);
                    rect.y += 8;
                    smallLabelStyle.normal.textColor = greyColor;
                    EditorGUI.LabelField(rect, layerName, smallLabelStyle);
                    rect.y -= 7;
                }

                return(rect.width + 4);
            }
        }
Пример #19
0
        static float drawVisibilityButton(GameObject gameObject, Rect rect)
        {
            rect.x    -= 18;
            rect.width = 18;

            int visibility = gameObject.activeSelf ? 1 : 0;

            bool editModeVisibleObjectsContains   = objectList == null ? false : objectList.editModeVisibileObjects.Contains(gameObject);
            bool editModeInvisibleObjectsContains = objectList == null ? false : objectList.editModeInvisibleObjects.Contains(gameObject);

            if (!EditorApplication.isPlayingOrWillChangePlaymode &&
                ((!gameObject.activeSelf && editModeVisibleObjectsContains) ||
                 (gameObject.activeSelf && editModeInvisibleObjectsContains)))
            {
                gameObject.SetActive(!gameObject.activeSelf);
            }

            if (visibility == 1)
            {
                Transform transform = gameObject.transform;
                while (transform.parent != null)
                {
                    transform = transform.parent;
                    if (!transform.gameObject.activeSelf)
                    {
                        visibility = 2;
                        break;
                    }
                }
            }

            Texture2D visibilityIcon;

            if (!EditorApplication.isPlayingOrWillChangePlaymode && (editModeVisibleObjectsContains || editModeInvisibleObjectsContains))
            {
                visibilityIcon = visibility == 0 ? QHierarchyResource.getTexture(QHierarchyTexture.ButtonVisibilityOffEdit) : visibility == 1 ? QHierarchyResource.getTexture(QHierarchyTexture.ButtonVisibilityOnEdit) : QHierarchyResource.getTexture(QHierarchyTexture.ButtonVisibilityOffParentEdit);
            }
            else
            {
                visibilityIcon = visibility == 0 ? QHierarchyResource.getTexture(QHierarchyTexture.ButtonVisibilityOff) : visibility == 1 ? QHierarchyResource.getTexture(QHierarchyTexture.ButtonVisibilityOn) : QHierarchyResource.getTexture(QHierarchyTexture.ButtonVisibilityOffParent);
            }

            GUI.DrawTexture(rect, visibilityIcon);

            if (Event.current.isMouse && Event.current.button == 0 && rect.Contains(Event.current.mousePosition))
            {
                if (Event.current.type == EventType.MouseDown)
                {
                    targetVisibilityState = ((!gameObject.activeSelf) == true ? 1 : 0);
                }
                else if (Event.current.type == EventType.MouseDrag && targetVisibilityState != -1)
                {
                    if (targetVisibilityState == (gameObject.activeSelf == true ? 1 : 0))
                    {
                        return(rect.width);
                    }
                }
                else
                {
                    targetVisibilityState = -1;
                    return(rect.width);
                }

                Event.current.Use();

                Undo.RecordObject(gameObject, "Change GameObject Visibility");

                bool showWarning = QHierarchySettings.getSetting <bool>(QHierarchySetting.ShowModifierWarning);
                if (Event.current.control || Event.current.command)
                {
                    if (Event.current.shift)
                    {
                        if (!showWarning || EditorUtility.DisplayDialog("Change edit-time visibility",
                                                                        "Are you sure you want to turn " + (gameObject.activeSelf ? "off" : "on") + " the edit-time visibility of this GameObject and all its children? (You can disable this warning in the settings)",
                                                                        "Yes",
                                                                        "Cancel"))
                        {
                            setEditModeVisibilityRecursive(gameObject, !gameObject.activeSelf);
                        }
                    }
                    else if (Event.current.alt)
                    {
                        if (!showWarning || EditorUtility.DisplayDialog("Change edit-time visibility",
                                                                        "Are you sure you want to turn " + (gameObject.activeSelf ? "off" : "on") + " the edit-time visibility this GameObject and its siblings? (You can disable this warning in the settings)",
                                                                        "Yes",
                                                                        "Cancel"))
                        {
                            setEditModeVisibilityRecursive(gameObject, !gameObject.activeSelf, 1);
                        }
                    }
                    else
                    {
                        setEditModeVisibilityRecursive(gameObject, !gameObject.activeSelf, 0);
                    }
                }
                else if (Event.current.shift)
                {
                    if (!showWarning || EditorUtility.DisplayDialog("Change visibility",
                                                                    "Are you sure you want to turn " + (gameObject.activeSelf ? "off" : "on") + " the visibility of this GameObject and all its children? (You can disable this warning in the settings)",
                                                                    "Yes",
                                                                    "Cancel"))
                    {
                        setVisibilityRecursive(gameObject.transform, !gameObject.activeSelf);
                    }
                }
                else if (Event.current.alt)
                {
                    if (!showWarning || EditorUtility.DisplayDialog("Change visibility",
                                                                    "Are you sure you want to turn " + (gameObject.activeSelf ? "off" : "on") + " the visibility this GameObject and its siblings? (You can disable this warning in the settings)",
                                                                    "Yes",
                                                                    "Cancel"))
                    {
                        setVisibilityRecursive(gameObject.transform, !gameObject.activeSelf, 1);
                    }
                }
                else
                {
                    setVisibilityRecursive(gameObject.transform, !gameObject.activeSelf, 0);
                }
            }

            return(rect.width);
        }
Пример #20
0
        static float drawLockButton(QObjectList objectList, GameObject gameObject, Rect rect)
        {
            rect.x    -= 13;
            rect.width = 13;

            bool isLock = objectList == null ? false : objectList.lockedObjects.Contains(gameObject);

            if (isLock == true && (gameObject.hideFlags & HideFlags.NotEditable) != HideFlags.NotEditable)
            {
                gameObject.hideFlags |= HideFlags.NotEditable;
                EditorUtility.SetDirty(gameObject);
            }
            else if (isLock == false && (gameObject.hideFlags & HideFlags.NotEditable) == HideFlags.NotEditable)
            {
                gameObject.hideFlags ^= HideFlags.NotEditable;
                EditorUtility.SetDirty(gameObject);
            }

            GUI.DrawTexture(rect, isLock ? QHierarchyResource.getTexture(QHierarchyTexture.ButtonLockOn) : QHierarchyResource.getTexture(QHierarchyTexture.ButtonLockOff));

            if (Event.current.isMouse && Event.current.button == 0 && rect.Contains(Event.current.mousePosition))
            {
                if (Event.current.type == EventType.MouseDown)
                {
                    targetLockState = ((!isLock) == true ? 1 : 0);
                }
                else if (Event.current.type == EventType.MouseDrag && targetLockState != -1)
                {
                    if (targetLockState == (isLock == true ? 1 : 0))
                    {
                        return(rect.width);
                    }
                }
                else
                {
                    targetLockState = -1;
                    return(rect.width);
                }

                if (objectList == null)
                {
                    objectList = createObjectListInScene(gameObject.scene);
                }

                Event.current.Use();
                bool showWarning = QHierarchySettings.getSetting <bool>(QHierarchySetting.ShowModifierWarning);

                List <GameObject> targetGameObjects = new List <GameObject>();
                if (Event.current.shift)
                {
                    if (!showWarning || EditorUtility.DisplayDialog("Change locking", "Are you sure you want to " + (isLock ? "unlock" : "lock") + " this GameObject and all its children? (You can disable this warning in the settings)", "Yes", "Cancel"))
                    {
                        getGameObjectListRecursive(ref targetGameObjects, gameObject);
                    }
                }
                else if (Event.current.alt)
                {
                    if (gameObject.transform.parent != null)
                    {
                        if (!showWarning || EditorUtility.DisplayDialog("Change locking", "Are you sure you want to " + (isLock ? "unlock" : "lock") + " this GameObject and its siblings? (You can disable this warning in the settings)", "Yes", "Cancel"))
                        {
                            getGameObjectListRecursive(ref targetGameObjects, gameObject.transform.parent.gameObject, 1);
                            targetGameObjects.Remove(gameObject.transform.parent.gameObject);
                        }
                    }
                    else
                    {
                        gameObject.scene.GetRootGameObjects(targetGameObjects);;
                    }
                }
                else
                {
                    if (Selection.Contains(gameObject))
                    {
                        targetGameObjects.AddRange(Selection.gameObjects);
                    }
                    else
                    {
                        getGameObjectListRecursive(ref targetGameObjects, gameObject, 0);
                    };
                }

                setLock(objectList, targetGameObjects, !isLock);
            }
            return(rect.width);
        }
Пример #21
0
        static bool findError(MonoBehaviour[] components)
        {
            bool showErrorTypeReferenceIsNull   = QHierarchySettings.getSetting <bool>(QHierarchySetting.ShowErrorIconReferenceIsNull);
            bool showErrorTypeStringIsEmpty     = QHierarchySettings.getSetting <bool>(QHierarchySetting.ShowErrorIconStringIsEmpty);
            bool showErrorIconScriptIsMissing   = QHierarchySettings.getSetting <bool>(QHierarchySetting.ShowErrorIconScriptIsMissing);
            bool showErrorForDisabledComponents = QHierarchySettings.getSetting <bool>(QHierarchySetting.ShowErrorForDisabledComponents);

            for (int i = 0; i < components.Length; i++)
            {
                if (components[i] == null)
                {
                    if (showErrorIconScriptIsMissing)
                    {
                        return(true);
                    }
                }
                else
                {
                    if (showErrorTypeReferenceIsNull || showErrorTypeStringIsEmpty)
                    {
                        MonoBehaviour monoBehaviour = components[i];
                        if (!(monoBehaviour.enabled && monoBehaviour.gameObject.activeSelf) && !showErrorForDisabledComponents)
                        {
                            continue;
                        }

                        FieldInfo[] fieldArray = monoBehaviour.GetType().GetFields();
                        for (int j = 0; j < fieldArray.Length; j++)
                        {
                            FieldInfo field = fieldArray[j];

                            try
                            {
                                if (System.Attribute.IsDefined(field, typeof(HideInInspector)) || field.IsStatic)
                                {
                                    continue;
                                }

                                object value = field.GetValue(monoBehaviour);

                                if (showErrorTypeReferenceIsNull && value != null && value.Equals(null))
                                {
                                    return(true);
                                }
                                else if (field.FieldType == typeof(string))
                                {
                                    if (showErrorTypeStringIsEmpty && value != null && ((string)value).Equals(""))
                                    {
                                        return(true);
                                    }
                                }
                                else
                                {
                                    if (showErrorTypeReferenceIsNull && (value is IEnumerable))
                                    {
                                        foreach (var item in (IEnumerable)value)
                                        {
                                            if (item == null)
                                            {
                                                return(true);
                                            }
                                        }
                                    }
                                }
                            }
                            catch
                            {
                            }
                        }
                    }
                }
            }
            return(false);
        }
Пример #22
0
        static QHierarchySettings()
        {
            settings = new Dictionary <int, object>();
            settings[(int)QHierarchySetting.ShowVisibilityButton]         = getEditorSetting(QHierarchySetting.ShowVisibilityButton, true);
            settings[(int)QHierarchySetting.ShowLockButton]               = getEditorSetting(QHierarchySetting.ShowLockButton, true);
            settings[(int)QHierarchySetting.ShowGameObjectIcon]           = getEditorSetting(QHierarchySetting.ShowGameObjectIcon, true);
            settings[(int)QHierarchySetting.ShowTreeMap]                  = getEditorSetting(QHierarchySetting.ShowTreeMap, true);
            settings[(int)QHierarchySetting.ShowMonoBehaviourIcon]        = getEditorSetting(QHierarchySetting.ShowMonoBehaviourIcon, true);
            settings[(int)QHierarchySetting.ShowTagAndLayerText]          = getEditorSetting(QHierarchySetting.ShowTagAndLayerText, true);
            settings[(int)QHierarchySetting.ShowErrorIcon]                = getEditorSetting(QHierarchySetting.ShowErrorIcon, true);
            settings[(int)QHierarchySetting.ShowErrorIconParent]          = getEditorSetting(QHierarchySetting.ShowErrorIconParent, true);
            settings[(int)QHierarchySetting.ShowErrorIconScriptIsMissing] = getEditorSetting(QHierarchySetting.ShowErrorIconScriptIsMissing, true);
            settings[(int)QHierarchySetting.ShowErrorIconReferenceIsNull] = getEditorSetting(QHierarchySetting.ShowErrorIconReferenceIsNull, false);
            settings[(int)QHierarchySetting.ShowErrorIconStringIsEmpty]   = getEditorSetting(QHierarchySetting.ShowErrorIconStringIsEmpty, false);
            settings[(int)QHierarchySetting.FixedIconWidth]               = getEditorSetting(QHierarchySetting.FixedIconWidth, true);
            settings[(int)QHierarchySetting.TagAndLayerType]              = getEditorSetting(QHierarchySetting.TagAndLayerType, 1);
            settings[(int)QHierarchySetting.TagAndLayerSizeType]          = getEditorSetting(QHierarchySetting.TagAndLayerSizeType, 0);
            settings[(int)QHierarchySetting.TagAndLayerSizeValue]         = getEditorSetting(QHierarchySetting.TagAndLayerSizeValue, 50);
            settings[(int)QHierarchySetting.TagAndLayerAligment]          = getEditorSetting(QHierarchySetting.TagAndLayerAligment, 0);
            settings[(int)QHierarchySetting.TagAndLayerSizeValueType]     = getEditorSetting(QHierarchySetting.TagAndLayerSizeValueType, 0);
            settings[(int)QHierarchySetting.TagAndLayerSizeValuePercent]  = getEditorSetting(QHierarchySetting.TagAndLayerSizeValuePercent, 0.25f);

            string iconOrder = getEditorSetting(QHierarchySetting.IconOrder, DEFAULT_ORDER);

            if (iconOrder.Length != DEFAULT_ORDER.Length)
            {
                iconOrder = DEFAULT_ORDER;
            }
            List <QHierarchyIconType> iconOrderList = new List <QHierarchyIconType>();
            int type;

            for (int i = 0; i < iconOrder.Length; i++)
            {
                if (int.TryParse(iconOrder[i].ToString(), out type))
                {
                    iconOrderList.Add((QHierarchyIconType)type);
                }
                else
                {
                    iconOrderList.Clear();
                    QHierarchySettings.setSetting(QHierarchySetting.IconOrder, DEFAULT_ORDER);
                    iconOrder = DEFAULT_ORDER;
                    i         = -1;
                }
            }

            settings[(int)QHierarchySetting.IconOrder]         = iconOrderList;
            settings[(int)QHierarchySetting.Identation]        = getEditorSetting(QHierarchySetting.Identation, 0);
            settings[(int)QHierarchySetting.ShowCustomTagIcon] = getEditorSetting(QHierarchySetting.ShowCustomTagIcon, true);

            List <QTagTexture> tagTextureList = new List <QTagTexture>();
            string             customTagIcon  = getEditorSetting(QHierarchySetting.CustomTagIcon, "");

            string[]      customTagIconArray = customTagIcon.Split(new char[] { ';' });
            List <string> tags = new List <string>(UnityEditorInternal.InternalEditorUtility.tags);

            for (int i = 0; i < customTagIconArray.Length - 1; i += 2)
            {
                string tag = customTagIconArray[i];
                if (!tags.Contains(tag))
                {
                    continue;
                }
                string texturePath = customTagIconArray[i + 1];

                Texture2D texture = (Texture2D)AssetDatabase.LoadAssetAtPath(texturePath, typeof(Texture2D));
                if (texture != null)
                {
                    QTagTexture tagTexture = new QTagTexture(tag, texture);
                    tagTextureList.Add(tagTexture);
                }
            }
            settings[(int)QHierarchySetting.CustomTagIcon]                   = tagTextureList;
            settings[(int)QHierarchySetting.GeneralSettingsFoldout]          = getEditorSetting(QHierarchySetting.GeneralSettingsFoldout, true);
            settings[(int)QHierarchySetting.AppearanceSettingsFoldout]       = getEditorSetting(QHierarchySetting.AppearanceSettingsFoldout, true);
            settings[(int)QHierarchySetting.OrderSettingsFoldout]            = getEditorSetting(QHierarchySetting.OrderSettingsFoldout, true);
            settings[(int)QHierarchySetting.ErrorIconSettingsFoldout]        = getEditorSetting(QHierarchySetting.ErrorIconSettingsFoldout, true);
            settings[(int)QHierarchySetting.TagAndLayerSettingsFoldout]      = getEditorSetting(QHierarchySetting.TagAndLayerSettingsFoldout, true);
            settings[(int)QHierarchySetting.CustomTagIconFoldout]            = getEditorSetting(QHierarchySetting.CustomTagIconFoldout, true);
            settings[(int)QHierarchySetting.PreventSelectionOfLockedObjects] = getEditorSetting(QHierarchySetting.PreventSelectionOfLockedObjects, false);
            settings[(int)QHierarchySetting.LockSettingsFoldout]             = getEditorSetting(QHierarchySetting.LockSettingsFoldout, true);
            settings[(int)QHierarchySetting.ShowStaticIcon]                  = getEditorSetting(QHierarchySetting.ShowStaticIcon, true);
            settings[(int)QHierarchySetting.CustomTagIconReplace]            = getEditorSetting(QHierarchySetting.CustomTagIconReplace, true);
            settings[(int)QHierarchySetting.CustomTagIconTextureListFoldout] = getEditorSetting(QHierarchySetting.CustomTagIconTextureListFoldout, false);
            settings[(int)QHierarchySetting.ShowHiddenQHierarchyObjectList]  = getEditorSetting(QHierarchySetting.ShowHiddenQHierarchyObjectList, true);
            settings[(int)QHierarchySetting.ShowModifierWarning]             = getEditorSetting(QHierarchySetting.ShowModifierWarning, true);
            settings[(int)QHierarchySetting.ShowErrorForDisabledComponents]  = getEditorSetting(QHierarchySetting.ShowErrorForDisabledComponents, true);
            settings[(int)QHierarchySetting.IgnoreUnityMonobehaviour]        = getEditorSetting(QHierarchySetting.IgnoreUnityMonobehaviour, true);
            settings[(int)QHierarchySetting.MonoBehaviourIconFoldout]        = getEditorSetting(QHierarchySetting.MonoBehaviourIconFoldout, true);
            settings[(int)QHierarchySetting.ShowMeshButton]                  = getEditorSetting(QHierarchySetting.ShowMeshButton, true);
        }