[Unity插件]DOTween(3)

DOTween是一個快速,高效,完全統一的類型安全的對象屬性動畫引擎,免費開源,大量的高級特性.
DoTween兼容Unity4.5以上的版本,支持的平臺: Win, Mac, Unity WebPlayer, WebGL, iOSAndroid,Windows Phone 8, Windows Store, PS Vita (PSM), PS4,Xbox One平臺,


特性:
  • 速度和效率: 不僅非常快,而且非常有效:一切都是緩存和重用,避免無用的GC分配。
  • 快捷: 使用擴展方法擴展公共對象用戶方便編寫代碼如下

      [AppleScript] 純文本查看 複製代碼
      1
      2
      3
      4
      5
      6
      // Move a transform to position 1,2,3 in 1 second
      transform.DOMove(new Vector3(1,2,3), 1);
      // Scale the Y of a transform to 3 in 1 second
      transform.DOScaleY(3, 1);
      // Pause a transform's tween
      transform.DOPause();


  • 幾乎支持任何動畫: 支持屬性數字,非數字, 字符串和富文本動畫展現
  • 還有很多我就不一一介紹了

簡單移動Cube到達目的地:
[AppleScript] 純文本查看 複製代碼
01
02
03
04
05
06
07
08
09
10
11
12
13
14
public Transform cube;
 
    // Use this for initialization
    void Start () {
        //0,4,0的位置移動過去
        cube.DOMove(new Vector3(0,4,0), 2);                   
        //0,4,0的位置移動過來
        cube.DOMove (new Vector3 (0, 4, 0), 2).From();
        //0,4,0的位置來回移動
        cube.DOMove (new Vector3 (0, 4, 0), 2).SetRelative().SetLoops(-1,LoopType.Yoyo);
     
        //另一種寫法
        DOTween.To(()=> cube.position, x=> cube.position = x, new Vector3(0, 4, 0), 1).SetRelative().SetLoops(-1, LoopType.Yoyo);
    }


移動,旋轉,縮放:
[AppleScript] 純文本查看 複製代碼
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
//向上移動4個單位
cube.transform.DOBlendableMoveBy (new Vector3 (0, 4, 0), 2);
 
//自身座標向上移動4個單位
cube.transform.DOBlendableLocalMoveBy (new Vector3 (0, 4, 0), 2);
 
//旋轉
cube.transform.DOBlendableRotateBy(new Vector3(0, 180, 0), 2).SetLoops(-1,LoopType.Yoyo);
 
//本地座標系轉換30
cube.transform.DOBlendableLocalRotateBy(new Vector3(0, 180, 0), 2).SetLoops(-1,LoopType.Yoyo);
 
  //開始值(1,1,1) 5秒內增加到 (3,3,3)
       
cube.transform.DOBlendableScaleBy(new Vector3(2, 2, 2), 5);


跳躍,衝壓機
DOJump(new Vector3(5, 0, 0), 5, 1,5);假設cube座標(0,0,0)最終跳躍到(5,0,0)位置,跳躍的中間最高度是5,跳躍1次,5秒完成
DOPunchPosition(new Vector3(10, 10, 10), 5);在 5 秒內在原始座標和下面座標之間,來回衝壓
DOPunchRotation(new Vector3(50, 50, 50), 5);在 5 秒內在原始旋轉和下面角度之間,來回衝壓變化
DOPunchScale(new Vector3(5, 5, 5), 5);在 5 秒內在原始比例和下面比例之間,來回衝壓變化
控制DOTween方法:
DOComplete();   執行該方法,變化立即結束,且完成移動
DOFlip();   在變化過程中執行該方法,則物體慢慢的變回原樣,如果變化已經完成,該方法無效
DOGoto(2);變化過程中執行該方法,則物體變化到 第二秒 時該物體的位置、比例等
DOKill();停止掉當前的變化
DOPlayBackwards();播放結束之前,讓物體倒序運動到原位
DOPlayForward();播放結束之前,讓物體繼續運動到目標位置
DORestart();   在變化結束之前,執行該方法,則重新開始變化
DORewind();變化過程中執行該方法,回到原始
DOPause();停止
DOPlay();開始
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章