public BezierPoint3D AddKeyPointAt(int index)
{
BezierPoint3D newPoint = new GameObject("Point " + this.KeyPoints.Count, typeof(BezierPoint3D)).GetComponent<BezierPoint3D>();
newPoint.Curve = this;
newPoint.transform.parent = this.transform;
newPoint.transform.localRotation = Quaternion.identity;
if (this.KeyPointsCount == 0 || this.KeyPointsCount == 1)
{
newPoint.LocalPosition = Vector3.zero;
}
else
{
if (index == 0)
{
newPoint.Position = (this.KeyPoints[0].Position - this.KeyPoints[1].Position).normalized + this.KeyPoints[0].Position;
}
else if (index == this.KeyPointsCount)
{
newPoint.Position = (this.KeyPoints[index - 1].Position - this.KeyPoints[index - 2].Position).normalized + this.KeyPoints[index - 1].Position;
}
else
{
newPoint.Position = BezierCurve3D.GetPointOnCubicCurve(0.5f, this.KeyPoints[index - 1], this.KeyPoints[index]);
}
}
this.KeyPoints.Insert(index, newPoint);
return newPoint;
}