Ejemplo n.º 1
0
        private static void OnHierarchyWindowChanged()
        {
            var scene         = EditorSceneManager.GetActiveScene();
            var isSceneLoaded = scene.name != m_currentSceneName ||
                                // Drag drop of scene into hierarchy.
                                EditorSceneManager.loadedSceneCount > m_numScenesLoaded;

            if (isSceneLoaded)
            {
                EditorData.Instance.GC();

                m_currentSceneName = scene.name;

                AutoUpdateSceneHandler.HandleUpdates(scene);
            }
            else if (Selection.activeGameObject != null)
            {
#if UNITY_2018_3_OR_NEWER
                var isPrefabInstance = PrefabUtility.GetPrefabInstanceStatus(Selection.activeGameObject) != PrefabInstanceStatus.NotAPrefab;
#else
                var isPrefabInstance = PrefabUtility.GetPrefabType(Selection.activeGameObject) == PrefabType.PrefabInstance ||
                                       PrefabUtility.GetPrefabType(Selection.activeGameObject) == PrefabType.DisconnectedPrefabInstance;
#endif
                if (isPrefabInstance)
                {
                    AssetPostprocessorHandler.OnPrefabAddedToScene(Selection.activeGameObject);
                }
            }

            m_numScenesLoaded = EditorSceneManager.loadedSceneCount;
        }
Ejemplo n.º 2
0
        private static void OnHierarchyWindowChanged()
        {
            var scene         = EditorSceneManager.GetActiveScene();
            var isSceneLoaded = scene.name != m_currentSceneName ||
                                // Drag drop of scene into hierarchy.
                                EditorSceneManager.loadedSceneCount > m_numScenesLoaded;

            if (isSceneLoaded)
            {
                EditorData.Instance.GC();

                m_currentSceneName = scene.name;

                AutoUpdateSceneHandler.HandleUpdates(scene);
            }
            else if (Selection.activeGameObject != null)
            {
                var isPrefabInstance = PrefabUtility.GetPrefabInstanceStatus(Selection.activeGameObject) != PrefabInstanceStatus.NotAPrefab;

                // We want to catch when a prefab has been instantiated in the
                // scene. Maybe this feature should be explicit, i.e., some
                // method doing the work.
                // NOTE: We receive callbacks to OnHierarchyWindowChanged when a
                //       component is added and when the undo/redo is performed.
                //       To not screw up the undo/redo history we block this feature
                //       when undo/redo has been made close in time.
                // TODO: Make this work - OnHierarchyWindowChanged is not a good place
                //       to instantiate additional things.
                if (isPrefabInstance && (EditorApplication.timeSinceStartup - s_lastUndoRedoTime) > 2.0)
                {
                    AssetPostprocessorHandler.OnPrefabAddedToScene(Selection.activeGameObject);
                }
            }

            m_numScenesLoaded = EditorSceneManager.loadedSceneCount;
        }