LeanTween的链式调用是其特征之一,LTDescr类就是其中的关键。具体描述可见官方文档:
以下主要是对一些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
缓动函数系列(个人认为是补间动画的精髓)
可自定义也可以用缓动函数库里的缓动函数