123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- using TMPro;
- using Sirenix.OdinInspector;
- using KairoEngine.Core;
- using KairoEngine.UI.Tooltips;
- namespace KairoEngine.UI.ActivityMessages
- {
- public class ActivityMessageUi : MonoBehaviour
- {
- public TextMeshProUGUI textUi;
- public Image iconImage;
- public TooltipTrigger tooltipTrigger;
- 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 bool hideOnClick = 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()
- {
- if(message.action != null) message.action();
- if(hideOnClick)
- {
- //isFading = true;
- Remove();
- }
- }
- public void Setup(ActivityMessageController controller, ActivityMessage newMessage)
- {
- this.controller = controller;
- message = newMessage;
- textUi.text = message.text;
- hideTimer = message.time;
- autoHide = !message.sticky;
- hideOnClick = message.hideOnClick;
- if(iconImage != null && message.icon != null)
- {
- iconImage.sprite = message.icon;
- iconImage.gameObject.SetActive(true);
- }
- else if(iconImage != null && message.icon == null) iconImage.gameObject.SetActive(false);
- if(!message.sticky)
- {
- Timer.ExecuteRealTime(message.time * 1000, () => {
- Remove();
- });
- }
- if(tooltipTrigger != null && message.tooltipBody != "")
- {
- tooltipTrigger.header = message.tooltipHeader;
- tooltipTrigger.content = message.tooltipBody;
- tooltipTrigger.tooltipType = message.tooltipType;
- }
- else if (tooltipTrigger != null && message.tooltipBody == "")
- {
- tooltipTrigger.enabled = false;
- }
- }
- public void Remove()
- {
- controller.RemoveActivityMessageFromList(message);
- if(this == null) return;
- UiAnimator uiAnimator = gameObject.GetComponent<UiAnimator>();
- if(uiAnimator != null)
- {
- uiAnimator.Disable();
- Timer.ExecuteRealTime(uiAnimator.animationTime * 1000, () => {
- if(this != null) Destroy(this.gameObject);
- });
- }
- else if(this != null) Destroy(this.gameObject);
- }
- }
- }
|