1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- using UnityEngine;
- using UnityEngine.Rendering;
- using UnityEngine.Rendering.Universal;
- namespace UnityEditor.Rendering.Universal
- {
- [CanEditMultipleObjects]
- [CustomEditorForRenderPipeline(typeof(Light), typeof(UniversalRenderPipelineAsset))]
- class UniversalRenderPipelineLightEditor : LightEditor
- {
- UniversalRenderPipelineSerializedLight serializedLight { get; set; }
- protected override void OnEnable()
- {
- serializedLight = new UniversalRenderPipelineSerializedLight(serializedObject, settings);
- }
- // 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;
- }
- }
- }
- }
|