| | 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 DeactivatePreview(); |
| | 15 | | public abstract void FadeOut(); |
| | 16 | | public abstract void ActivatePreview(); |
| | 17 | | public abstract void ActivatePreviewInstantly(); |
| | 18 | | public abstract void DeactivatePreviewInstantly(); |
| | 19 | |
|
| | 20 | | protected IEnumerator InterpolateAlpha(float destinationAlpha, float duration) |
| | 21 | | { |
| 0 | 22 | | if (!fadeEnabled) |
| | 23 | | { |
| 0 | 24 | | group.alpha = destinationAlpha; |
| 0 | 25 | | StopCoroutine(previewInterpolationAlphaRoutine); |
| | 26 | | } |
| 0 | 27 | | if(destinationAlpha.Equals(group.alpha)) yield break; |
| 0 | 28 | | var t = 0f; |
| 0 | 29 | | var startAlpha = group.alpha; |
| | 30 | | //NOTE(Brian): Small offset using normalized Y so we keep the cascade effect |
| 0 | 31 | | double yOffset = ((RectTransform) transform).localPosition.y / (double) Screen.height * 2.5f; |
| 0 | 32 | | duration -= (float) yOffset; |
| 0 | 33 | | while (t < duration) |
| | 34 | | { |
| 0 | 35 | | t += Time.deltaTime; |
| 0 | 36 | | group.alpha = Mathf.Lerp(startAlpha, destinationAlpha, t / duration); |
| 0 | 37 | | yield return null; |
| | 38 | | } |
| 0 | 39 | | group.alpha = destinationAlpha; |
| 0 | 40 | | } |
| | 41 | | } |