ShadowCaster2DShapeTool.cs 1.3 KB

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