开源项目工具:LeanTween - 为Unity 3D打造的高效缓动引擎详解(比较麻烦的API版) 之 “LTDescr”

LeanTween的链式调用是其特征之一,LTDescr类就是其中的关键。具体描述可见官方文档:

LTDescr - LeanTween

以下主要是对一些API进行示例:

一、Loop系列

1.setLoopOnce ()

不进行循环,仅运行一次

2.setLoopPingPong()

当物体运动结束的时候,会沿着路线返回

3.setLoopClamp() 

当物体运动结束的时候,从起始点重新开始

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class TestLTDescr : MonoBehaviour
{
    public GameObject gameObjectLoopOnce;
    public GameObject gameObjectLoopPingPong;
    public GameObject gameObjectLoopClamp;
    void Start()
    {
        LeanTween.reset();
        //运行到终点就停止运动
        LeanTween.move(gameObjectLoopOnce, new Vector3(2f, gameObjectLoopOnce.transform.position.y, gameObjectLoopOnce.transform.position.z), 3f).setLoopOnce();
        //循环运动,在终点和起点往返
        LeanTween.move(gameObjectLoopPingPong, new Vector3(2f, gameObjectLoopPingPong.transform.position.y, gameObjectLoopPingPong.transform.position.z), 3f).setLoopPingPong();
        //循环运动,不断从起点开始运动
        LeanTween.move(gameObjectLoopClamp, new Vector3(2f, gameObjectLoopClamp.transform.position.y, gameObjectLoopClamp.transform.position.z), 3f).setLoopClamp();
    }


}

二、cancel,pause,resumer状态系列

其中,cancel已经弃用,改用LeanTween.cancel(id)

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class TestLTDescr : MonoBehaviour
{
    public GameObject gameObjectLoopOnce;
    public GameObject gameObjectLoopPingPong;
    public GameObject gameObjectLoopClamp;

    public int id;

    public float timer = 0;

    void Start()
    {
        //循环运动,在终点和起点往返
        LTDescr lTDescr = LeanTween.move(gameObjectLoopPingPong, new Vector3(2f, gameObjectLoopPingPong.transform.position.y, gameObjectLoopPingPong.transform.position.z), 3f).setLoopPingPong();
        Debug.Log("id:" + lTDescr.id);
        //取消循环
        id = lTDescr.id;

    }

    // Update is called once per frame
    void Update()
    {
        if (timer > 5f)
        {
            Debug.Log("id:" + id + "到时间了");

            LeanTween.cancel(id);//LeanTween.descr(id).cancel(gameObjectLoopPingPong);已弃用
            LeanTween.descr(id).pause();
            LeanTween.descr(id).resume();
        }
        timer += Time.deltaTime;

    }
}

三、setEase 缓动函数系列(个人认为是补间动画的精髓)

可自定义也可以用缓动函数库里的缓动函数

缓动函数库:Easing Functions Cheat Sheet

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值