| | 1 | | using System.Collections; |
| | 2 | | using UnityEngine; |
| | 3 | | using UnityEngine.UI; |
| | 4 | |
|
| | 5 | | public interface ISaveHUDView |
| | 6 | | { |
| | 7 | | void SetFirstPersonView(); |
| | 8 | | void SetGodModeView(); |
| | 9 | | void SceneStateSaved(); |
| | 10 | | void StopAnimation(); |
| | 11 | | void SetViewByEntityListOpen(bool isOpen); |
| | 12 | | } |
| | 13 | |
|
| | 14 | | public class SaveHUDView : MonoBehaviour, ISaveHUDView |
| | 15 | | { |
| | 16 | | [Header("Animation design")] |
| 20 | 17 | | [SerializeField] internal float saveAnimationSpeed = 1.25f; |
| 20 | 18 | | [SerializeField] internal float sFullVisibleTime = 0.5f; |
| 20 | 19 | | [SerializeField] internal float percentMinVisible = 0.25f; |
| 20 | 20 | | [SerializeField] internal int totalAnimationTimes = 5; |
| | 21 | |
|
| | 22 | | [Header("References")] |
| | 23 | | [SerializeField] internal Image saveImg; |
| | 24 | | [SerializeField] internal RectTransform godModePosition; |
| | 25 | | [SerializeField] internal RectTransform godModeEntityListOpenPosition; |
| | 26 | | [SerializeField] internal RectTransform firstPersonModePosition; |
| | 27 | | [SerializeField] internal InspectorView inspectorView; |
| | 28 | |
|
| | 29 | | private Coroutine animationCourutine; |
| | 30 | |
|
| 40 | 31 | | private void OnDisable() { StopAnimation(); } |
| | 32 | |
|
| | 33 | | public void SceneStateSaved() |
| | 34 | | { |
| 0 | 35 | | StopAnimation(); |
| 0 | 36 | | animationCourutine = CoroutineStarter.Start(SceneStateSaveAnimation()); |
| 0 | 37 | | } |
| | 38 | | public void StopAnimation() |
| | 39 | | { |
| 20 | 40 | | if (animationCourutine != null) |
| | 41 | | { |
| 0 | 42 | | CoroutineStarter.Stop(animationCourutine); |
| 0 | 43 | | animationCourutine = null; |
| | 44 | | } |
| | 45 | |
|
| 20 | 46 | | HideSaveImage(); |
| 20 | 47 | | } |
| | 48 | |
|
| 2 | 49 | | public void SetFirstPersonView() { saveImg.rectTransform.anchoredPosition = firstPersonModePosition.anchoredPosition |
| | 50 | |
|
| 0 | 51 | | public void SetGodModeView() { SetViewByEntityListOpen(inspectorView.IsActive()); } |
| | 52 | |
|
| 0 | 53 | | public void SetViewByEntityListOpen(bool isOpen) { saveImg.rectTransform.anchoredPosition = isOpen ? godModeEntityLi |
| | 54 | |
|
| | 55 | | private IEnumerator SceneStateSaveAnimation() |
| | 56 | | { |
| 0 | 57 | | float initialValue = percentMinVisible; |
| 0 | 58 | | float finalValue = 1; |
| | 59 | |
|
| 0 | 60 | | Color from = saveImg.color; |
| 0 | 61 | | from.a = initialValue; |
| 0 | 62 | | Color to = saveImg.color; |
| 0 | 63 | | to.a = finalValue; |
| | 64 | |
|
| | 65 | | Color currentColor; |
| | 66 | |
|
| 0 | 67 | | float currentAdvance = 0; |
| 0 | 68 | | int currentAnimationTimes = 0; |
| 0 | 69 | | while (currentAnimationTimes < totalAnimationTimes) |
| | 70 | | { |
| 0 | 71 | | currentAdvance += saveAnimationSpeed * Time.deltaTime; |
| 0 | 72 | | currentColor = Color.Lerp(from, to, currentAdvance); |
| 0 | 73 | | saveImg.color = currentColor; |
| | 74 | |
|
| 0 | 75 | | if (currentAdvance >= 1) |
| | 76 | | { |
| 0 | 77 | | if (Mathf.Abs(from.a - initialValue) < 0.1f ) |
| | 78 | | { |
| 0 | 79 | | from.a = finalValue; |
| 0 | 80 | | to.a = initialValue; |
| 0 | 81 | | yield return new WaitForSecondsRealtime(sFullVisibleTime); |
| 0 | 82 | | } |
| | 83 | | else |
| | 84 | | { |
| 0 | 85 | | from.a = initialValue; |
| 0 | 86 | | to.a = finalValue; |
| | 87 | | } |
| 0 | 88 | | currentAnimationTimes++; |
| 0 | 89 | | currentAdvance = 0; |
| | 90 | | } |
| 0 | 91 | | yield return null; |
| | 92 | | } |
| | 93 | |
|
| 0 | 94 | | HideSaveImage(); |
| 0 | 95 | | } |
| | 96 | |
|
| | 97 | | private void HideSaveImage() |
| | 98 | | { |
| 20 | 99 | | Color final = saveImg.color; |
| 20 | 100 | | final.a = 0; |
| 20 | 101 | | saveImg.color = final; |
| 20 | 102 | | } |
| | 103 | | } |