public static void GetDotweenCurvePath(ref List<Vector3> countPaths,List<Vector3> anchors, int smoothyBetweenPoints)
{
Vector3[] curveAnchors = null; //实际计算的路径点
int PointCount = 10; //路径点的数量
PointCount = anchors.Count > 2 ?anchors.Count * smoothyBetweenPoints :anchors.Count;
if (anchors.Count > 1) //如果路径点大于一个
{
curveAnchors = new Vector3[anchors.Count + 2];//实际路径点的数量是
curveAnchors[0] = anchors[0] + anchors[0] - anchors[1];//第一个点往前一点
curveAnchors[anchors.Count + 1] = anchors[anchors.Count - 1] + anchors[anchors.Count - 1] - anchors[anchors.Count - 2];//最后一个点也往前一点
for (var i = 0; i < anchors.Count; i++) {
curveAnchors[i + 1] = anchors[i];
}
}
countPaths.Clear();
for (int index = 0; index < PointCount; index++) {
Vector3 point;
if (index < 0) index = 0;
if (anchors.Count < 1)
{
point = Vector3.zero;
}
else if (anchors.Count < 3)
{
index %= anchors.Count;
point = anchors[index];
}
else
{
int totalCount = anchors.Count * smoothyBetweenPoints;
index %= totalCount;
if (curveAnchors == null)
{
PointCount = anchors.Count > 2 ?anchors.Count * smoothyBetweenPoints :anchors.Count;
if (anchors.Count > 1) //如果路径点大于一个
{
curveAnchors = new Vector3[anchors.Count + 2];
curveAnchors[0] = anchors[0] + anchors[0] - anchors[1];
curveAnchors[anchors.Count + 1] = anchors[anchors.Count - 1] + anchors[anchors.Count - 1] - anchors[anchors.Count - 2];
for (int i = 0; i < anchors.Count; i++) {
curveAnchors[i + 1] = anchors[i];
}
}
}
int numSections = curveAnchors.Length - 3;
int currPt = Mathf.Min(Mathf.FloorToInt(1.0f * index / totalCount * (float) numSections), numSections - 1);
float u = 1.0f * index / totalCount * (float) numSections - (float) currPt;
Vector3 p0 = curveAnchors[currPt];
Vector3 p1 = curveAnchors[currPt + 1];
Vector3 p2 = curveAnchors[currPt + 2];
Vector3 p3 = curveAnchors[currPt + 3];
point = 0.5f * ((-p0 + 3f * p1 - 3f * p2 + p3) * (u * u * u) + (2f * p0 - 5f * p1 + 4f * p2 - p3) * (u * u) + (-p0 + p2) * u + 2f * p1);
}
countPaths.Add(point);
}
countPaths.Add(anchors[anchors.Count-1]);
}