xLua中導出Dotween


前言

在xlua的lua腳本中使用dotween,官方的文檔中有提到可以導出,但未介紹詳細的步驟,相信比較多的朋友有需要,剛好項目中也在使用xlua和dotween,所以做個筆記。

 

基礎知識:

xLua:https://github.com/Tencent/xLua

dotween:http://dotween.demigiant.com/

關於dotween的使用,可以參考我之前的文章

DOTween文檔

DoTween(HOTween V2) 教程

 

我的測試環境:

xLua 2.1.6

dotween 1.1.x

unity 5.3.5/5.4

 

本文的測試代碼:

https://github.com/zhaoqingqing/blog_samplecode/blob/master/unity_helper/XLuaCustomExport.cs

https://github.com/zhaoqingqing/blog_samplecode/blob/master/unity_helper/xlua_dotween_test.lua

 

導出Dotween

1、在項目的Asset目錄下(自己項目的Scripts目錄),新建一個class,命名為:XLuaCustomExport.cs

2、導出腳本如下,如果在手機上調用報錯,但PC上正常,請檢查是否添加了[ReflectionUse]標簽

using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;
using XLua;

/// <summary>
/// xlua自定義導出
/// </summary>
public static class XLuaCustomExport
{
    /// <summary>
    /// dotween的擴展方法在lua中調用
    /// </summary>
    [LuaCallCSharp]
    [ReflectionUse]
    public static List<Type> dotween_lua_call_cs_list = 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),
       
        //dotween pro 的功能
        //typeof(DG.Tweening.DOTweenPath),
        //typeof(DG.Tweening.DOTweenVisualManager),
    };
}

 

xLua中調用Dotween

在Lua中調用dotween的示例如下:

-- transform:DOMove(Vector3.zero, 3, false);

--場景中綁定LuaBehaviour,執行Unity的默認函數

function start()
    print("lua start .");
    local tween = self.transform:DOMoveX(10,3)
    --tween:OnComplete(){
    --    print("move callback")
    --}
end


免責聲明!

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



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