Code structure cleanup.
This commit is contained in:
37
Assets/Cryville/Crtr/UI/Popup.cs
Normal file
37
Assets/Cryville/Crtr/UI/Popup.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace Cryville.Crtr.UI {
|
||||
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<CanvasGroup>();
|
||||
group.alpha = 0;
|
||||
GetComponentInChildren<Text>().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<GameObject>("Common/Popup")).GetComponent<Popup>().Message = msg;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user