ShadowCaster2DShapeTool.cs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. using UnityEditor.Rendering.Universal.Path2D;
  2. using UnityEngine;
  3. using UnityEngine.Rendering.Universal;
  4. namespace UnityEditor.Rendering.Universal
  5. {
  6. class ShadowCaster2DShapeTool : PathEditorTool<ShadowCasterPath>
  7. {
  8. const string k_ShapePath = "m_ShapePath";
  9. protected override IShape GetShape(Object target)
  10. {
  11. return (target as ShadowCaster2D).shapePath.ToPolygon(false);
  12. }
  13. protected override void SetShape(ShadowCasterPath shapeEditor, SerializedObject serializedObject)
  14. {
  15. serializedObject.Update();
  16. var pointsProperty = serializedObject.FindProperty(k_ShapePath);
  17. pointsProperty.arraySize = shapeEditor.pointCount;
  18. for (var i = 0; i < shapeEditor.pointCount; ++i)
  19. pointsProperty.GetArrayElementAtIndex(i).vector3Value = shapeEditor.GetPoint(i).position;
  20. // This is untracked right now...
  21. serializedObject.ApplyModifiedProperties();
  22. ShadowCaster2D shadowCaster = target as ShadowCaster2D;
  23. if (shadowCaster != null)
  24. {
  25. int hash = LightUtility.GetShapePathHash(shadowCaster.shapePath);
  26. shadowCaster.shapePathHash = hash;
  27. }
  28. }
  29. }
  30. }