static bool RejectDrawMode(SceneView.CameraMode cameraMode) { if ( //cameraMode.drawMode == DrawCameraMode.TexturedWire || //cameraMode.drawMode == DrawCameraMode.Wireframe || cameraMode.drawMode == DrawCameraMode.ShadowCascades || cameraMode.drawMode == DrawCameraMode.RenderPaths || //cameraMode.drawMode == DrawCameraMode.AlphaChannel || //cameraMode.drawMode == DrawCameraMode.Overdraw || //cameraMode.drawMode == DrawCameraMode.Mipmaps || cameraMode.drawMode == DrawCameraMode.SpriteMask || cameraMode.drawMode == DrawCameraMode.DeferredDiffuse || cameraMode.drawMode == DrawCameraMode.DeferredSpecular || cameraMode.drawMode == DrawCameraMode.DeferredSmoothness || cameraMode.drawMode == DrawCameraMode.DeferredNormal || cameraMode.drawMode == DrawCameraMode.ValidateAlbedo || cameraMode.drawMode == DrawCameraMode.ValidateMetalSpecular || cameraMode.drawMode == DrawCameraMode.ShadowMasks //cameraMode.drawMode == DrawCameraMode.LightOverlap ) { return(false); } return(true); }
private void UpdateShadingMode(bool wireframeOn) { if (SceneView.lastActiveSceneView == null) { Debug.LogWarning("currentDrawingSceneView is null"); return; } #if UNITY_2018_1_OR_NEWER SceneView.CameraMode newMode = SceneView.lastActiveSceneView.cameraMode; if (wireframeOn) { newMode.drawMode = DrawCameraMode.TexturedWire; } else { newMode.drawMode = DrawCameraMode.Textured; } #else if (wireframeOn) { SceneView.lastActiveSceneView.renderMode = DrawCameraMode.TexturedWire; } else { SceneView.lastActiveSceneView.renderMode = DrawCameraMode.Textured; } #endif SceneView.RepaintAll(); }
public void SaveStateFromSceneView(SceneView view) { cameraMode = view.cameraMode; sceneLighting = view.sceneLighting; audioPlay = view.audioPlay; sceneViewState = new SceneView.SceneViewState(view.sceneViewState); in2DMode = view.in2DMode; pivot = view.pivot; rotation = view.rotation; size = view.size; orthographic = view.orthographic; }
static bool AcceptedDrawMode(SceneView.CameraMode cameraMode) { // if ( // cameraMode.drawMode == DrawCameraMode.Wireframe || // cameraMode.drawMode == DrawCameraMode.TexturedWire || // cameraMode.drawMode == DrawCameraMode.Textured || // //cameraMode.drawMode == DrawCameraMode.Normal || // cameraMode.drawMode == DrawCameraMode.UserDefined // ) // return true; return(true); }
public ViewSettings(Vector3 pivot, Quaternion rotation, float size, bool ortho, float fieldOfView, bool is2D, SceneView.CameraMode cameraMode, bool drawGizmos, bool sceneLighting, SceneView.SceneViewState sceneViewState, bool showGrid) { this.pivot = pivot; this.rotation = rotation; this.size = size; this.ortho = ortho; this.fov = fieldOfView; this.is2D = is2D; this.mode = cameraMode; this.drawGizmos = drawGizmos; this.sceneLighting = sceneLighting; this.sceneViewState = new SceneView.SceneViewState(sceneViewState); this.showGrid = showGrid; }
public ViewSettings(SceneView sceneView) { this.pivot = sceneView.pivot; this.rotation = sceneView.rotation; this.size = sceneView.size; this.ortho = sceneView.orthographic; this.fov = sceneView.cameraSettings.fieldOfView; this.is2D = sceneView.in2DMode; this.mode = sceneView.cameraMode; this.drawGizmos = sceneView.drawGizmos; this.sceneLighting = sceneView.sceneLighting; this.sceneViewState = new SceneView.SceneViewState(sceneView.sceneViewState); this.showGrid = sceneView.showGrid; }
private void DoBuiltinMode(EditorWindow caller, ref Rect rect, SceneView.CameraMode mode) { using (new EditorGUI.DisabledScope(!this.m_SceneView.CheckDrawModeForRenderingPath(mode.drawMode))) { EditorGUI.BeginChangeCheck(); GUI.Toggle(rect, this.m_SceneView.cameraMode == mode, EditorGUIUtility.TextContent(mode.name), SceneRenderModeWindow.Styles.sMenuItem); if (EditorGUI.EndChangeCheck()) { this.m_SceneView.cameraMode = mode; this.m_SceneView.Repaint(); GUIUtility.ExitGUI(); } rect.y += 16f; } }
void OnCameraModeChanged(SceneView.CameraMode mode) { // If the rootVisualElement hasn't yet been created, early out if (m_ContentRoot == null) { CreatePanelContent(); } m_AlbedoContent.EnableInClassList(k_UnityHiddenClass, mode.drawMode != DrawCameraMode.ValidateAlbedo && mode.drawMode != DrawCameraMode.ValidateMetalSpecular); m_AlbedoContent.Q("Albedo").EnableInClassList(k_UnityHiddenClass, mode.drawMode != DrawCameraMode.ValidateAlbedo); m_LightExposureContent.EnableInClassList(k_UnityHiddenClass, !sceneView.showExposureSettings); m_GlobalIlluminationContent.EnableInClassList(k_UnityHiddenClass, mode.drawMode != DrawCameraMode.GIContributorsReceivers); m_ShouldDisplay = true; switch (mode.drawMode) { case DrawCameraMode.ValidateAlbedo: case DrawCameraMode.ValidateMetalSpecular: displayName = "PBR Validation Settings"; m_AlbedoContent.Q <HelpBox>().EnableInClassList(k_UnityHiddenClass, PlayerSettings.colorSpace != ColorSpace.Gamma); m_SceneView.SetOverlayVisible(k_OverlayID, true); break; case DrawCameraMode.BakedEmissive: case DrawCameraMode.BakedLightmap: case DrawCameraMode.RealtimeEmissive: case DrawCameraMode.RealtimeIndirect: displayName = "Lightmap Exposure"; m_SceneView.SetOverlayVisible(k_OverlayID, true); break; case DrawCameraMode.GIContributorsReceivers: displayName = "GI Contributors / Receivers"; break; default: m_ShouldDisplay = false; break; } UpdateAlbedoMetalValidation(); Handles.SetSceneViewModeGIContributorsReceiversColors( kSceneViewMaterialNoContributeGI.Color, kSceneViewMaterialReceiveGILightmaps.Color, kSceneViewMaterialReceiveGILightProbes.Color); }
void DoBuiltinMode(ref Rect rect, SceneView.CameraMode mode) { using (new EditorGUI.DisabledScope(!m_SceneView.CheckDrawModeForRenderingPath(mode.drawMode))) { EditorGUI.BeginChangeCheck(); GUI.Toggle(rect, m_SceneView.cameraMode == mode, EditorGUIUtility.TextContent(mode.name), Styles.sMenuItem); if (EditorGUI.EndChangeCheck()) { m_SceneView.cameraMode = mode; m_SceneView.Repaint(); GUIUtility.ExitGUI(); } rect.y += EditorGUI.kSingleLineHeight; } }
static void UpdateCommandBuffer(Camera cam, SceneView.CameraMode mode) { // If this is the first time we're rendering this camera, create a command buffer and add it to the camera. if (!commandBuffers.TryGetValue(cam, out var buffer)) { buffer = new CommandBuffer(); buffer.name = $"Custom Camera Mode"; cam.AddCommandBuffer(CameraEvent.AfterForwardAlpha, buffer); commandBuffers[cam] = buffer; } // Select the right source texture and blit it into the camera target. var source = mode == depthCameraMode ? BuiltinRenderTextureType.Depth : BuiltinRenderTextureType.DepthNormals; int blitPass = mode == depthCameraMode ? depthBlitPass : normalsBlitPass; buffer.Clear(); buffer.Blit(source, BuiltinRenderTextureType.CameraTarget, BlitMaterial, blitPass); }
static private bool RejectDrawMode(SceneView.CameraMode cameraMode) { if (cameraMode.drawMode == DrawCameraMode.ShadowCascades || cameraMode.drawMode == DrawCameraMode.RenderPaths || cameraMode.drawMode == DrawCameraMode.AlphaChannel || cameraMode.drawMode == DrawCameraMode.Overdraw || cameraMode.drawMode == DrawCameraMode.Mipmaps || cameraMode.drawMode == DrawCameraMode.DeferredDiffuse || cameraMode.drawMode == DrawCameraMode.DeferredSpecular || cameraMode.drawMode == DrawCameraMode.DeferredSmoothness || cameraMode.drawMode == DrawCameraMode.DeferredNormal || cameraMode.drawMode == DrawCameraMode.ValidateAlbedo || cameraMode.drawMode == DrawCameraMode.ValidateMetalSpecular ) { return(false); } return(true); }
void SceneViewOnCameraModeChanged(SceneView.CameraMode mode) { switch (mode.name) { case "Shaded": icon = m_ShadedIcon; break; case "Wireframe": icon = m_WireframeIcon; break; case "Shaded Wireframe": icon = m_ShadedWireframeIcon; break; default: icon = m_DebugIcon; break; } }
private static void OnCameraModeChanged(SceneView sceneView) { var overdrawMode = GetOverdrawMode(); SceneView.CameraMode cameraMode = sceneView.cameraMode; if (!Utility.IsExistOverdrawRenderer()) { if (cameraMode.name.Equals(overdrawMode.name)) { Debug.LogError("[OverdrawForURP] Not set OverdrawRenderer asset. Please add to UniversalRenderpipelineAsset."); } return; } Object asset = Utility.LoadUniversalRenderPipelineAsset(); var so = new SerializedObject(asset); SerializedProperty prop = so.FindProperty("m_DefaultRendererIndex"); int overdrawRendererIndex = Utility.GetOverdrawRendererIndex(asset); if (cameraMode.name.Equals(overdrawMode.name)) { if (prop.intValue != overdrawRendererIndex) { EditorPrefs.SetInt(RendererIndexKey, prop.intValue); } prop.intValue = overdrawRendererIndex; so.ApplyModifiedProperties(); } else { if (EditorPrefs.HasKey(RendererIndexKey) && prop.intValue == overdrawRendererIndex) { prop.intValue = EditorPrefs.GetInt(RendererIndexKey); so.ApplyModifiedProperties(); } } }
void SceneViewOnCameraModeChanged(SceneView.CameraMode mode) { RemoveFromClassList(currentUssClassName); switch (mode.name) { case "Shaded": currentUssClassName = s_UssClassName_Shaded; break; case "Wireframe": currentUssClassName = s_UssClassName_Wireframe; break; case "Shaded Wireframe": currentUssClassName = s_UssClassName_ShadedWireframe; break; default: currentUssClassName = s_UssClassName_Debug; break; } AddToClassList(currentUssClassName); }
/** * Static function to handle the GUI and User input related to the cascade slider. * * @param normalizedCascadePartition The array of partition sizes in the range 0.0f - 1.0f; expects ONE entry if cascades = 2, and THREE if cascades=4 * The last entry will be automatically determined by summing up the array, and doing 1.0f - sum */ public static void HandleCascadeSliderGUI(ref float[] normalizedCascadePartitions) { EditorGUILayout.LabelField("Cascade splits"); // get the inspector width since we need it while drawing the partition rects. // Only way currently is to reserve the block in the layout using GetRect(), and then immediately drawing the empty box // to match the call to GetRect. // From this point on, we move to non-layout based code. var sliderRect = GUILayoutUtility.GetRect(GUIContent.none , s_CascadeSliderBG , GUILayout.Height(kSliderbarTopMargin + kSliderbarHeight + kSliderbarBottomMargin) , GUILayout.ExpandWidth(true)); GUI.Box(sliderRect, GUIContent.none); float currentX = sliderRect.x; float cascadeBoxStartY = sliderRect.y + kSliderbarTopMargin; float cascadeSliderWidth = sliderRect.width - (normalizedCascadePartitions.Length * kPartitionHandleWidth); Color origTextColor = GUI.color; Color origBackgroundColor = GUI.backgroundColor; int colorIndex = -1; // setup the array locally with the last partition float[] adjustedCascadePartitions = new float[normalizedCascadePartitions.Length + 1]; System.Array.Copy(normalizedCascadePartitions, adjustedCascadePartitions, normalizedCascadePartitions.Length); adjustedCascadePartitions[adjustedCascadePartitions.Length - 1] = 1.0f - normalizedCascadePartitions.Sum(); // check for user input on any of the partition handles // this mechanism gets the current event in the queue... make sure that the mouse is over our control before consuming the event int sliderControlId = GUIUtility.GetControlID(s_CascadeSliderId, FocusType.Passive); Event currentEvent = Event.current; int hotPartitionHandleIndex = -1; // the index of any partition handle that we are hovering over or dragging // draw each cascade partition for (int i = 0; i < adjustedCascadePartitions.Length; ++i) { float currentPartition = adjustedCascadePartitions[i]; colorIndex = (colorIndex + 1) % kCascadeColors.Length; GUI.backgroundColor = kCascadeColors[colorIndex]; float boxLength = (cascadeSliderWidth * currentPartition); // main cascade box Rect partitionRect = new Rect(currentX, cascadeBoxStartY, boxLength, kSliderbarHeight); GUI.Box(partitionRect, GUIContent.none, s_CascadeSliderBG); currentX += boxLength; // cascade box percentage text GUI.color = Color.white; Rect textRect = partitionRect; var cascadeText = string.Format("{0}\n{1:F1}%", i, currentPartition * 100.0f); GUI.Label(textRect, cascadeText, s_TextCenteredStyle); // no need to draw the partition handle for last box if (i == adjustedCascadePartitions.Length - 1) { break; } // partition handle GUI.backgroundColor = Color.black; Rect handleRect = partitionRect; handleRect.x = currentX; handleRect.width = kPartitionHandleWidth; GUI.Box(handleRect, GUIContent.none, s_CascadeSliderBG); // we want a thin handle visually (since wide black bar looks bad), but a slightly larger // hit area for easier manipulation Rect handleHitRect = handleRect; handleHitRect.xMin -= kPartitionHandleExtraHitAreaWidth; handleHitRect.xMax += kPartitionHandleExtraHitAreaWidth; if (handleHitRect.Contains(currentEvent.mousePosition)) { hotPartitionHandleIndex = i; } // add regions to slider where the cursor changes to Resize-Horizontal if (s_DragCache == null) { EditorGUIUtility.AddCursorRect(handleHitRect, MouseCursor.ResizeHorizontal, sliderControlId); } currentX += kPartitionHandleWidth; } GUI.color = origTextColor; GUI.backgroundColor = origBackgroundColor; EventType eventType = currentEvent.GetTypeForControl(sliderControlId); switch (eventType) { case EventType.MouseDown: if (hotPartitionHandleIndex >= 0) { s_DragCache = new DragCache(hotPartitionHandleIndex, normalizedCascadePartitions[hotPartitionHandleIndex], currentEvent.mousePosition); if (GUIUtility.hotControl == 0) { GUIUtility.hotControl = sliderControlId; } currentEvent.Use(); // Switch active scene view into shadow cascades visualization mode, once we start // tweaking cascade splits. if (s_RestoreSceneView == null) { s_RestoreSceneView = SceneView.lastActiveSceneView; if (s_RestoreSceneView != null) { s_OldSceneDrawMode = s_RestoreSceneView.cameraMode; s_OldSceneLightingMode = s_RestoreSceneView.m_SceneLighting; s_RestoreSceneView.cameraMode = SceneView.GetBuiltinCameraMode(DrawCameraMode.ShadowCascades); } } } break; case EventType.MouseUp: // mouseUp event anywhere should release the hotcontrol (if it belongs to us), drags (if any) if (GUIUtility.hotControl == sliderControlId) { GUIUtility.hotControl = 0; currentEvent.Use(); } s_DragCache = null; // Restore previous scene view drawing mode once we stop tweaking cascade splits. if (s_RestoreSceneView != null) { s_RestoreSceneView.cameraMode = s_OldSceneDrawMode; s_RestoreSceneView.m_SceneLighting = s_OldSceneLightingMode; s_RestoreSceneView = null; } break; case EventType.MouseDrag: if (GUIUtility.hotControl != sliderControlId) { break; } // convert the mouse movement to normalized cascade width. Make sure that we are safe to apply the delta before using it. float delta = (currentEvent.mousePosition - s_DragCache.m_LastCachedMousePosition).x / cascadeSliderWidth; bool isLeftPartitionHappy = ((adjustedCascadePartitions[s_DragCache.m_ActivePartition] + delta) > 0.0f); bool isRightPartitionHappy = ((adjustedCascadePartitions[s_DragCache.m_ActivePartition + 1] - delta) > 0.0f); if (isLeftPartitionHappy && isRightPartitionHappy) { s_DragCache.m_NormalizedPartitionSize += delta; normalizedCascadePartitions[s_DragCache.m_ActivePartition] = s_DragCache.m_NormalizedPartitionSize; if (s_DragCache.m_ActivePartition < normalizedCascadePartitions.Length - 1) { normalizedCascadePartitions[s_DragCache.m_ActivePartition + 1] -= delta; } GUI.changed = true; } s_DragCache.m_LastCachedMousePosition = currentEvent.mousePosition; currentEvent.Use(); break; } }
static void Initialize() { depthCameraMode = SceneView.AddCameraMode("Camera Depth", "Shading Mode"); normalsCameraMode = SceneView.AddCameraMode("Camera Normals", "Shading Mode"); Camera.onPreRender += OnPreRender; }
public static void HandleCascadeSliderGUI(ref float[] normalizedCascadePartitions) { GUILayout.Label("Cascade splits", new GUILayoutOption[0]); Rect rect = GUILayoutUtility.GetRect(GUIContent.none, ShadowCascadeSplitGUI.s_CascadeSliderBG, new GUILayoutOption[] { GUILayout.Height(28f), GUILayout.ExpandWidth(true) }); GUI.Box(rect, GUIContent.none); float num = rect.x; float y = rect.y + 2f; float num2 = rect.width - (float)(normalizedCascadePartitions.Length * 2); Color color = GUI.color; Color backgroundColor = GUI.backgroundColor; int num3 = -1; float[] array = new float[normalizedCascadePartitions.Length + 1]; Array.Copy(normalizedCascadePartitions, array, normalizedCascadePartitions.Length); array[array.Length - 1] = 1f - normalizedCascadePartitions.Sum(); int controlID = GUIUtility.GetControlID(ShadowCascadeSplitGUI.s_CascadeSliderId, FocusType.Passive); Event current = Event.current; int num4 = -1; for (int i = 0; i < array.Length; i++) { float num5 = array[i]; num3 = (num3 + 1) % ShadowCascadeSplitGUI.kCascadeColors.Length; GUI.backgroundColor = ShadowCascadeSplitGUI.kCascadeColors[num3]; float num6 = num2 * num5; Rect rect2 = new Rect(num, y, num6, 24f); GUI.Box(rect2, GUIContent.none, ShadowCascadeSplitGUI.s_CascadeSliderBG); num += num6; GUI.color = Color.white; Rect position = rect2; string text = string.Format("{0}\n{1:F1}%", i, num5 * 100f); GUI.Label(position, GUIContent.Temp(text, text), ShadowCascadeSplitGUI.s_TextCenteredStyle); if (i == array.Length - 1) { break; } GUI.backgroundColor = Color.black; Rect rect3 = rect2; rect3.x = num; rect3.width = 2f; GUI.Box(rect3, GUIContent.none, ShadowCascadeSplitGUI.s_CascadeSliderBG); Rect position2 = rect3; position2.xMin -= 2f; position2.xMax += 2f; if (position2.Contains(current.mousePosition)) { num4 = i; } if (ShadowCascadeSplitGUI.s_DragCache == null) { EditorGUIUtility.AddCursorRect(position2, MouseCursor.ResizeHorizontal, controlID); } num += 2f; } GUI.color = color; GUI.backgroundColor = backgroundColor; EventType typeForControl = current.GetTypeForControl(controlID); if (typeForControl != EventType.MouseDown) { if (typeForControl != EventType.MouseUp) { if (typeForControl == EventType.MouseDrag) { if (GUIUtility.hotControl == controlID) { float num7 = (current.mousePosition - ShadowCascadeSplitGUI.s_DragCache.m_LastCachedMousePosition).x / num2; bool flag = array[ShadowCascadeSplitGUI.s_DragCache.m_ActivePartition] + num7 > 0f; bool flag2 = array[ShadowCascadeSplitGUI.s_DragCache.m_ActivePartition + 1] - num7 > 0f; if (flag && flag2) { ShadowCascadeSplitGUI.s_DragCache.m_NormalizedPartitionSize += num7; normalizedCascadePartitions[ShadowCascadeSplitGUI.s_DragCache.m_ActivePartition] = ShadowCascadeSplitGUI.s_DragCache.m_NormalizedPartitionSize; if (ShadowCascadeSplitGUI.s_DragCache.m_ActivePartition < normalizedCascadePartitions.Length - 1) { normalizedCascadePartitions[ShadowCascadeSplitGUI.s_DragCache.m_ActivePartition + 1] -= num7; } GUI.changed = true; } ShadowCascadeSplitGUI.s_DragCache.m_LastCachedMousePosition = current.mousePosition; current.Use(); } } } else { if (GUIUtility.hotControl == controlID) { GUIUtility.hotControl = 0; current.Use(); } ShadowCascadeSplitGUI.s_DragCache = null; if (ShadowCascadeSplitGUI.s_RestoreSceneView != null) { ShadowCascadeSplitGUI.s_RestoreSceneView.cameraMode = ShadowCascadeSplitGUI.s_OldSceneDrawMode; ShadowCascadeSplitGUI.s_RestoreSceneView.m_SceneLighting = ShadowCascadeSplitGUI.s_OldSceneLightingMode; ShadowCascadeSplitGUI.s_RestoreSceneView = null; } } } else if (num4 >= 0) { ShadowCascadeSplitGUI.s_DragCache = new ShadowCascadeSplitGUI.DragCache(num4, normalizedCascadePartitions[num4], current.mousePosition); if (GUIUtility.hotControl == 0) { GUIUtility.hotControl = controlID; } current.Use(); if (ShadowCascadeSplitGUI.s_RestoreSceneView == null) { ShadowCascadeSplitGUI.s_RestoreSceneView = SceneView.lastActiveSceneView; if (ShadowCascadeSplitGUI.s_RestoreSceneView != null) { ShadowCascadeSplitGUI.s_OldSceneDrawMode = ShadowCascadeSplitGUI.s_RestoreSceneView.cameraMode; ShadowCascadeSplitGUI.s_OldSceneLightingMode = ShadowCascadeSplitGUI.s_RestoreSceneView.m_SceneLighting; ShadowCascadeSplitGUI.s_RestoreSceneView.cameraMode = SceneView.GetBuiltinCameraMode(DrawCameraMode.ShadowCascades); } } } }