fix:代码提交
This commit is contained in:
109
Assets/Scripts/Anim/TweenScale.cs
Normal file
109
Assets/Scripts/Anim/TweenScale.cs
Normal file
@@ -0,0 +1,109 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using DG.Tweening;
|
||||
|
||||
public class TweenScale : MonoBehaviour
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
private void Reset()
|
||||
{
|
||||
from = transform.localScale;
|
||||
to = transform.localScale;
|
||||
}
|
||||
#endif
|
||||
|
||||
public Vector3 from = Vector3.one;
|
||||
public Vector3 to = Vector3.one;
|
||||
|
||||
public TweenStyle playStyle = TweenStyle.Once;
|
||||
|
||||
public AnimationCurve curve = new AnimationCurve(new Keyframe(0f, 0f, 0f, 1f), new Keyframe(1f, 1f, 1f, 0f));
|
||||
|
||||
public float timer = 1f;
|
||||
|
||||
private Tween tweener = null;
|
||||
|
||||
// Use this for initialization
|
||||
void Start()
|
||||
{
|
||||
PlayForward();
|
||||
}
|
||||
|
||||
public void PlayForward()
|
||||
{
|
||||
ResetToBegining();
|
||||
switch (playStyle)
|
||||
{
|
||||
case TweenStyle.Once:
|
||||
tweener = transform.DOScale(to, timer).SetEase(curve);
|
||||
break;
|
||||
case TweenStyle.Loop:
|
||||
tweener = transform.DOScale(to, timer).SetEase(curve).SetLoops(-1);
|
||||
break;
|
||||
case TweenStyle.PingPong:
|
||||
tweener = transform.DOScale(to, timer).SetEase(curve).SetLoops(-1, LoopType.Yoyo);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void PlayReverse()
|
||||
{
|
||||
ResetToEnding();
|
||||
switch (playStyle)
|
||||
{
|
||||
case TweenStyle.Once:
|
||||
tweener = transform.DOScale(from, timer).SetEase(curve);
|
||||
break;
|
||||
case TweenStyle.Loop:
|
||||
tweener = transform.DOScale(from, timer).SetEase(curve).SetLoops(-1);
|
||||
break;
|
||||
case TweenStyle.PingPong:
|
||||
tweener = transform.DOScale(from, timer).SetEase(curve).SetLoops(-1, LoopType.Yoyo);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void Stop()
|
||||
{
|
||||
if (tweener != null)
|
||||
{
|
||||
tweener.Kill();
|
||||
}
|
||||
}
|
||||
|
||||
public void Pause()
|
||||
{
|
||||
if (tweener != null)
|
||||
{
|
||||
tweener.Pause();
|
||||
}
|
||||
}
|
||||
|
||||
public void Play()
|
||||
{
|
||||
if (tweener != null)
|
||||
{
|
||||
tweener.Play();
|
||||
}
|
||||
}
|
||||
|
||||
public void ResetToBegining()
|
||||
{
|
||||
if (tweener != null)
|
||||
{
|
||||
tweener.Kill();
|
||||
}
|
||||
transform.localScale = from;
|
||||
|
||||
}
|
||||
|
||||
public void ResetToEnding()
|
||||
{
|
||||
if (tweener != null)
|
||||
{
|
||||
tweener.Kill();
|
||||
}
|
||||
transform.localScale = to;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user