SceneViewDrawMode.cs 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #if UNITY_EDITOR
  2. using System.Collections.Generic;
  3. using System.Collections;
  4. namespace UnityEditor.Rendering.Universal
  5. {
  6. internal static class SceneViewDrawMode
  7. {
  8. static HashSet<SceneView> sceneViewHaveValidateFunction = new HashSet<SceneView>();
  9. static bool RejectDrawMode(SceneView.CameraMode cameraMode)
  10. {
  11. if (cameraMode.drawMode == DrawCameraMode.ShadowCascades ||
  12. cameraMode.drawMode == DrawCameraMode.RenderPaths ||
  13. cameraMode.drawMode == DrawCameraMode.AlphaChannel ||
  14. cameraMode.drawMode == DrawCameraMode.Overdraw ||
  15. cameraMode.drawMode == DrawCameraMode.Mipmaps ||
  16. cameraMode.drawMode == DrawCameraMode.SpriteMask ||
  17. cameraMode.drawMode == DrawCameraMode.DeferredDiffuse ||
  18. cameraMode.drawMode == DrawCameraMode.DeferredSpecular ||
  19. cameraMode.drawMode == DrawCameraMode.DeferredSmoothness ||
  20. cameraMode.drawMode == DrawCameraMode.DeferredNormal ||
  21. cameraMode.drawMode == DrawCameraMode.ValidateAlbedo ||
  22. cameraMode.drawMode == DrawCameraMode.ValidateMetalSpecular ||
  23. cameraMode.drawMode == DrawCameraMode.TextureStreaming
  24. )
  25. return false;
  26. return true;
  27. }
  28. static void UpdateSceneViewStates()
  29. {
  30. foreach (SceneView sceneView in SceneView.sceneViews)
  31. {
  32. if (sceneViewHaveValidateFunction.Contains(sceneView))
  33. continue;
  34. sceneView.onValidateCameraMode += RejectDrawMode;
  35. sceneViewHaveValidateFunction.Add(sceneView);
  36. }
  37. }
  38. public static void SetupDrawMode()
  39. {
  40. EditorApplication.update -= UpdateSceneViewStates;
  41. EditorApplication.update += UpdateSceneViewStates;
  42. }
  43. public static void ResetDrawMode()
  44. {
  45. EditorApplication.update -= UpdateSceneViewStates;
  46. foreach (var sceneView in sceneViewHaveValidateFunction)
  47. sceneView.onValidateCameraMode -= RejectDrawMode;
  48. sceneViewHaveValidateFunction.Clear();
  49. }
  50. }
  51. }
  52. #endif