在xlua中使用DoTween動畫插件


  在使用xlua編程熱更新項目時,如果需要使用DoTween動畫插件該如何去設置呢?今天就遇到了這個問題,將解決方案記錄在這里:

  DoTween通過添加拓展方法的方式為Unity本身的類或對象添加了許多方法,這些方法使用DO、Set、On等開頭,不同開頭的方法都有特定的作用。xlua要識別DoTween,需要在相應的拓展類上添加[LuaCallCSharp]特性並生成代碼,但是對於系統或插件的API,一般不能修改或不方便修改源碼(如導出為dll格式使用的插件就不能修改源碼),因此需要使用xlua提供的方法為這些API生成代碼。

  參考文件:1)xLua中導出DoTween;2)熱更新解決方案--xlua學習筆記  五.lua調用C# 9.特殊問題

  代碼:1)自定義靜態類,包含靜態的list屬性,在list中添加要生成代碼的類型

/// <summary>
/// 在Xlua中使用DoTween
/// </summary>
public static class DoTweenCallXLua
{
    [LuaCallCSharp]
    [ReflectionUse]
    public static List<Type> luaCallCsharpList = new List<Type>(){
        typeof(DG.Tweening.AutoPlay),
        typeof(DG.Tweening.AxisConstraint),
        typeof(DG.Tweening.Ease),
        typeof(DG.Tweening.LogBehaviour),
        typeof(DG.Tweening.LoopType),
        typeof(DG.Tweening.PathMode),
        typeof(DG.Tweening.PathType),
        typeof(DG.Tweening.RotateMode),
        typeof(DG.Tweening.ScrambleMode),
        typeof(DG.Tweening.TweenType),
        typeof(DG.Tweening.UpdateType),

        typeof(DG.Tweening.DOTween),
        typeof(DG.Tweening.DOVirtual),
        typeof(DG.Tweening.EaseFactory),
        typeof(DG.Tweening.Tweener),
        typeof(DG.Tweening.Tween),
        typeof(DG.Tweening.Sequence),
        typeof(DG.Tweening.TweenParams),
        typeof(DG.Tweening.Core.ABSSequentiable),

        typeof(DG.Tweening.Core.TweenerCore<Vector3, Vector3, DG.Tweening.Plugins.Options.VectorOptions>),

        typeof(DG.Tweening.TweenCallback),
        typeof(DG.Tweening.TweenExtensions),
        typeof(DG.Tweening.TweenSettingsExtensions),
        typeof(DG.Tweening.ShortcutExtensions),
        typeof(DG.Tweening.ShortcutExtensions43),
        typeof(DG.Tweening.ShortcutExtensions46),
        typeof(DG.Tweening.ShortcutExtensions50),
    };
}

  2)在Unity中生成代碼

  3)在xlua中調用相關方法即可

  注意事項:在調用過程中發現了一個以前都沒有注意到的問題,就是DoTween的DO系列方法DO都是大寫的,如果方法名稱不正確無法調用


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM