using System; using UnityEngine; using UnityEngine.UI; namespace Cryville.Crtr { public class Popup : MonoBehaviour { public string Message = ""; CanvasGroup group; float timer = 0; const float DURATION = 5.0f; const float DURIN = 0.4f; const float DUROUT = 0.4f; void Start() { group = GetComponent(); group.alpha = 0; GetComponentInChildren().text = Message; transform.SetParent(GameObject.Find("PopupList").transform, false); } void Update() { if (timer <= DURIN) group.alpha = timer / DURIN; else if (timer >= DURATION) GameObject.Destroy(gameObject); else if (timer >= DURATION - DUROUT) group.alpha = (DURATION - timer) / DUROUT; timer += Time.deltaTime; } public static void CreateException(Exception ex) { Create(ex.Message); } public static void Create(string msg) { Instantiate(Resources.Load("Common/Popup")).GetComponent().Message = msg; } } }