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

1.LeanTween.reset()

一、工具介绍

参考:推荐开源项目:LeanTween - 为Unity 3D打造的高效缓动引擎-CSDN博客

LeanTween是一个专为Unity 3D引擎设计的高效缓动(tweening)库,它提供了简单易用的API,帮助开发者轻松实现各种复杂场景。

二、常用的方法详解


1.LeanTween.reset()

 很明了的方法,用于重置,最好在每次加载的时候进行重置,一般放在Start或者Awaik方法中使用


2.LeanTween.addListener和LeanTween.dispatchEvent

 

代码示例:

public class MoveTools : MonoBehaviour
{
    public GameObject ball;

    public MyActions action;
    void Start()
    {
        LeanTween.reset();
        LeanTween.addListener(this.gameObject, (int)MyActions.Jump, jumpUp);
    }

    void Update()
    {
        if (Input.GetKeyDown(KeyCode.Space))
        {
            Debug.Log("jump!");
            LeanTween.dispatchEvent((int)MyActions.Jump, this);

        }

    }

    void jumpUp(LTEvent e) { Debug.Log("LTEvent:" + e.ToString()); }


}

public enum MyActions
{
    Idle,
    Jump,
}

3.LeanTween.moveSpline

让物体按照一些列点进行移动,但是需要注意的是,第一个点和最后一个点不会经过


public class TestMoveSpline : MonoBehaviour
{
    public MyActions action;

    public List<GameObject> targets;

    private Vector3[] positions; //

    void Start()
    {
        positions = new Vector3[targets.Count];
        LeanTween.reset();
        for (int i = 0; i < targets.Count; i++)
        {
            positions[i] = targets[i].transform.position;
        }
    }

    void Update()
    {
        if (Input.GetKeyDown(KeyCode.Space))
        {
            LeanTween.moveSpline(gameObject, positions, 3.0f);
        }

    }

}

4.LeanTween.rotate系列

rotate系列有:

  • rotate(GameObject gameObject, Vector3 to, float time)
  • rotate(LTRect ltRect, float to, float time)
  • rotateLocal(GameObject gameObject, Vector3 to, float time)

  • rotateX(GameObject gameObject, float to, float time)

  • rotateY(GameObject gameObject, float to, float time)

  • rotateZ(GameObject gameObject, float to, float time)

  • rotateAround(GameObject gameObject, Vector3 axis, float add, float time)

  • rotateAroundLocal(GameObject gameObject, Vector3 axis, float add, float time)

优点:直接输入需要旋转的角度,用法也简单,妈妈再也不用担心旋转的时候出现万象锁啦~

需要注意的是:rotate旋转方向以180°为界,会寻找离当前位置最近的角度进行旋转。

如果要旋转超过180°的话,需要用rotateAround方法,例如要不停的旋转360°,写法可以是:

LeanTween.rotateAround(gameObject, transform.up, -360f, 5f).setLoopClamp();

后续更新ing...

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值