protected override void OnSceneGUI()
        {
            m_SerializedAdditionalLightData.Update();

            HDAdditionalLightData src = (HDAdditionalLightData)m_SerializedAdditionalLightData.targetObject;
            Light light = (Light)target;

            Color wireframeColorAbove  = light.enabled ? LightEditor.kGizmoLight : LightEditor.kGizmoDisabledLight;
            Color handleColorAbove     = CoreLightEditorUtilities.GetLightHandleColor(wireframeColorAbove);
            Color wireframeColorBehind = CoreLightEditorUtilities.GetLightBehindObjectWireframeColor(wireframeColorAbove);
            Color handleColorBehind    = CoreLightEditorUtilities.GetLightHandleColor(wireframeColorBehind);

            switch (src.lightTypeExtent)
            {
            case LightTypeExtent.Punctual:
                switch (light.type)
                {
                case LightType.Directional:
                case LightType.Point:
                    base.OnSceneGUI();          //use legacy handles
                    break;

                case LightType.Spot:
                    switch (src.spotLightShape)
                    {
                    case SpotLightShape.Cone:
                        CoreLightEditorUtilities.DrawSpotlightGizmo(light, src.GetInnerSpotPercent01(), true);
                        break;

                    case SpotLightShape.Pyramid:
                        using (new Handles.DrawingScope(Matrix4x4.TRS(light.transform.position, light.transform.rotation, Vector3.one)))
                        {
                            Vector4 aspectFovMaxRangeMinRange = new Vector4(src.aspectRatio, light.spotAngle, light.range);
                            Handles.zTest = UnityEngine.Rendering.CompareFunction.Greater;
                            Handles.color = wireframeColorBehind;
                            CoreLightEditorUtilities.DrawPyramidFrustumWireframe(aspectFovMaxRangeMinRange);
                            Handles.zTest = UnityEngine.Rendering.CompareFunction.LessEqual;
                            Handles.color = wireframeColorAbove;
                            CoreLightEditorUtilities.DrawPyramidFrustumWireframe(aspectFovMaxRangeMinRange);
                            EditorGUI.BeginChangeCheck();
                            Handles.zTest             = UnityEngine.Rendering.CompareFunction.Greater;
                            Handles.color             = handleColorBehind;
                            aspectFovMaxRangeMinRange = CoreLightEditorUtilities.DrawPyramidFrustumHandle(aspectFovMaxRangeMinRange, false);
                            Handles.zTest             = UnityEngine.Rendering.CompareFunction.LessEqual;
                            Handles.color             = handleColorAbove;
                            aspectFovMaxRangeMinRange = CoreLightEditorUtilities.DrawPyramidFrustumHandle(aspectFovMaxRangeMinRange, false);
                            if (EditorGUI.EndChangeCheck())
                            {
                                Undo.RecordObjects(new UnityEngine.Object[] { target, src }, "Adjust Pyramid Spot Light");
                                src.aspectRatio = aspectFovMaxRangeMinRange.x;
                                light.spotAngle = aspectFovMaxRangeMinRange.y;
                                light.range     = aspectFovMaxRangeMinRange.z;
                            }

                            // Handles.color reseted at end of scope
                        }
                        break;

                    case SpotLightShape.Box:
                        using (new Handles.DrawingScope(Matrix4x4.TRS(light.transform.position, light.transform.rotation, Vector3.one)))
                        {
                            Vector4 widthHeightMaxRangeMinRange = new Vector4(src.shapeWidth, src.shapeHeight, light.range);
                            Handles.zTest = UnityEngine.Rendering.CompareFunction.Greater;
                            Handles.color = wireframeColorBehind;
                            CoreLightEditorUtilities.DrawOrthoFrustumWireframe(widthHeightMaxRangeMinRange);
                            Handles.zTest = UnityEngine.Rendering.CompareFunction.LessEqual;
                            Handles.color = wireframeColorAbove;
                            CoreLightEditorUtilities.DrawOrthoFrustumWireframe(widthHeightMaxRangeMinRange);
                            EditorGUI.BeginChangeCheck();
                            Handles.zTest = UnityEngine.Rendering.CompareFunction.Greater;
                            Handles.color = handleColorBehind;
                            widthHeightMaxRangeMinRange = CoreLightEditorUtilities.DrawOrthoFrustumHandle(widthHeightMaxRangeMinRange, false);
                            Handles.zTest = UnityEngine.Rendering.CompareFunction.LessEqual;
                            Handles.color = handleColorAbove;
                            widthHeightMaxRangeMinRange = CoreLightEditorUtilities.DrawOrthoFrustumHandle(widthHeightMaxRangeMinRange, false);
                            if (EditorGUI.EndChangeCheck())
                            {
                                Undo.RecordObjects(new UnityEngine.Object[] { target, src }, "Adjust Box Spot Light");
                                src.shapeWidth  = widthHeightMaxRangeMinRange.x;
                                src.shapeHeight = widthHeightMaxRangeMinRange.y;
                                light.range     = widthHeightMaxRangeMinRange.z;
                            }

                            // Handles.color reseted at end of scope
                        }
                        break;
                    }
                    break;
                }
                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);
                }
            }
        }