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
复制代码
pos
ted  本文出自赵青青,原文链接:http://www.cnblogs.com/zhaoqingqing/p/6753701.html ,如需转载请自行联系原作者
相关文章
|
8月前
QML 界面切换的方法
QML 界面切换的方法
495 1
|
图形学
Unity脚本声明周期和MonoBehaviour常用方法
Unity脚本声明周期和MonoBehaviour常用方法
144 0
QT应用编程: 导出QTableWidget数据写入到Execl表格
QT应用编程: 导出QTableWidget数据写入到Execl表格
585 1
Qt-第一个QML程序-4-自定义按钮类,动画,状态
上篇中,我们写到了自己定义了一个按钮,但是呢,按照这样的写法,要写一个程序出来,那要累死了,所以,qml给我的感觉就是各种随便调用,所以了,可以自己写一个自己Button的qml,这样在以后用到了,就可以直接使用了。
466 0
Qt-第一个QML程序-4-自定义按钮类,动画,状态
|
测试技术
DoTween的基本用法
DoTween的基本用法 本文提供全流程,中文翻译。Chinar坚持将简单的生活方式,带给世人!(拥有更好的阅读体验 —— 高分辨率用户请根据需求调整网页缩放比例) ...
2079 0
|
数据可视化
DoTween可视化编程用法详解
DoTween可视化编辑 本文提供全流程,中文翻译。Chinar坚持将简单的生活方式,带给世人!(拥有更好的阅读体验 —— 高分辨率用户请根据需求调整网页缩放比例) ...
2748 0
EMF+GEF的属性页问题
最近有朋友问使用EMF作为GEF模型时,如何在选中editpart时在属性页里显示属性的问题。是的,因为GEF是这样判断是否填充属性 页的: public Object getAdapter(Class key) {     if (IPropertySource.
1374 0