| | 1 | | using System.Collections; |
| | 2 | | using DCL.Helpers; |
| | 3 | | using UnityEngine; |
| | 4 | |
|
| | 5 | | namespace DCL.Controllers |
| | 6 | | { |
| | 7 | | public interface IBlockerAnimationHandler |
| | 8 | | { |
| | 9 | | void FadeIn(GameObject go); |
| | 10 | | void FadeOut(GameObject go, System.Action OnFinish); |
| | 11 | | } |
| | 12 | |
|
| | 13 | | /// <summary> |
| | 14 | | /// This class is in charge of handling the FadeIn/FadeOut animation |
| | 15 | | /// of blockers. |
| | 16 | | /// </summary> |
| | 17 | | public class BlockerAnimationHandler : IBlockerAnimationHandler |
| | 18 | | { |
| 32 | 19 | | public void FadeIn(GameObject go) { CoroutineStarter.Start(FadeInCoroutine(go)); } |
| | 20 | |
|
| 0 | 21 | | public void FadeOut(GameObject go, System.Action OnFinish) { CoroutineStarter.Start(FadeOutCoroutine(go, OnFinis |
| | 22 | |
|
| | 23 | | IEnumerator FadeInCoroutine(GameObject go) |
| | 24 | | { |
| 16 | 25 | | Renderer rend = go.GetComponent<Renderer>(); |
| | 26 | |
|
| 16 | 27 | | Color color = rend.material.GetColor(ShaderUtils.BaseColor); |
| | 28 | |
|
| 16 | 29 | | while (color.a < 0.5f) |
| | 30 | | { |
| 0 | 31 | | color.a += Time.deltaTime; |
| 0 | 32 | | rend.material.SetColor(ShaderUtils.BaseColor, color); |
| 0 | 33 | | yield return null; |
| | 34 | | } |
| 16 | 35 | | } |
| | 36 | |
|
| | 37 | | IEnumerator FadeOutCoroutine(GameObject go, System.Action OnFinish) |
| | 38 | | { |
| | 39 | | #if UNITY_STANDALONE || UNITY_EDITOR |
| 0 | 40 | | if (DataStore.i.common.isApplicationQuitting.Get()) |
| 0 | 41 | | yield break; |
| | 42 | | #endif |
| | 43 | |
|
| 0 | 44 | | Renderer rend = go.GetComponent<Renderer>(); |
| | 45 | |
|
| 0 | 46 | | Color color = rend.material.GetColor(ShaderUtils.BaseColor); |
| | 47 | |
|
| 0 | 48 | | while (color.a > 0) |
| | 49 | | { |
| 0 | 50 | | if (rend == null) |
| | 51 | | break; |
| | 52 | |
|
| 0 | 53 | | color.a -= Time.deltaTime; |
| 0 | 54 | | rend.material.SetColor(ShaderUtils.BaseColor, color); |
| 0 | 55 | | yield return null; |
| | 56 | | } |
| | 57 | |
|
| 0 | 58 | | OnFinish?.Invoke(); |
| 0 | 59 | | } |
| | 60 | | } |
| | 61 | | } |