| | 1 | | using DG.Tweening; |
| | 2 | | using UnityEngine; |
| | 3 | |
|
| | 4 | | namespace DCLServices.MapRendererV2.MapLayers.PlayerMarker |
| | 5 | | { |
| | 6 | | public class PlayerMarkerCircleAnimation : MonoBehaviour |
| | 7 | | { |
| | 8 | | [Space] |
| | 9 | | [SerializeField] private Transform circle; |
| | 10 | |
|
| 97 | 11 | | [SerializeField] private float endScaleFactor = 0.85f; |
| 97 | 12 | | [SerializeField] private float animationDuration = 0.5f; |
| 97 | 13 | | [SerializeField] private Ease easyType = Ease.InOutQuart; |
| | 14 | |
|
| | 15 | | private Vector3 startScale; |
| | 16 | | private Vector3 endScale; |
| | 17 | |
|
| | 18 | | private Tween tween; |
| | 19 | |
|
| | 20 | | private void Start() |
| | 21 | | { |
| 0 | 22 | | startScale = circle.localScale; |
| 0 | 23 | | endScale = startScale * endScaleFactor; |
| | 24 | |
|
| 0 | 25 | | if (tween == null) |
| 0 | 26 | | StartPingPongAnimation(); |
| 0 | 27 | | } |
| | 28 | |
|
| | 29 | | private void OnEnable() |
| | 30 | | { |
| 192 | 31 | | if (startScale == Vector3.zero) return; |
| | 32 | |
|
| 0 | 33 | | StartPingPongAnimation(); |
| 0 | 34 | | } |
| | 35 | |
|
| | 36 | | private void OnDisable() |
| | 37 | | { |
| 192 | 38 | | if (tween == null || !tween.IsActive()) return; |
| | 39 | |
|
| 0 | 40 | | tween.Kill(); |
| 0 | 41 | | circle.localScale = startScale; |
| 0 | 42 | | } |
| | 43 | |
|
| | 44 | | [ContextMenu(nameof(StartPingPongAnimation))] |
| | 45 | | private void StartPingPongAnimation() |
| | 46 | | { |
| 0 | 47 | | tween = circle.DOScale(endScale, animationDuration) |
| | 48 | | .SetLoops(-1, LoopType.Yoyo) // -1 for infinite loops |
| | 49 | | .SetEase(easyType); |
| 0 | 50 | | } |
| | 51 | | } |
| | 52 | | } |