private static void ReplaceHierarchyTextures(int instanceId, Rect selectionRect)
        {
            var gameObject = (GameObject)EditorUtility.InstanceIDToObject(instanceId);

            if (gameObject == null)
            {
                return;
            }

            var currentScene = gameObject.scene;
            var sceneConf    = RainbowHierarchySceneConf.GetConfByScene(currentScene);

            if (sceneConf == null || sceneConf.HierarchyItems.Count == 0)
            {
                return;
            }

            var hierarchyItem = sceneConf.GetItem(gameObject);

            if (hierarchyItem != null)
            {
                CheckRecursiveListUpdate(hierarchyItem, gameObject);
                DrawCustomIcon(hierarchyItem, selectionRect);
                DrawCustomBackground(hierarchyItem, selectionRect);
            }
            else
            {
                HandleRecursive(selectionRect, gameObject, sceneConf);
            }
        }
        public void ShowWithParams(Vector2 inPosition, List <GameObject> selectedObjects, int firstSelected)
        {
            _selectedObjects = selectedObjects;

            var scene = selectedObjects[0].scene;

            _rainbowHierarchySceneConf = RainbowHierarchySceneConf.GetConfByScene(scene, true);

            _currentObject = selectedObjects[firstSelected];

            var item = _rainbowHierarchySceneConf.GetItem(_currentObject);

            _currentHierarchyItem = item == null ?
                                    new HierarchyItem(KeyType.Object, _currentObject, _currentObject.name) :
                                    new HierarchyItem(item);

            _currentHierarchyItem.GameObject = _currentObject;

            // Resize

            var customIconHeight       = (_currentHierarchyItem.IsIconCustom) ? LINE_HEIGHT : 0f;
            var customBackgroundHeight = (_currentHierarchyItem.IsBackgroundCustom) ? LINE_HEIGHT : 0f;

            var rect = new Rect(inPosition, WINDOW_SIZE)
            {
                height = WINDOW_HEIGHT + customIconHeight + customBackgroundHeight
            };

            _windowRect     = new Rect(Vector2.zero, rect.size);
            _backgroundRect = new Rect(Vector2.one, rect.size - new Vector2(2f, 2f));

            Show <RainbowHierarchyPopup>(rect);
        }
        private void ButtonApply(Rect rect)
        {
            if (!GUI.Button(rect, "Apply"))
            {
                return;
            }

            var scene     = _currentObject.scene;
            var sceneConf = RainbowHierarchySceneConf.GetConfByScene(scene, true);

            foreach (var selectedObject in _selectedObjects)
            {
                _currentHierarchyItem.GameObject = _currentHierarchyItem.Type == KeyType.Name ? null : selectedObject;
                _currentHierarchyItem.Name       = _currentHierarchyItem.Type == KeyType.Name ? selectedObject.name : null;
                Undo.RecordObject(sceneConf, "Scene Config Changes");
                sceneConf.UpdateItem(selectedObject, _currentHierarchyItem);
            }

            Close();
        }
        private static void HandleRecursive(Rect selectionRect, GameObject gameObject, RainbowHierarchySceneConf sceneConf)
        {
            for (var i = RecursiveList.Count - 1; i >= 0; i--)
            {
                if (RecursiveList[i] == null)
                {
                    RecursiveList.Remove(RecursiveList[i]);
                    return;
                }
                if (!gameObject.transform.IsChildOf(RecursiveList[i].transform))
                {
                    continue;
                }

                var parentItem = sceneConf.GetItem(RecursiveList[i]);
                if (parentItem == null)
                {
                    return;
                }

                if (parentItem.IsIconRecursive)
                {
                    DrawCustomIcon(parentItem, selectionRect);
                }
                if (parentItem.IsBackgroundRecursive)
                {
                    DrawCustomBackground(parentItem, selectionRect);
                }
                return;
            }
        }