I want to make a common alert window to show information about some info maybe warning, tutorial etc,
I think it will be good if there is a way that the alert widget(mostly just a box border, a close button, the info text and some hint sign stuff) could pop up when there is event received, so in the game I could just shoot the msg through a static method, and the widget could just pop up.
I have no problem to do the event part, but I couldn't find a way to active the gameobject of the widget since it will be deactivated as the game started, and seems couldn't assign itself the event pool.
Is there a way to do that? Or how you deal with the problem?
And here is the event assignment so far I have complete:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class WarningTextUGUIController : MonoBehaviour {
private Text text;
// Use this for initialization
void Start () {
text = GetComponent<Text>();
text.text = ApplicationModel.CurrentErrMsg;
ApplicationModel.OnErrMsg += ChangeErrMsg;
}
private void ChangeErrMsg(string msg, bool isNgui)
{
if (!isNgui)
{
text.text = msg;
if (!gameObject.transform.parent.parent.gameObject.activeSelf)
{
gameObject.transform.parent.parent.localScale = new Vector3(0f, 0f, 0f);
gameObject.transform.parent.parent.gameObject.SetActive(true);
LeanTween.scale(gameObject.transform.parent.parent.gameObject, new Vector3(1f, 1f, 1f), 0.2f).setEase(LeanTweenType.easeInBounce);
}
}
}
private void OnDestroy()
{
ApplicationModel.OnErrMsg -= ChangeErrMsg;
}
}
I must note that things will work if I made the widget active at the beginning of the game, but I have to disable it because it's shouldn't be seen under most circumstances.