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;
            }
        }
示例#2
0
        static void DrawGizmoForHDAdditionalLightData(HDAdditionalLightData src, GizmoType gizmoType)
        {
            bool selected = (gizmoType & GizmoType.Selected) != 0;

            var light      = src.gameObject.GetComponent <Light>();
            var gizmoColor = light.color;

            gizmoColor.a = selected ? 1.0f : 0.3f; // Fade for the gizmo
            Gizmos.color = Handles.color = gizmoColor;

            if (src.lightTypeExtent == LightTypeExtent.Punctual)
            {
                switch (light.type)
                {
                case LightType.Directional:
                    CoreLightEditorUtilities.DrawDirectionalLightGizmo(light);
                    break;

                case LightType.Point:
                    CoreLightEditorUtilities.DrawPointlightGizmo(light, selected);
                    break;

                case LightType.Spot:
                    if (src.spotLightShape == SpotLightShape.Cone)
                    {
                        CoreLightEditorUtilities.DrawSpotlightGizmo(light, src.GetInnerSpotPercent01(), selected);
                    }
                    else if (src.spotLightShape == SpotLightShape.Pyramid)
                    {
                        HDLightEditorUtilities.DrawFrustumlightGizmo(light);
                    }
                    else if (src.spotLightShape == SpotLightShape.Box)
                    {
                        HDLightEditorUtilities.DrawFrustumlightGizmo(light);
                    }
                    break;
                }
            }
            else
            {
                switch (src.lightTypeExtent)
                {
                case LightTypeExtent.Rectangle:
                    CoreLightEditorUtilities.DrawArealightGizmo(light);
                    break;

                case LightTypeExtent.Line:
                    CoreLightEditorUtilities.DrawArealightGizmo(light);
                    break;
                }
            }

            if (selected)
            {
                // Trace a ray down to better locate the light location
                Ray        ray = new Ray(src.gameObject.transform.position, Vector3.down);
                RaycastHit hit;
                if (Physics.Raycast(ray, out hit))
                {
                    Handles.color = Color.green;
                    Handles.zTest = UnityEngine.Rendering.CompareFunction.LessEqual;
                    Handles.DrawLine(src.gameObject.transform.position, hit.point);
                    Handles.DrawWireDisc(hit.point, hit.normal, 0.5f);

                    Handles.color = Color.red;
                    Handles.zTest = UnityEngine.Rendering.CompareFunction.Greater;
                    Handles.DrawLine(src.gameObject.transform.position, hit.point);
                    Handles.DrawWireDisc(hit.point, hit.normal, 0.5f);
                }
            }
        }