Ingen beskrivning
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

UniversalRenderPipelineLightEditor.cs 3.7KB

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