U3D 扩展方法 & Dotween & tolua

本文介绍Unity3D中自定义扩展方法及Dotween动画库的应用,通过具体代码示例展示了如何创建链式调用的扩展方法,并结合Dotween实现物体平滑移动效果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

U3D 扩展方法 & Dotween & tolua

using UnityEngine;
using System.Collections;
using LuaInterface;//tolua 空间引用 
using DG.Tweening;//DOTWEEN 空间引用 


public static class MyExt{//扩展方法必须在静态类中
    public static Transform LQDoMove(this Transform root, string str){//必须为静态方法, 第一参数为 this Transform, camera 等
        Debug.Log(str);
        return root;//返回transform以实现链式调用

    }
    public static Transform LQ1(this Transform root){
        Debug.Log ("lq1========================");
        return root;
    }

    public static Transform LQ2(this Transform root){
        Debug.Log ("lq2========================");
        return root;
    }

    public static Transform LQ3(this Transform root){
        Debug.Log ("lq3========================");
        return root;
    }
}
public class helloLua : MonoBehaviour {


    // Use this for initialization
    void Start () {
        Debug.Log ("start------------");
        LuaState L = new LuaState ();
        string luaPath = Application.dataPath + "/Lua";

        L.Start ();
        L.AddSearchPath (luaPath);
        L.DoFile ("helloLua.lua");
        L.CheckTop ();
        L.Dispose ();

        transform.LQDoMove ("LQDoMove=====================").LQ1 ().LQ2 ().LQ3 ();//链式调用
        Tweener tw = transform.DOMove (new Vector3 (2, 2, 2), 1, false);
        tw.SetEase (Ease.InOutBack);
        tw.SetLoops (4, LoopType.Restart);
        tw.OnComplete(() => {
            Debug.Log("OnComplete================================");
        });
    }
    
    // Update is called once per frame
    void Update () {
        
    }
}

 

posted on 2016-11-07 11:34 时空观察者9号 阅读(...) 评论(...) 编辑 收藏

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值