123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- using System;
- using UnityEngine;
- using UnityEngine.Rendering;
- using UnityEngine.Rendering.Universal;
-
- namespace UnityEditor.Rendering.Universal
- {
- [CustomEditor(typeof(Light))]
- [SupportedOnRenderPipeline(typeof(UniversalRenderPipelineAsset))]
- [CanEditMultipleObjects]
- class UniversalRenderPipelineLightEditor : LightEditor
- {
- UniversalRenderPipelineSerializedLight serializedLight { get; set; }
-
- protected override void OnEnable()
- {
- serializedLight = new UniversalRenderPipelineSerializedLight(serializedObject, settings);
- Undo.undoRedoPerformed += ReconstructReferenceToAdditionalDataSO;
- }
-
- internal void ReconstructReferenceToAdditionalDataSO()
- {
- OnDisable();
- OnEnable();
- }
-
- protected void OnDisable()
- {
- Undo.undoRedoPerformed -= ReconstructReferenceToAdditionalDataSO;
- }
-
- // IsPreset is an internal API - lets reuse the usable part of this function
- // 93 is a "magic number" and does not represent a combination of other flags here
- internal static bool IsPresetEditor(UnityEditor.Editor editor)
- {
- return (int)((editor.target as Component).gameObject.hideFlags) == 93;
- }
-
- public override void OnInspectorGUI()
- {
- serializedLight.Update();
-
- if (IsPresetEditor(this))
- {
- UniversalRenderPipelineLightUI.PresetInspector.Draw(serializedLight, this);
- }
- else
- {
- UniversalRenderPipelineLightUI.Inspector.Draw(serializedLight, this);
- }
-
- serializedLight.Apply();
- }
-
- protected override void OnSceneGUI()
- {
- if (!(GraphicsSettings.currentRenderPipeline is UniversalRenderPipelineAsset))
- return;
-
- if (!(target is Light light) || light == null)
- return;
-
- switch (light.type)
- {
- case LightType.Spot:
- using (new Handles.DrawingScope(Matrix4x4.TRS(light.transform.position, light.transform.rotation, Vector3.one)))
- {
- CoreLightEditorUtilities.DrawSpotLightGizmo(light);
- }
- break;
-
- case LightType.Point:
- using (new Handles.DrawingScope(Matrix4x4.TRS(light.transform.position, Quaternion.identity, Vector3.one)))
- {
- CoreLightEditorUtilities.DrawPointLightGizmo(light);
- }
- break;
-
- case LightType.Rectangle:
- using (new Handles.DrawingScope(Matrix4x4.TRS(light.transform.position, light.transform.rotation, Vector3.one)))
- {
- CoreLightEditorUtilities.DrawRectangleLightGizmo(light);
- }
- break;
-
- case LightType.Disc:
- using (new Handles.DrawingScope(Matrix4x4.TRS(light.transform.position, light.transform.rotation, Vector3.one)))
- {
- CoreLightEditorUtilities.DrawDiscLightGizmo(light);
- }
- break;
-
- case LightType.Directional:
- using (new Handles.DrawingScope(Matrix4x4.TRS(light.transform.position, light.transform.rotation, Vector3.one)))
- {
- CoreLightEditorUtilities.DrawDirectionalLightGizmo(light);
- }
- break;
-
- default:
- base.OnSceneGUI();
- break;
- }
- }
- }
- }
|