using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using TMPro; using Sirenix.OdinInspector; namespace KairoEngine.UI.ActivityMessages { public class ActivityMessageUi : MonoBehaviour { public TextMeshProUGUI textUi; public Image buttonImage; public ActivityMessage message; public bool autoHide = true; public float hideTimer = 5f; private float hideCounter = 0f; public bool fadeIn = true; public bool fadeOut = true; public float fadeTimer = 0.5f; private float fadeCounter = 0f; private bool isFading = false; private bool hasFadedIn = false; private ActivityMessageController controller; private void Update() { if (fadeIn && !hasFadedIn) { fadeCounter += Time.deltaTime; Color color = textUi.color; color.a = fadeCounter / fadeTimer; textUi.color = color; buttonImage.color = color; if (fadeCounter >= fadeTimer) { fadeCounter = 0f; hasFadedIn = true; } } if (autoHide && hasFadedIn || fadeIn == false) { hideCounter += Time.deltaTime; if(hideCounter >= hideTimer) { hideCounter = 0f; isFading = true; } } if (fadeOut && isFading) { fadeCounter += Time.deltaTime; Color color = textUi.color; color.a = 1f - (fadeCounter / fadeTimer); textUi.color = color; buttonImage.color = color; if (fadeCounter >= fadeTimer) { fadeCounter = 0f; if(controller != null) { controller.messages.Remove(message); controller.activeMessages.Remove(this); } Destroy(this.gameObject); } } } public void OnClick() { isFading = true; } public void Setup(ActivityMessageController controller, ActivityMessage newMessage, bool sticky = false) { this.controller = controller; message = newMessage; textUi.text = message.text; autoHide = !sticky; } public void Setup(ActivityMessageController controller, ActivityMessage newMessage, float time, bool sticky = false) { this.controller = controller; message = newMessage; textUi.text = message.text; hideTimer = time; autoHide = !sticky; } public void Remove(ActivityMessageController controller) { this.controller = controller; autoHide = true; hideTimer = 0f; } } }