/// <summary> /// Stop this instance ans sets <see cref="currentPos"/> to 0. /// </summary> public void Stop() { if (pathMagic.waypoints.Length == 0) { return; } isPlaying = false; currentPos = 0f; UpdateTarget(pathMagic.computePositionAtPos(currentPos), pathMagic.computeRotationAtPos(currentPos)); }
/// <summary> /// Gets the position for position whether the path is pre-sampled or not. /// </summary> /// <returns>The position for position.</returns> /// <param name="pos">Position.</param> private Vector3 GetPositionForPos(float pos) { Vector3 position = Vector3.zero; Quaternion rotation = Quaternion.identity; if (pos < 0) { if (connectedPath.loop) { pos = 1 + pos; } else { pos = 0; } } float velocity = 1.0f; int waypoint = 0; if (connectedPath.presampledPath) { connectedPath.sampledPositionAndRotationAndVelocityAndWaypointAtPos(pos, out position, out rotation, out velocity, out waypoint); } else { position = connectedPath.computePositionAtPos(pos); } return(connectedPath.transform.TransformPoint(position)); }
public void Generate() { if (count < 0) { count = 0; } List <GameObject> elements = new List <GameObject> (); for (int i = 0; i < count; i++) { if (i < transform.childCount) { elements.Insert(i, transform.GetChild(i).gameObject); } else { elements.Insert(i, Instantiate(target)); elements [i].transform.parent = transform; elements [i].transform.localScale = new Vector3(1, 1, 1); } } if (elements.Count < transform.childCount) { for (int i = transform.childCount - 1; i >= elements.Count; i--) { DestroyImmediate(transform.GetChild(i).gameObject); } } for (int i = 0; i < elements.Count; i++) { float pos = startingFrom + (float)(1f / count * i) * (endTo - startingFrom); Vector3 position; Quaternion rotation; if (path.PresampledPath) { float velocity; int waypoint; path.sampledPositionAndRotationAndVelocityAndWaypointAtPos( pos, out position, out rotation, out velocity, out waypoint); } else { position = path.computePositionAtPos(pos); rotation = path.computeRotationAtPos(pos); } elements [i].transform.position = path.transform.TransformPoint( position ); elements [i].transform.rotation = transform.rotation * rotation; } }