internal static void CutGO() { m_GOCutboard = Selection.transforms; m_SelectedObjects = Selection.objects; // Selection.transform does not provide correct list order, so we have to do it manually m_GOCutboard = m_GOCutboard.ToList().OrderBy(g => Array.IndexOf(m_SelectedObjects, g.gameObject)).ToArray(); // Return if nothing selected if (!hasCutboardData) { return; } m_StageCutWasPerformedIn = StageUtility.GetStage(m_GOCutboard[0].gameObject); // If cut gameObject is prefab, get its root transform for (int i = 0; i < m_GOCutboard.Length; i++) { if (PrefabUtility.GetPrefabAssetType(m_GOCutboard[i].gameObject) != PrefabAssetType.NotAPrefab) { m_GOCutboard[i] = PrefabUtility.GetOutermostPrefabInstanceRoot(m_GOCutboard[i].gameObject)?.transform; } } // Cut gameObjects should be visually marked as cut, so adding them to the hashset m_CutAffectedGOs.Clear(); foreach (var item in m_GOCutboard) { m_CutAffectedGOs.Add(item); AddChildrenToHashset(item); } // Clean pasteboard when cutting gameObjects Unsupported.ClearPasteboard(); }
void DrawGizmos(bool usingRenderPipeline) { UnityEngine.Profiling.Profiler.BeginSample("Refresh Selection Cache"); GizmoContext.Refresh(); UnityEngine.Profiling.Profiler.EndSample(); UnityEngine.Profiling.Profiler.BeginSample("GizmosAllowed"); typeToGizmosEnabled.Clear(); if (!usingRenderPipeline) { // Fill the typeToGizmosEnabled dict with info about which classes should be drawn // We take advantage of the fact that IsGizmosAllowedForObject only depends on the type of the object and if it is active and enabled // and not the specific object instance. // When using a render pipeline the ShouldDrawGizmos method cannot be used because it seems to occasionally crash Unity :( // So we need these two separate cases. for (int i = gizmoDrawers.Count - 1; i >= 0; i--) { var tp = gizmoDrawers[i].GetType(); if (!typeToGizmosEnabled.ContainsKey(tp) && (gizmoDrawers[i] as MonoBehaviour).isActiveAndEnabled) { typeToGizmosEnabled[tp] = ShouldDrawGizmos((UnityEngine.Object)gizmoDrawers[i]); } } } UnityEngine.Profiling.Profiler.EndSample(); // Set the current frame's redraw scope to an empty scope. // This is because gizmos are rendered every frame anyway so we never want to redraw them. // The frame redraw scope is otherwise used when the game has been paused. var frameRedrawScope = gizmos.frameRedrawScope; gizmos.frameRedrawScope = default(RedrawScope); #if UNITY_EDITOR && UNITY_2020_1_OR_NEWER var currentStage = StageUtility.GetCurrentStage(); var isInNonMainStage = currentStage != StageUtility.GetMainStage(); #endif // This would look nicer as a 'using' block, but built-in command builders // cannot be disposed normally to prevent user error. // The try-finally is equivalent to a 'using' block. var gizmoBuilder = gizmos.GetBuiltInBuilder(); try { // Replace Draw.builder with a custom one just for gizmos var debugBuilder = Draw.builder; Draw.builder = gizmoBuilder; UnityEngine.Profiling.Profiler.BeginSample("DrawGizmos"); GizmoContext.drawingGizmos = true; if (usingRenderPipeline) { for (int i = gizmoDrawers.Count - 1; i >= 0; i--) { #if UNITY_EDITOR && UNITY_2020_1_OR_NEWER // True if the scene is in isolation mode (e.g. focusing on a single prefab) and this object is not part of that sub-stage var disabledDueToIsolationMode = isInNonMainStage && StageUtility.GetStage((gizmoDrawers[i] as MonoBehaviour).gameObject) != currentStage; #else var disabledDueToIsolationMode = false; #endif if ((gizmoDrawers[i] as MonoBehaviour).isActiveAndEnabled && !disabledDueToIsolationMode) { try { gizmoDrawers[i].DrawGizmos(); } catch (System.Exception e) { Debug.LogException(e, gizmoDrawers[i] as MonoBehaviour); } } } } else { for (int i = gizmoDrawers.Count - 1; i >= 0; i--) { #if UNITY_EDITOR && UNITY_2020_1_OR_NEWER // True if the scene is in isolation mode (e.g. focusing on a single prefab) and this object is not part of that sub-stage var disabledDueToIsolationMode = isInNonMainStage && StageUtility.GetStage((gizmoDrawers[i] as MonoBehaviour).gameObject) != currentStage; #else var disabledDueToIsolationMode = false; #endif if ((gizmoDrawers[i] as MonoBehaviour).isActiveAndEnabled && typeToGizmosEnabled[gizmoDrawers[i].GetType()] && !disabledDueToIsolationMode) { try { gizmoDrawers[i].DrawGizmos(); } catch (System.Exception e) { Debug.LogException(e, gizmoDrawers[i] as MonoBehaviour); } } } } GizmoContext.drawingGizmos = false; UnityEngine.Profiling.Profiler.EndSample(); // Revert to the original builder Draw.builder = debugBuilder; } finally { gizmoBuilder.DisposeInternal(); } gizmos.frameRedrawScope = frameRedrawScope; // Schedule jobs that may have been scheduled while drawing gizmos JobHandle.ScheduleBatchedJobs(); }
public static PrefabStage GetPrefabStage(GameObject gameObject) { return(StageUtility.GetStage(gameObject) as PrefabStage); }