void GenerateMoveToPathTargets()
{
Vector3[] suppliedPath;
//create and store path points:
if(tweenArguments["path"].GetType() == typeof(Vector3[])){
Vector3[] temp = (Vector3[])tweenArguments["path"];
//if only one point is supplied fall back to MoveTo's traditional use since we can't have a curve with one value:
if(temp.Length==1){
Debug.LogError("iTween Error: Attempting a path movement with MoveTo requires an array of more than 1 entry!");
Dispose();
}
suppliedPath=new Vector3[temp.Length];
Array.Copy(temp,suppliedPath, temp.Length);
}else{
Transform[] temp = (Transform[])tweenArguments["path"];
//if only one point is supplied fall back to MoveTo's traditional use since we can't have a curve with one value:
if(temp.Length==1){
Debug.LogError("iTween Error: Attempting a path movement with MoveTo requires an array of more than 1 entry!");
Dispose();
}
suppliedPath = new Vector3[temp.Length];
for (int i = 0; i < temp.Length; i++) {
suppliedPath[i]=temp[i].position;
}
}
//do we need to plot a path to get to the beginning of the supplied path?
bool plotStart;
int offset;
if(transform.position != suppliedPath[0]){
if(!tweenArguments.Contains("movetopath") || (bool)tweenArguments["movetopath"]==true){
plotStart=true;
offset=3;
}else{
plotStart=false;
offset=2;
}
}else{
plotStart=false;
offset=2;
}
//build calculated path:
vector3s = new Vector3[suppliedPath.Length+offset];
if(plotStart){
vector3s[1]=transform.position;
offset=2;
}else{
offset=1;
}
//populate calculate path;
Array.Copy(suppliedPath,0,vector3s,offset,suppliedPath.Length);
//populate start and end control points:
//vector3s[0] = vector3s[1] - vector3s[2];
vector3s[0] = vector3s[1] + (vector3s[1] - vector3s[2]);
vector3s[vector3s.Length-1] = vector3s[vector3s.Length-2] + (vector3s[vector3s.Length-2] - vector3s[vector3s.Length-3]);
//is this a closed, continuous loop? yes? well then so let's make a continuous Catmull-Rom spline!
if(vector3s[1] == vector3s[vector3s.Length-2]){
Vector3[] tmpLoopSpline = new Vector3[vector3s.Length];
Array.Copy(vector3s,tmpLoopSpline,vector3s.Length);
tmpLoopSpline[0]=tmpLoopSpline[tmpLoopSpline.Length-3];
tmpLoopSpline[tmpLoopSpline.Length-1]=tmpLoopSpline[2];
vector3s=new Vector3[tmpLoopSpline.Length];
Array.Copy(tmpLoopSpline,vector3s,tmpLoopSpline.Length);
}
//create Catmull-Rom path:
path = new CRSpline(vector3s);
//need for speed?
if(tweenArguments.Contains("speed")){
float distance = PathLength(vector3s);
time = distance/(float)tweenArguments["speed"];
}
}