2021-01-03 12:38:02 +00:00
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
namespace Popcron
|
|
|
|
|
{
|
2021-01-04 17:31:58 +00:00
|
|
|
|
public class PolygonDrawer : Drawer
|
|
|
|
|
{
|
2021-01-03 12:38:02 +00:00
|
|
|
|
public PolygonDrawer()
|
|
|
|
|
{
|
2021-01-04 17:31:58 +00:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override int Draw(ref Vector3[] buffer, params object[] values)
|
|
|
|
|
{
|
2021-01-05 15:58:12 +00:00
|
|
|
|
var position = (Vector3)values[0];
|
|
|
|
|
var points = (int)values[1];
|
|
|
|
|
var radius = (float)values[2];
|
|
|
|
|
var offset = (float)values[3];
|
|
|
|
|
var rotation = (Quaternion)values[4];
|
2021-01-04 17:31:58 +00:00
|
|
|
|
|
2021-01-05 15:58:12 +00:00
|
|
|
|
var step = 360f / points;
|
2021-01-04 17:31:58 +00:00
|
|
|
|
offset *= Mathf.Deg2Rad;
|
|
|
|
|
|
2021-01-05 15:58:12 +00:00
|
|
|
|
for (var i = 0; i < points; i++)
|
2021-01-04 17:31:58 +00:00
|
|
|
|
{
|
2021-01-05 15:58:12 +00:00
|
|
|
|
var cx = Mathf.Cos(Mathf.Deg2Rad * step * i + offset) * radius;
|
|
|
|
|
var cy = Mathf.Sin(Mathf.Deg2Rad * step * i + offset) * radius;
|
|
|
|
|
var current = new Vector3(cx, cy);
|
2021-01-04 17:31:58 +00:00
|
|
|
|
|
2021-01-05 15:58:12 +00:00
|
|
|
|
var nx = Mathf.Cos(Mathf.Deg2Rad * step * (i + 1) + offset) * radius;
|
|
|
|
|
var ny = Mathf.Sin(Mathf.Deg2Rad * step * (i + 1) + offset) * radius;
|
|
|
|
|
var next = new Vector3(nx, ny);
|
2021-01-04 17:31:58 +00:00
|
|
|
|
|
|
|
|
|
buffer[i * 2] = position + (rotation * current);
|
|
|
|
|
buffer[(i * 2) + 1] = position + (rotation * next);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return points * 2;
|
2021-01-03 12:38:02 +00:00
|
|
|
|
}
|
2021-01-04 17:31:58 +00:00
|
|
|
|
}
|
2021-01-03 12:38:02 +00:00
|
|
|
|
}
|