Light2DShape.cs 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. namespace UnityEngine.Experimental.Rendering.Universal
  2. {
  3. sealed public partial class Light2D : MonoBehaviour
  4. {
  5. //------------------------------------------------------------------------------------------
  6. // Variables/Properties
  7. //------------------------------------------------------------------------------------------
  8. [SerializeField] int m_ShapeLightParametricSides = 5;
  9. [SerializeField] float m_ShapeLightParametricAngleOffset = 0.0f;
  10. [SerializeField] float m_ShapeLightParametricRadius = 1.0f;
  11. [SerializeField] float m_ShapeLightFalloffSize = 0.50f;
  12. [SerializeField] Vector2 m_ShapeLightFalloffOffset = Vector2.zero;
  13. [SerializeField] Vector3[] m_ShapePath = null;
  14. float m_PreviousShapeLightFalloffSize = -1;
  15. int m_PreviousShapeLightParametricSides = -1;
  16. float m_PreviousShapeLightParametricAngleOffset = -1;
  17. float m_PreviousShapeLightParametricRadius = -1;
  18. Vector2 m_PreviousShapeLightFalloffOffset = Vector2.negativeInfinity;
  19. #if UNITY_EDITOR
  20. int m_PreviousShapePathHash = -1;
  21. #endif
  22. public int shapeLightParametricSides => m_ShapeLightParametricSides;
  23. public float shapeLightParametricAngleOffset => m_ShapeLightParametricAngleOffset;
  24. public float shapeLightParametricRadius => m_ShapeLightParametricRadius;
  25. public float shapeLightFalloffSize => m_ShapeLightFalloffSize;
  26. public Vector2 shapeLightFalloffOffset => m_ShapeLightFalloffOffset;
  27. public Vector3[] shapePath => m_ShapePath;
  28. //==========================================================================================
  29. // Functions
  30. //==========================================================================================
  31. internal bool IsShapeLight()
  32. {
  33. return m_LightType != LightType.Point;
  34. }
  35. BoundingSphere GetShapeLightBoundingSphere()
  36. {
  37. BoundingSphere boundingSphere;
  38. Vector3 maxBound = Vector3.Max(m_LocalBounds.max, m_LocalBounds.max + (Vector3)m_ShapeLightFalloffOffset);
  39. Vector3 minBound = Vector3.Min(m_LocalBounds.min, m_LocalBounds.min + (Vector3)m_ShapeLightFalloffOffset);
  40. Vector3 maximum = transform.TransformPoint(maxBound);
  41. Vector3 minimum = transform.TransformPoint(minBound);
  42. Vector3 center = 0.5f * (maximum + minimum);
  43. float radius = Vector3.Magnitude(maximum - center);
  44. boundingSphere.radius = radius;
  45. boundingSphere.position = center;
  46. return boundingSphere;
  47. }
  48. }
  49. }