Files
crtr/Assets/Cryville/Common/Unity/Popup.cs
2022-11-15 13:30:40 +08:00

35 lines
860 B
C#

using UnityEngine;
using UnityEngine.UI;
namespace Cryville.Common.Unity {
public class Popup : MonoBehaviour {
public string Message = "";
LayoutElement layout;
float timer = 0;
const float DURATION = 5.0f;
const float DURIN = 0.4f;
const float DUROUT = 0.4f;
const float HEIGHT = 50f;
#pragma warning disable IDE0051
void Start() {
layout = GetComponent<LayoutElement>();
GetComponentInChildren<Text>().text = Message;
transform.SetParent(GameObject.Find("PopupList").transform);
layout.minHeight = 0;
}
void Update() {
if (timer <= DURIN) layout.minHeight = timer / DURIN * HEIGHT;
else if (timer >= DURATION) GameObject.Destroy(gameObject);
else if (timer >= DURATION - DUROUT) layout.minHeight = (DURATION - timer) / DUROUT * HEIGHT;
timer += Time.deltaTime;
}
#pragma warning restore IDE0051
}
}