void OnDrawGizmos() { if (!this.drawTrail || this.trailDetailLevel == 0 || !this.drawTrailGizmos) { return; } if (this.waypointData != null && Event.current.type == EventType.Repaint) { Gizmos.color = this.trailColor; for (int i = 0; i < this.waypointData.length; i++) { if (i == this.waypointData.length - 1) { if (this.completeTrail) { WaypointUtility.DrawCurve(this.TransformPoint(this.waypointData[i + 0]), this.TransformPoint(this.waypointData[0 + 0]), this.trailDetailLevel, Gizmos.DrawLine); } } else { WaypointUtility.DrawCurve(this.TransformPoint(this.waypointData[i + 0]), this.TransformPoint(this.waypointData[i + 1]), this.trailDetailLevel, Gizmos.DrawLine); } } Gizmos.color = Color.white; } }
private Vector3 GetPosition(float factor, bool loop) { int len = loop ? this.waypointData.length : this.waypointData.length - 1; int i0 = this.NormalizeIndex(Mathf.FloorToInt(factor * len), loop); int i1 = this.NormalizeIndex(i0 + 1, loop); //This is like: (currentIndexPoint - lastIndexPoint) / (nextIndexPoint - lastIndexPoint) //currentIndexPoint = factor * lengthWaypoint //lastIndexPoint = floor(factor * lengthWaypoint) //nextIndexPoint = lastIndexPoint + 1 float time = (factor * len) % 1; Point p0 = this.TransformPoint(this.waypointData [i0]); Point p1 = this.TransformPoint(this.waypointData [i1]); Vector3 tan0 = p0.position + (p0.uniqueTangent ? p0.tangent : p0.tangentR); Vector3 tan1 = p1.position + (p1.uniqueTangent ? -p1.tangent : p1.tangentL); return(WaypointUtility.CubicBezier(p0.position, tan0, tan1, p1.position, time)); }
/// <summary> /// Draws the bezier curve /// </summary> /// <param name="pointA">Point a.</param> /// <param name="pointB">Point b.</param> /// <param name="detail">Level Detail of Curve</param> /// <param name="drawLine">Function to Draw the Curve</param> public static void DrawCurve(Point pointA, Point pointB, int detail, DrawLine drawLine) { //float dis = Mathf.Clamp((pointB.position - pointA.position).magnitude, 0.5f, 1); Vector3 tan0 = pointA.position + (pointA.uniqueTangent ? pointA.tangent : pointA.tangentR); Vector3 tan1 = pointB.position + (pointB.uniqueTangent ? -pointB.tangent : pointB.tangentL); if (tan0 == pointA.position && tan1 == pointB.position) { drawLine(pointA.position, pointB.position); } else { int max = Mathf.RoundToInt(detail /** dis*/); Vector3 lpos = pointA.position; for (int i = 1; i < max + 1; i++) { float step = (float)i / (max); Vector3 npos = WaypointUtility.CubicBezier(pointA.position, tan0, tan1, pointB.position, step); drawLine(lpos, npos); lpos = npos; } } }