ベジェ曲線によって編集されました

使用にSystem.Collectionsを。
使用してSystem.Collections.Genericを。
使用してUnityEngineを。
使用してDG.Tweeningを。


// [ExecuteInEditMode] 
パブリック クラスにSPS:MonoBehaviour 
{ 
    パブリックゲームオブジェクトrootPoint。
    国民は、トランス変換します。
    公共LineRenderer lineRenderer。
    プライベート 静的SPSのインスタンス。
    // 初期化のために使用し、これを
    パブリック 静的にSPSでGetInstance()
    { 
        戻りインスタンス。
    } 

    パブリックBezierPathModel BezierPath; 

    プライベート ボイドアウェイク()
    { 
        インスタンス = この; 
      
    } 

    ボイド開始()
    { 
        場合(!lineRenderer)
        { 
            lineRenderer = gameObject.AddComponent <LineRenderer> (); 
        } 
        { 
            lineRenderer = gameObject.GetComponent <LineRenderer> (); 
        } 
        InitPath()。
        DrawCurve(BezierPath.PathTrans)。

        // trans.DOPath(BezierPath.PathTrans、10)。
      //  trans.DOPath(BezierPath.PathTrans、15、PathType.Linear、PathMode.Full3D)。
       // rootPoint.DOPath(BezierPath.PathTrans、15、PathType.Linear、PathMode.Full3D)。
    } 

    公共 ボイド更新()
    { 
       
    } 

    ボイド DrawCurve(リスト<のVector3> POS)
    { 
        lineRenderer.positionCount = pos.Count。
        以下のためにINT iが= 0 ; I <pos.Count; I ++ 
        { 
            //    フロートT = I /(フロート)pos.Count。
            // int型nodeIndex = 0;
           // DEBUG.LOG( "I" + I)。
            ピクセル=のVector3 POS [I];
             // lineRenderer.positionCount = I; 
            lineRenderer.SetPosition(I、ピクセル); 
        } 
    } 

    公共 ボイドInitPath()
    { 
        BezierPath.PathTrans = 計算(BezierPath.ControlTrans、BezierPath.segmentNum); 

    } 

    公共リスト<のVector3>計算(リスト<変形> POSS、整数精度)
    { 

        // 寸法は(...二次元座標を三次元座標)を座標データ軸
        INT dimersion = 2 ; 

        // ベジエ制御点(順)
        INT番号= poss.Count; 

        //制御点2以上ではない、少なくとも二次元の座標系
        IF(数< 2 || dimersion < 2 リターン NULL ; 

        リスト <のVector3>結果= 新しい新しいリスト<のVector3> (); 

        // 計算パスカルの三角形の
        INT [] = miザ新しい新しい INT [番号]; 
        miザ[ 0 ] = miザ[ 1 ] = 1 ;
         のためのINT I = 3 ; I <=数; I ++ 
        { 

            int型 [] T = 新しい新しい INT [I - 1 ]。
            INT J = 0 ; J <t.Length; J ++ 
            { 
                T [j] = MI [J]。
            } 

            MI [ 0 ] = MI [I - 1 ] = 1 int型 J = 0 - ; J <I 2、J ++ 
            { 
                MI [J + 1 ] = T [J] + T [j + 1 ]。
            } 
        } 

        // 计算坐标点
        INT I = 0; I <精度。I ++ 
        { 
            フロート T =(フロート)I / 精密。
            するVector3 temp_ = 新規のVector3(000 );
            int型のk = 0 ; K <数; K ++ 
            { 
                temp_.x + = Mathf.Pow(1 - T、数- K - 1)* POSS [K] .position.x * Mathf.Pow(T、K )* MI [K]。
                temp_.y + = Mathf.Pow(1 - T、数- K - 1)* Mathf.Pow(T、K).position.y POSS [K] * MI [K]。
                temp_.z + = Mathf.Pow(1 - T、数- K - 1)* POSS [K] .position.z * Mathf.Pow(T、K)* MI [K]。
            } 

            result.Add(temp_)。
        } 
        戻り値の結果; 
    } 

    パブリックリスト<のVector3> ReturnPath(int型のID)
    { 
        戻りBezierPath.PathTrans。
    } 
} 

[System.Serializable] 
パブリック クラスBezierPathModel 
{ 
    パブリックリスト<変形> ControlTrans。
    公共 のintsegmentNum;
    公共の一覧<のVector3> PathTrans。

}

 

おすすめ

転載: www.cnblogs.com/Mr147/p/12376852.html
おすすめ