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.2.x

unity 2018.2.X

导出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;

///
/// xlua自定义导出
///
public static class XLuaCustomExport
{
///
/// dotween的扩展方法在lua中调用
///
[LuaCallCSharp]
[ReflectionUse]
public static List dotween_lua_call_cs_list = new List()
{
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的默认函数

–[==[

  • Author: Kevin
  • CreateTime: 2018-11-28 18:53:31
  • Organization: #ORGANIZATION#
  • Description:
    –]==]
    local GameObject = CS.UnityEngine.GameObject
    local PrimitiveType = CS.UnityEngine.PrimitiveType

local M = {}
----- CODE -----
local cube = GameObject.CreatePrimitive(PrimitiveType.Cube)
cube.transform:DOScale(0.1, 1):OnComplete(function()
print(cube.name, “DOScale Complete”)
end)

local sphere = GameObject.CreatePrimitive(PrimitiveType.Sphere)
local sequence = CS.DG.Tweening.DOTween.Sequence()
sequence:Append(sphere.transform:DOMoveX(1, 1))
sequence:Append(sphere.transform:DOScale(1.5, 1))
sequence:OnComplete(function()
print(sphere.name, “Sequence Complete”)
end)
----- CODE -----
return M

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值