在xlua中使用DoTween动画插件

  在使用xlua编程热更新项目时,如果需要使用DoTween动画插件该如何去设置呢?今天就遇到了这个问题,将解决方案记录在这里:

  DoTween通过添加拓展方法的方式为Unity本身的类或对象添加了许多方法,这些方法使用DO、Set、On等开头,不同开头的方法都有特定的作用。xlua要识别DoTween,需要在相应的拓展类上添加[LuaCallCSharp]特性并生成代码,但是对于系统或插件的API,一般不能修改或不方便修改源码(如导出为dll格式使用的插件就不能修改源码),因此需要使用xlua提供的方法为这些API生成代码。

  参考文件:1)xLua中导出DoTween;2)热更新解决方案--xlua学习笔记  五.lua调用C# 9.特殊问题

  代码:1)自定义静态类,包含静态的list属性,在list中添加要生成代码的类型

/// <summary>
/// 在Xlua中使用DoTween
/// </summary>
public static class DoTweenCallXLua
{
    [LuaCallCSharp]
    [ReflectionUse]
    public static List<Type> luaCallCsharpList = 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),
    };
}

  2)在Unity中生成代码

  3)在xlua中调用相关方法即可

  注意事项:在调用过程中发现了一个以前都没有注意到的问题,就是DoTween的DO系列方法DO都是大写的,如果方法名称不正确无法调用

原文地址:https://www.cnblogs.com/movin2333/p/14681639.html