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