PolygonDrawer.cs 1.2 KB

1234567891011121314151617181920212223242526272829303132333435
  1. using UnityEngine;
  2. namespace Popcron
  3. {
  4. public class PolygonDrawer : Drawer
  5. {
  6. public override int Draw(ref Vector3[] buffer, params object[] values)
  7. {
  8. Vector3 position = (Vector3)values[0];
  9. int points = (int)values[1];
  10. float radius = (float)values[2];
  11. float offset = (float)values[3];
  12. Quaternion rotation = (Quaternion)values[4];
  13. float step = 360f / points;
  14. offset *= Mathf.Deg2Rad;
  15. for (int i = 0; i < points; i++)
  16. {
  17. float cx = Mathf.Cos(Mathf.Deg2Rad * step * i + offset) * radius;
  18. float cy = Mathf.Sin(Mathf.Deg2Rad * step * i + offset) * radius;
  19. Vector3 current = new Vector3(cx, cy);
  20. float nx = Mathf.Cos(Mathf.Deg2Rad * step * (i + 1) + offset) * radius;
  21. float ny = Mathf.Sin(Mathf.Deg2Rad * step * (i + 1) + offset) * radius;
  22. Vector3 next = new Vector3(nx, ny);
  23. buffer[i * 2] = position + (rotation * current);
  24. buffer[(i * 2) + 1] = position + (rotation * next);
  25. }
  26. return points * 2;
  27. }
  28. }
  29. }