private static void HandleHierarchyWindowItemOnGUI(int instanceID, Rect selectionRect)
            {
                if (spriteMatTransparent == null)
                {
                    LoadMaterials();
                }

                GameObject obj = (GameObject)EditorUtility.InstanceIDToObject(instanceID);

                if (obj == null)
                {
                    return;
                }

                HierarchyDivider found = obj.GetComponent <HierarchyDivider>();

                if (found == null)
                {
                    return;
                }

                HierarchyDividerValues foundDivider = found.HDV;

                if (Dividers == null || Dividers.Count == 0)
                {
                    Dividers = new List <HierarchyDividerValues>();
                    Dividers.AddRange(GameObject.FindObjectsOfType <HierarchyDivider>().ToList().Select(x => x.HDV).ToList());
                }

                try
                {
                    HierarchyDividerValues divider = Dividers.Find(x => x.DividerID == foundDivider.DividerID);
                    if (divider == null)
                    {
                        Dividers.AddRange(GameObject.FindObjectsOfType <HierarchyDivider>().ToList().Select(x => x.HDV).ToList());
                    }

                    if (obj != null && divider != null)
                    {
                        Color fontColor = divider.fontColor;
                        Color bgColor   = new Color(divider.bgColor.r, divider.bgColor.g, divider.bgColor.b, 1f);

                        Color standardBg = EditorGUIUtility.isProSkin ?
                                           new Color(0.22f, 0.22f, 0.22f)
                                                        : new Color(.76f, .76f, .76f);

                        Color _selectionColor = EditorGUIUtility.isProSkin ? new Color(0.24f, 0.37f, 0.59f) : new Color(0.24f, 0.48f, 0.90f);

                        bool selected = Selection.instanceIDs.Contains(instanceID);
                        if (selected)
                        {
                            fontColor = Color.white;
                            bgColor   = _selectionColor;
                        }

                        float spriteSize = 15f;

                                                #if UNITY_2019_2
                        selectionRect.x     += 18;
                        selectionRect.width -= 4;
                                                #elif UNITY_2019_1_OR_NEWER
                        selectionRect.x     += 20;
                        selectionRect.width -= 6;
                                                #endif

                        Rect offsetRect = new Rect(selectionRect.position + offset, selectionRect.size);

                                                #if UNITY_2018_3
                        offsetRect.width += 15f;
                                                #endif

                        if (divider.hasBgColor || selected)
                        {
                            if (divider.hasRightSprite)
                            {
                                                                #if UNITY_2019_1_OR_NEWER
                                EditorGUI.DrawRect(new Rect(selectionRect.x, selectionRect.y, offsetRect.width - (spriteSize + 4) - 5, offsetRect.height), bgColor);
                                                                #else
                                EditorGUI.DrawRect(new Rect(selectionRect.x, selectionRect.y, offsetRect.width - (spriteSize + 4), offsetRect.height), bgColor);
                                                                #endif
                            }
                            else
                            {
                                {
                                                                        #if UNITY_2019_2
                                    EditorGUI.DrawRect(new Rect(selectionRect.x, selectionRect.y, offsetRect.width + 2, offsetRect.height), bgColor);
                                                                        #else
                                    EditorGUI.DrawRect(new Rect(selectionRect.x, selectionRect.y, offsetRect.width, offsetRect.height), bgColor);
                                                                        #endif
                                }
                            }
                        }
                        else
                        {
                                                        #if UNITY_2019_2
                            EditorGUI.DrawRect(new Rect(selectionRect.x - 45, selectionRect.y, offsetRect.width + 45, selectionRect.height), standardBg);
                                                        #else
                            EditorGUI.DrawRect(new Rect(selectionRect.x, selectionRect.y, offsetRect.width, selectionRect.height), standardBg);
                                                        #endif
                        }


                        GUIStyle _style = new GUIStyle();
                        if (!divider.boldFont && !divider.italicFont)
                        {
                            _style.fontStyle = FontStyle.Normal;
                        }
                        if (divider.boldFont && !divider.italicFont)
                        {
                            _style.fontStyle = FontStyle.Bold;
                        }
                        else if (!divider.boldFont && divider.italicFont)
                        {
                            _style.fontStyle = FontStyle.Italic;
                        }
                        else if (divider.boldFont && divider.italicFont)
                        {
                            _style.fontStyle = FontStyle.BoldAndItalic;
                        }

                        _style.normal = divider.hasFontColor || selected
                                                        ? new GUIStyleState()
                        {
                            textColor = fontColor
                        }
                                                        : new GUIStyleState();

                        _style.alignment = TextAnchor.UpperCenter;

//						if (divider.hasRightSprite)
//							EditorGUI.LabelField(new Rect(offsetRect.x, offsetRect.y, offsetRect.width - (spriteSize + 4f), offsetRect.height), obj.name, _style);
//						else
//							EditorGUI.LabelField(offsetRect, obj.name, _style);
                        EditorGUI.LabelField(new Rect(offsetRect.x, offsetRect.y, offsetRect.width - (spriteSize + 4f), offsetRect.height), obj.name, _style);

                                                #if UNITY_2019_2
                        EditorGUI.DrawRect(new Rect(16f, offsetRect.y - 2, 45, EditorGUIUtility.singleLineHeight), selected? _selectionColor : standardBg);
                                                #elif UNITY_2019_1_OR_NEWER
                        EditorGUI.DrawRect(new Rect(25f, offsetRect.y - 2, 30, EditorGUIUtility.singleLineHeight), selected? _selectionColor : standardBg);
                                                #else
                        EditorGUI.DrawRect(new Rect(0f, offsetRect.y - 2, 30, EditorGUIUtility.singleLineHeight), selected? _selectionColor : standardBg);
                                                #endif

                        if (divider.hasLeftSprite)
                        {
                            Rect _leftSpriteRect = new Rect(offsetRect.x - (spriteSize * 1.5f), offsetRect.y - 2,
                                                            spriteSize, EditorGUIUtility.singleLineHeight);

                                                        #if UNITY_2019_2
                            _leftSpriteRect.x += 4;
                                                        #elif UNITY_2019_1_OR_NEWER
                            _leftSpriteRect.x += 3;
                                                        #endif

                            DrawSprite(_leftSpriteRect,
                                       divider.leftSprite, spriteSize);
                        }

                        if (divider.hasRightSprite)
                        {
                            Rect _rightSpriteRect = new Rect(offsetRect.x + offsetRect.width - spriteSize - 3f,
                                                             offsetRect.y - 2, spriteSize,
                                                             EditorGUIUtility.singleLineHeight);

                                                        #if UNITY_2019_1_OR_NEWER
                            EditorGUI.DrawRect(new Rect(_rightSpriteRect.x - 5f, _rightSpriteRect.y, _rightSpriteRect.width + 55f, _rightSpriteRect.height), selected? _selectionColor : standardBg);
                            _rightSpriteRect.x -= 2;
                                                        #else
                            EditorGUI.DrawRect(new Rect(_rightSpriteRect.x - 1f, _rightSpriteRect.y, _rightSpriteRect.width + 50f, _rightSpriteRect.height), selected? _selectionColor : standardBg);
                                                        #endif

                            DrawSprite(_rightSpriteRect,
                                       divider.rightSprite, spriteSize);
                        }
                    }
                }
                catch (Exception e)
                {
                    throw e;
                }
            }
Пример #2
0
            void PlaceDividers()
            {
                if (HierarchyDividerDrawing.Dividers == null)
                {
                    HierarchyDividerDrawing.Dividers = new List <HierarchyDividerValues>();
                }

                MonoBehaviour[]     _sceneComponents = FindObjectsOfType <MonoBehaviour>();
                IHierarchyDivider[] hds = _sceneComponents
                                          .Where(x => x.GetComponent <IHierarchyDivider>() != null)
                                          .Select(x => x.GetComponent <IHierarchyDivider>()).ToArray();

                if (Array.Exists(hds, x => x.GetTransform.childCount > 0))
                {
                    if (!EditorUtility.DisplayDialog("Caution: Invalid parenting", "There are dividers with other GameObjects as children. Replacing the dividers will delete these GameObjects.", "Go on", "Abort"))
                    {
                        return;
                    }
                }

                int c = hds.Length;

                hcInfo[] _hcInfos = new hcInfo[c];

                if (c != 0)
                {
                    if (!EditorUtility.DisplayDialog("Replace hierarchy dividers", "This will replace all hierarchy dividers in this scene!", "Go on", "Abort"))
                    {
                        return;
                    }

                    for (int i = 0; i < c; i++)
                    {
                        _hcInfos[i] = new hcInfo(hds[i].DividerLabel, hds[i].GetTransform.GetSiblingIndex());
                    }

                    Array.Sort(_hcInfos, delegate(hcInfo _hc1, hcInfo _hc2) {
                        return(_hc1.Index.CompareTo(_hc2.Index));
                    });
                }

                List <HierarchyDivider> _createdHDs = new List <HierarchyDivider>();

                int count = dividerPreset.Dividers.Count;

                for (int i = 0; i < count; i++)
                {
                    GameObject _go = new GameObject();
                    _go.AddComponent(typeof(HierarchyDivider));
                    HierarchyDivider hd = _go.GetComponent <HierarchyDivider>();
                    hd.SetDivider(dividerPreset.Dividers[i].Label,
                                  dividerPreset.Dividers[i].FontColor,
                                  dividerPreset.Dividers[i].BGColor,
                                  dividerPreset.Dividers[i].OverrideColor_leftSprite,
                                  dividerPreset.Dividers[i].OverrideColor_rightSprite,
                                  dividerPreset.Dividers[i].BoldFont,
                                  dividerPreset.Dividers[i].ItalicFont,
                                  dividerPreset.Dividers[i].ColoredFont,
                                  dividerPreset.Dividers[i].ColoredBG,
                                  dividerPreset.Dividers[i].HasSprite_left,
                                  dividerPreset.Dividers[i].HasSprite_right,
                                  dividerPreset.Dividers[i].HasOverrideColor_leftSprite,
                                  dividerPreset.Dividers[i].HasOverrideColor_rightSprite,
                                  dividerPreset.Dividers[i].LeftSprite,
                                  dividerPreset.Dividers[i].RightSprite);

                    _createdHDs.Add(hd);
                }

                int _siblingIndexOffset = 0;

                for (int i = 0; i < c; i++)
                {
                    int _match = _createdHDs.FindIndex(x => x.HDV.Label == _hcInfos[i].Label);
                    if (_match >= 0)
                    {
                        _createdHDs[_match].transform.SetSiblingIndex(_hcInfos[i].Index + _siblingIndexOffset);
                        _siblingIndexOffset++;
                    }
                }

                for (int i = 0; i < c; i++)
                {
                    DestroyImmediate(hds[i].GetTransform.gameObject);
                }

                EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene());
            }