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; }
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; }
private static void OnHierarchyWindowChanged() { var scene = UnityEditor.SceneManagement.EditorSceneManager.GetActiveScene(); if (scene.name != m_currentSceneName) { EditorData.Instance.GC(); m_currentSceneName = scene.name; // - Verifies so that our shapes doesn't have multiple debug rendering components. // - Verifies version of OnSelectionProxy and patches it if Target == null. AGXUnity.Collide.Shape[] shapes = UnityEngine.Object.FindObjectsOfType <AGXUnity.Collide.Shape>(); foreach (var shape in shapes) { OnSelectionProxy selectionProxy = shape.GetComponent <OnSelectionProxy>(); if (selectionProxy != null && selectionProxy.Target == null) { selectionProxy.Component = shape; } AGXUnity.Rendering.ShapeDebugRenderData[] data = shape.GetComponents <AGXUnity.Rendering.ShapeDebugRenderData>(); if (data.Length > 1) { Debug.Log("Shape has several ShapeDebugRenderData. Removing/resetting.", shape); foreach (var instance in data) { Component.DestroyImmediate(instance); } data = null; } } // Verifying shape visuals material. { AGXUnity.Rendering.ShapeVisual[] shapeVisuals = UnityEngine.Object.FindObjectsOfType <AGXUnity.Rendering.ShapeVisual>(); foreach (var shapeVisual in shapeVisuals) { var renderers = shapeVisual.GetComponentsInChildren <MeshRenderer>(); foreach (var renderer in renderers) { if (renderer.sharedMaterial == null) { renderer.sharedMaterial = GetOrCreateShapeVisualDefaultMaterial(); Debug.Log("Shape visual with null material. Assigning default.", shapeVisual); if (!EditorApplication.isPlaying) { UnityEditor.SceneManagement.EditorSceneManager.MarkSceneDirty(scene); } } } } } } else if (Selection.activeGameObject != null) { if (Selection.activeGameObject.GetComponent <AGXUnity.IO.RestoredAGXFile>() != null) { AssetPostprocessorHandler.OnPrefabAddedToScene(Selection.activeGameObject); } var savedPrefabData = Selection.activeGameObject.GetComponent <AGXUnity.IO.SavedPrefabLocalData>(); if (savedPrefabData != null && savedPrefabData.DisabledGroups.Length > 0) { Undo.SetCurrentGroupName("Adding prefab data for " + Selection.activeGameObject.name + " to scene."); var grouId = Undo.GetCurrentGroup(); foreach (var disabledGroup in savedPrefabData.DisabledGroups) { TopMenu.GetOrCreateUniqueGameObject <AGXUnity.CollisionGroupsManager>().SetEnablePair(disabledGroup.First, disabledGroup.Second, false); } Undo.CollapseUndoOperations(grouId); } } }