UniversalRenderPipelineLightEditor.cs 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. using UnityEngine;
  2. using UnityEngine.Rendering;
  3. using UnityEngine.Rendering.Universal;
  4. namespace UnityEditor.Rendering.Universal
  5. {
  6. [CanEditMultipleObjects]
  7. [CustomEditorForRenderPipeline(typeof(Light), typeof(UniversalRenderPipelineAsset))]
  8. class UniversalRenderPipelineLightEditor : LightEditor
  9. {
  10. UniversalRenderPipelineSerializedLight serializedLight { get; set; }
  11. protected override void OnEnable()
  12. {
  13. serializedLight = new UniversalRenderPipelineSerializedLight(serializedObject, settings);
  14. }
  15. // IsPreset is an internal API - lets reuse the usable part of this function
  16. // 93 is a "magic number" and does not represent a combination of other flags here
  17. internal static bool IsPresetEditor(UnityEditor.Editor editor)
  18. {
  19. return (int)((editor.target as Component).gameObject.hideFlags) == 93;
  20. }
  21. public override void OnInspectorGUI()
  22. {
  23. serializedLight.Update();
  24. if (IsPresetEditor(this))
  25. {
  26. UniversalRenderPipelineLightUI.PresetInspector.Draw(serializedLight, this);
  27. }
  28. else
  29. {
  30. UniversalRenderPipelineLightUI.Inspector.Draw(serializedLight, this);
  31. }
  32. serializedLight.Apply();
  33. }
  34. protected override void OnSceneGUI()
  35. {
  36. if (!(GraphicsSettings.currentRenderPipeline is UniversalRenderPipelineAsset))
  37. return;
  38. if (!(target is Light light) || light == null)
  39. return;
  40. switch (light.type)
  41. {
  42. case LightType.Spot:
  43. using (new Handles.DrawingScope(Matrix4x4.TRS(light.transform.position, light.transform.rotation, Vector3.one)))
  44. {
  45. CoreLightEditorUtilities.DrawSpotLightGizmo(light);
  46. }
  47. break;
  48. case LightType.Point:
  49. using (new Handles.DrawingScope(Matrix4x4.TRS(light.transform.position, Quaternion.identity, Vector3.one)))
  50. {
  51. CoreLightEditorUtilities.DrawPointLightGizmo(light);
  52. }
  53. break;
  54. case LightType.Rectangle:
  55. using (new Handles.DrawingScope(Matrix4x4.TRS(light.transform.position, light.transform.rotation, Vector3.one)))
  56. {
  57. CoreLightEditorUtilities.DrawRectangleLightGizmo(light);
  58. }
  59. break;
  60. case LightType.Disc:
  61. using (new Handles.DrawingScope(Matrix4x4.TRS(light.transform.position, light.transform.rotation, Vector3.one)))
  62. {
  63. CoreLightEditorUtilities.DrawDiscLightGizmo(light);
  64. }
  65. break;
  66. case LightType.Directional:
  67. using (new Handles.DrawingScope(Matrix4x4.TRS(light.transform.position, light.transform.rotation, Vector3.one)))
  68. {
  69. CoreLightEditorUtilities.DrawDirectionalLightGizmo(light);
  70. }
  71. break;
  72. default:
  73. base.OnSceneGUI();
  74. break;
  75. }
  76. }
  77. }
  78. }