在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
导出Dotween1、在项目的Asset目录下(自己项目的Scripts目录),新建一个class,命名为:XLuaCustomExport.cs2、导出脚本如下,如果在手机上调用报错,但PC上正常,请检查是否添加了标签本文的测试代码:导入xlua中,新建一个自定义的XLuaCustomExport.cs
代码如下:
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>
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中重新Generate Code,绑定新写的Lua
在xlua中使用:
-- 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
页:
[1]