public void SetPathNode(int index, Vector3 value) { Utility_Path path = Utility_Path.GetPath(pathName); path.Nodes[index] = value; SetPath(path); }
protected void SetPath(Utility_Path path) { Vector3[] nodes = path.Nodes; if (shouldDuplicate) { int duplicatedNodeCount = nodes.Length * duplicationMultiplier - duplicationMultiplier; Vector3[] duplicatedNodes = new Vector3[duplicatedNodeCount]; for (int i = 0; i < duplicatedNodes.Length; ++i) { if (i < nodes.Length) { duplicatedNodes[i] = nodes[i]; } else { int additionalNodeCount = nodes.Length - 1; // 2 int adjustedIndex = i - nodes.Length; // int scaleMultiplier = adjustedIndex / additionalNodeCount + 1; //leave here adjustedIndex %= additionalNodeCount; adjustedIndex++; Vector3 newPosition = duplicatedNodes[scaleMultiplier * additionalNodeCount] + Vector3.Scale(nodes[adjustedIndex], duplicationScaleVector); duplicatedNodes[i] = newPosition; // Debug.Log(string.Format("i[{0}] + node[{1}]",i.ToString(),duplicatedNodes[i].ToString())); } } nodes = duplicatedNodes; } Vector3[] vector3s = Utility.PathControlPointGenerator(nodes); int SmoothAmount = vector3s.Length * smoothMultiplier; this.pathLength = SmoothAmount; if (this.closedLoop) { this.resetIndex = this.pathLength; } else { this.resetIndex = this.pathLength - this.lookOffset; } this.smoothedPath = new Vector3[SmoothAmount]; for (int i = 0; i < SmoothAmount; i++) { float pm = (float)i / SmoothAmount; Vector3 currPt = Utility.Interp(vector3s, pm); this.smoothedPath [i] = currPt; } }
/////////////////////////////////////////////////////////////////////////// // // Inherited from MonoBehaviour // protected void Start() { Utility_Path path = Utility_Path.GetPath(pathName); if (this.lerpUpVector) { this.startUpVector = this.upVector; } if (this.pathName != null) { this.lastUpdateTime = Time.time; SetPath(path); if (playOnStart) { if (startDelay == 0) { StartMoving(); } else { Invoke("StartMoving", startDelay); } UpdatePosition(); } if (!playOnStart && setValueOnStart) { UpdatePosition(); } } else { Debug.Log("No Path Found"); } }