| | 1 | | using System.Collections; |
| | 2 | | using UnityEngine; |
| | 3 | |
|
| | 4 | | public abstract class ChatEntry : MonoBehaviour |
| | 5 | | { |
| | 6 | | [SerializeField] internal CanvasGroup group; |
| | 7 | | protected bool fadeEnabled; |
| | 8 | | protected Coroutine previewInterpolationRoutine; |
| | 9 | | protected Coroutine previewInterpolationAlphaRoutine; |
| | 10 | |
|
| | 11 | | public abstract ChatEntryModel Model { get; } |
| | 12 | | public abstract void Populate(ChatEntryModel model); |
| | 13 | | public abstract void SetFadeout(bool enabled); |
| | 14 | | public abstract void FadeOut(); |
| | 15 | |
|
| | 16 | | protected IEnumerator InterpolateAlpha(float destinationAlpha, float duration) |
| | 17 | | { |
| 0 | 18 | | if (!fadeEnabled) |
| | 19 | | { |
| 0 | 20 | | group.alpha = destinationAlpha; |
| 0 | 21 | | StopCoroutine(previewInterpolationAlphaRoutine); |
| | 22 | | } |
| 0 | 23 | | if(destinationAlpha.Equals(group.alpha)) yield break; |
| 0 | 24 | | var t = 0f; |
| 0 | 25 | | var startAlpha = group.alpha; |
| | 26 | | //NOTE(Brian): Small offset using normalized Y so we keep the cascade effect |
| 0 | 27 | | double yOffset = ((RectTransform) transform).localPosition.y / (double) Screen.height * 2.5f; |
| 0 | 28 | | duration -= (float) yOffset; |
| 0 | 29 | | while (t < duration) |
| | 30 | | { |
| 0 | 31 | | t += Time.deltaTime; |
| 0 | 32 | | group.alpha = Mathf.Lerp(startAlpha, destinationAlpha, t / duration); |
| 0 | 33 | | yield return null; |
| | 34 | | } |
| 0 | 35 | | group.alpha = destinationAlpha; |
| 0 | 36 | | } |
| | 37 | | } |