找回密码
 立即注册
查看: 220|回复: 0

[简易教程] 在xlua中使用dotween

[复制链接]
发表于 2021-8-16 16:24 | 显示全部楼层 |阅读模式

前言
在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
导出Dotween
1、在项目的Asset目录下(自己项目的Scripts目录),新建一个class,命名为:XLuaCustomExport.cs
2、导出脚本如下,如果在手机上调用报错,但PC上正常,请检查是否添加了[ReflectionUse]标签
本文的测试代码:导入xlua中,新建一个自定义的XLuaCustomExport.cs
代码如下:
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Reflection;
  5. using UnityEngine;
  6. using UnityEngine.Events;
  7. using UnityEngine.UI;
  8. using XLua;

  9. /// <summary>
  10. /// xlua自定义导出
  11. /// </summary>
  12. public static class XLuaCustomExport
  13. {
  14.     /// <summary>
  15.     /// dotween的扩展方法在lua中调用
  16.     /// </summary>
  17.     [LuaCallCSharp]
  18.     [ReflectionUse]
  19.     public static List<Type> dotween_lua_call_cs_list = new List<Type>()
  20.     {
  21.         typeof(DG.Tweening.AutoPlay),
  22.         typeof(DG.Tweening.AxisConstraint),
  23.         typeof(DG.Tweening.Ease),
  24.         typeof(DG.Tweening.LogBehaviour),
  25.         typeof(DG.Tweening.LoopType),
  26.         typeof(DG.Tweening.PathMode),
  27.         typeof(DG.Tweening.PathType),
  28.         typeof(DG.Tweening.RotateMode),
  29.         typeof(DG.Tweening.ScrambleMode),
  30.         typeof(DG.Tweening.TweenType),
  31.         typeof(DG.Tweening.UpdateType),

  32.         typeof(DG.Tweening.DOTween),
  33.         typeof(DG.Tweening.DOVirtual),
  34.         typeof(DG.Tweening.EaseFactory),
  35.         typeof(DG.Tweening.Tweener),
  36.         typeof(DG.Tweening.Tween),
  37.         typeof(DG.Tweening.Sequence),
  38.         typeof(DG.Tweening.TweenParams),
  39.         typeof(DG.Tweening.Core.ABSSequentiable),

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

  41.         typeof(DG.Tweening.TweenCallback),
  42.         typeof(DG.Tweening.TweenExtensions),
  43.         typeof(DG.Tweening.TweenSettingsExtensions),
  44.         typeof(DG.Tweening.ShortcutExtensions),
  45.         typeof(DG.Tweening.ShortcutExtensions43),
  46.         typeof(DG.Tweening.ShortcutExtensions46),
  47.         typeof(DG.Tweening.ShortcutExtensions50),
  48.       
  49.         //dotween pro 的功能
  50.         //typeof(DG.Tweening.DOTweenPath),
  51.         //typeof(DG.Tweening.DOTweenVisualManager),
  52.     };
  53. }
复制代码

在菜单中XLua中重新Generate Code,绑定新写的Lua
在xlua中使用:
  1. -- transform:DOMove(Vector3.zero, 3, false);

  2. --场景中绑定LuaBehaviour,执行Unity的默认函数

  3. function start()
  4.     print("lua start .");
  5.     local tween = self.transform:DOMoveX(10,3)
  6.     --tween:OnComplete(){
  7.     --    print("move callback")
  8.     --}
  9. end
复制代码


懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Unity开发者联盟 ( 粤ICP备20003399号 )

GMT+8, 2024-5-22 09:42 , Processed in 0.088796 second(s), 26 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表