private void OnHierarchyChangedInEditMode()
        {
            hierarchyFolders.RemoveAll(isNull);
            hierarchyFolders.Sort(compareHierarchyDepth);

                        #if DEV_MODE && DEBUG_HIERARCHY_CHANGED
            Debug.Log("OnHierarchyChangedInEditMode with hierarchyFolders=" + hierarchyFolders.Count);
                        #endif

            bool prefabsNotAllowed = HierarchyFolderPreferences.Get().foldersInPrefabs == HierachyFoldersInPrefabs.NotAllowed;

            for (int n = 0, count = hierarchyFolders.Count - 1; n < count; n++)
            {
                var hierarchyFolder = hierarchyFolders[n];

                // Only process scene objects, not prefabs.
                if (!hierarchyFolder.gameObject.scene.IsValid())
                {
                    continue;
                }

                if (prefabsNotAllowed && hierarchyFolder.gameObject.IsConnectedPrefabInstance())
                {
                    OnHierarchyFolderDetectedOnAPrefabAndNotAllowed(hierarchyFolder, true);
                    count = hierarchyFolders.Count;
                    continue;
                }

                // If has RectTransform child convert Transform component into RectTransform
                // to avoid child RectTransform values being affected by the parent hierarchy folders.
                // For performance reasons only first child is checked.
                var transform = hierarchyFolder.transform;
                if (transform.GetFirstChild(true) is RectTransform && !(transform is RectTransform))
                {
                                        #if DEV_MODE
                    Debug.LogWarning("Converting Hierarchy Folder " + hierarchyFolder.name + " Transform into RectTransform because it had a RectTransform child.", hierarchyFolder);
                                        #endif

                    HierarchyFolderUtility.ForceResetTransformStateWithoutAffectingChildren(transform, true);
                }

                ApplyNamingPattern(hierarchyFolder);

                OnHierarchyChangedShared(hierarchyFolder);
            }

            hierarchyFolders.RemoveAll(isNull);
        }