| | 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 | | { |
| | 19 | | public void FadeIn(GameObject go) |
| | 20 | | { |
| 32 | 21 | | CoroutineStarter.Start(FadeInCoroutine(go)); |
| 32 | 22 | | } |
| | 23 | |
|
| | 24 | | public void FadeOut(GameObject go, System.Action OnFinish) |
| | 25 | | { |
| 0 | 26 | | CoroutineStarter.Start(FadeOutCoroutine(go, OnFinish)); |
| 0 | 27 | | } |
| | 28 | |
|
| | 29 | | IEnumerator FadeInCoroutine(GameObject go) |
| | 30 | | { |
| 32 | 31 | | Renderer rend = go.GetComponent<Renderer>(); |
| | 32 | |
|
| 32 | 33 | | Color color = rend.material.GetColor(ShaderUtils.BaseColor); |
| | 34 | |
|
| 32 | 35 | | while (color.a < 0.5f) |
| | 36 | | { |
| 0 | 37 | | color.a += Time.deltaTime; |
| 0 | 38 | | rend.material.SetColor(ShaderUtils.BaseColor, color); |
| 0 | 39 | | yield return null; |
| | 40 | | } |
| 32 | 41 | | } |
| | 42 | |
|
| | 43 | | IEnumerator FadeOutCoroutine(GameObject go, System.Action OnFinish) |
| | 44 | | { |
| | 45 | | #if UNITY_STANDALONE || UNITY_EDITOR |
| 0 | 46 | | if (DataStore.i.common.isApplicationQuitting.Get()) |
| 0 | 47 | | yield break; |
| | 48 | | #endif |
| | 49 | |
|
| 0 | 50 | | Renderer rend = go.GetComponent<Renderer>(); |
| | 51 | |
|
| 0 | 52 | | Color color = rend.material.GetColor(ShaderUtils.BaseColor); |
| | 53 | |
|
| 0 | 54 | | while (color.a > 0) |
| | 55 | | { |
| 0 | 56 | | if (rend == null) |
| | 57 | | break; |
| | 58 | |
|
| 0 | 59 | | color.a -= Time.deltaTime; |
| 0 | 60 | | rend.material.SetColor(ShaderUtils.BaseColor, color); |
| 0 | 61 | | yield return null; |
| | 62 | | } |
| | 63 | |
|
| 0 | 64 | | OnFinish?.Invoke(); |
| 0 | 65 | | } |
| | 66 | | } |
| | 67 | | } |