Exemplo n.º 1
0
        private static void OnHierarchyWindowChanged()
        {
            if (HierarchyUtils.IsHierarchyWindowInPrefabMode())
            {
                return;
            }

            if (IsSceneChanged())
            {
                // Create our marker
                _cachedGo   = new GameObject(GameObjectName, typeof(HierarchyNode));
                _cachedNode = _cachedGo.GetComponent <HierarchyNode>();

                // Note: We don't use the DontSaveInEditor flag as this causes OnDestroy/OnDisable() to not be called when the scene unloads
                _cachedGo.hideFlags = HideFlags.NotEditable | HideFlags.HideInHierarchy | HideFlags.HideInInspector;
#if UNITY_5 || UNITY_5_4_OR_NEWER
                _cachedGo.hideFlags |= HideFlags.DontSaveInBuild;
#endif
            }

            if (_cachedNode != null)
            {
                _cachedNode.SetHierarchyDirty();
            }
        }
Exemplo n.º 2
0
        private void RestoreSelection()
        {
            if (HierarchyUtils.IsHierarchyWindowInPrefabMode())
            {
                return;
            }

            UpdateSceneGUID();
            if (!string.IsNullOrEmpty(_sceneGUID))
            {
                _hierarchyPathList = RestoreHierarchyState(_sceneGUID, true);
                _selectionPathList = RestoreSelectionState(_sceneGUID, true);
                //Debug.Log("hierarchy " + _hierarchyPathList);
                //Debug.Log("selection " + _selectionPathList);
                if (string.IsNullOrEmpty(_selectionPathList))
                {
                    // No selection was restored, so we need to select at least one node so that the hierarchy expansion happens.
                    // So just select one of the items in the hierarchyList
                    string[] paths = null;
                    {
                        // Convert the string list to an array
                        if (!string.IsNullOrEmpty(_hierarchyPathList))
                        {
                            paths = _hierarchyPathList.Split(new char[] { '*' }, System.StringSplitOptions.RemoveEmptyEntries);
                        }

                        // Select the first found expanded object
                        if (paths != null && paths.Length > 0)
                        {
                            foreach (string path in paths)
                            {
                                GameObject go = GameObject.Find(path);
                                if (go != null)
                                {
                                    Selection.activeGameObject = go;
                                    break;
                                }
                            }
                        }
                    }
                }

                // Only force the hierarchy window to update if something has changed
                if (Selection.activeGameObject != null || !string.IsNullOrEmpty(_hierarchyPathList))
                {
                    // Force the hierarchy window to update to the current selection
                    EditorApplication.DirtyHierarchyWindowSorting();

                    // NOTE: We need to use the delayCall because sometimes DirtyHierarchyWindowSorting() doesn't work the first time
                    EditorApplication.delayCall += () =>
                    {
                        // Force the hierarchy window to update to the current selection
                        EditorApplication.DirtyHierarchyWindowSorting();
                    };
                }
            }
        }
Exemplo n.º 3
0
        // When the scene closes, this node will get destroyed, at which point we save the scene state information
        private void OnDestroy()
        {
            if (HierarchyUtils.IsHierarchyWindowInPrefabMode())
            {
                return;
            }

            SaveHierarchyState(_hierarchyPathList, _sceneGUID);
            SaveSelectionState(_selectionPathList, _sceneGUID);
        }
Exemplo n.º 4
0
 private void OnEditorUpdate()
 {
     // Editor updates are expensive, so don't do them too often as it can slow down the UI
     if (editorUpdateCount > 50 &&
         // We don't want to save hierarchy/selection when the app is playing
         !EditorApplication.isPlaying &&
         !EditorApplication.isPlayingOrWillChangePlaymode &&
         !EditorApplication.isCompiling &&
         !EditorApplication.isUpdating &&
         !HierarchyUtils.IsHierarchyWindowInPrefabMode())
     {
         editorUpdateCount = 0;
         if (HasSelectionChanged() || HasHierarchyChanged())
         {
             CacheHierarchy();
         }
     }
     editorUpdateCount++;
 }