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...