// 提供外部调用的方法 パブリック 静的するVector3 [] GetCurveData(のVector3 []のパス) { するVector3 [] vector3s = PathControlPointGenerator(パス)。 // 線画: のVector3 prevPt = INTERP(vector3s、0 ); int型 SmoothAmount = path.Length * 20 。 するVector3 [] finall = 新規のVector3 [SmoothAmount + 1 ]。 以下のために(int型 I = 1 ; I <= SmoothAmount; iは++ ) { フロート PM =(フロート)I / SmoothAmount。 Vector3 currPt = INTERP(vector3s、午後)。 finall [I] = currPt。 } 戻りfinall。 } // NGUI iTween.cs中方法、输入的路径点 パブリック 静的するVector3 [] PathControlPointGenerator(のVector3 []のパス) { するVector3 [] suppliedPath。 するVector3 [] vector3s。 // 作成し、ストア・パスポイント: suppliedPath = パス。 // 計算パスを読み込みます。 int型 =オフセット2 。 vector3s = 新しいのVector3 [suppliedPath.Length +オフセット]; Array.Copy(suppliedPath、0、vector3s、1 、suppliedPath.Length)。 // 開始および終了制御点移入: vector3s [ 0 ] = vector3s [ 1 ] +(vector3s [ 1 ] - vector3s [ 2 ])。 vector3s [vector3s.Length - 1 ] = vector3s [vector3s.Length - 2 ] +(vector3s [vector3s.Length - 2 ] - vector3s [vector3s.Length - 3 ])。 // これは、閉じた、連続ループのですか?はい?さてそれでは、連続キャットマル-Romのスプラインを作ってみよう! もし(vector3s [ 1] == vector3s [vector3s.Length - 2 ]) { するVector3 [] tmpLoopSpline = 新規のVector3 [vector3s.Length]。 Array.Copy(vector3s、tmpLoopSpline、vector3s.Length)。 tmpLoopSpline [ 0 ] = tmpLoopSpline [tmpLoopSpline.Length - 3 ]。 tmpLoopSpline [tmpLoopSpline.Length - 1 ] = tmpLoopSpline [ 2 ]。 vector3s = 新しいのVector3 [tmpLoopSpline.Length]。 Array.Copy(tmpLoopSpline、vector3s、tmpLoopSpline.Length)。 } リターン(vector3s)。 } //曲线插值函数 パブリック 静的するVector3 INTERP(のVector3 []、PTS、フロートT) { int型 numSections = pts.Length - 3 。 INT currPt = Mathf.Min(Mathf.FloorToInt(T *(フロート)numSections)、numSections - 1 )。 フロート Uは、T *(= フロート)numSections - (フロート)currPtと、 するVector3 =のPTS [currPt]。 するVector3 B = PTS [currPt + 1 ]。 するVector3 C = PTS [currPt + 2 ]。 Vector3 D = PTS [currPt +3 ]。 戻り .5f * ( ( -a + 3F * B - 3F * C + D)*(uは* Uは* U)を +(2Fの*のA - 5F * B + 4F * C - D)*(uは* U)を + (-A + C)* U + 2F * B )。 }
itweenダウンロードを添付:
リンク:https://pan.baidu.com/s/1aikpm9eQsfGGIPHR9K7eIA
抽出コード:msg6