-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathFlashAnim.cs
58 lines (52 loc) · 1.49 KB
/
FlashAnim.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
using DG.Tweening;
using UnityEngine;
namespace GameUtil
{
public class FlashAnim : MonoBehaviour
{
[SerializeField] private RectTransform m_RTFBound;
[SerializeField] private RectTransform m_RTFLine;
[SerializeField] private float mMoveSpeed = 500;
private Sequence mSequence;
private float mPosX;
private float mMoveTime;
private void Awake()
{
mPosX = (m_RTFBound.rect.width + m_RTFLine.rect.width) / 2;
var startPos = m_RTFLine.localPosition;
startPos.x = -mPosX;
m_RTFLine.localPosition = startPos;
mMoveTime = mPosX * 2 / mMoveSpeed;
CreateAnimation();
}
private void CreateAnimation()
{
mSequence = DOTween.Sequence()
.Append(m_RTFLine.DOLocalMoveX(mPosX, mMoveTime).SetEase(Ease.Linear))
.AppendInterval(1.8f)
.SetLoops(-1, LoopType.Restart)
.SetUpdate(true)
.Pause();
}
public void Play()
{
gameObject.SetActive(true);
if (!mSequence.IsPlaying())
{
mSequence.Play();
}
}
public void Stop()
{
gameObject.SetActive(false);
if (mSequence.IsPlaying())
{
mSequence.Pause();
}
}
private void OnDestroy()
{
mSequence.Kill();
}
}
}