Pull up singleton behaviour.

This commit is contained in:
2023-11-29 13:12:19 +08:00
parent 522699152b
commit e339ec3e4c
7 changed files with 48 additions and 36 deletions

View File

@@ -1,23 +1,11 @@
using System;
using Cryville.Common.Unity;
using UnityEngine;
using UnityEngine.UI;
namespace Cryville.Crtr.UI {
public class PopupManager : MonoBehaviour {
static PopupManager s_instance;
public static PopupManager Instance { get { return s_instance; } }
public class PopupManager : SingletonBehaviour<PopupManager> {
[SerializeField]
GameObject m_popupPrefab;
void Awake() {
if (s_instance != null) {
Destroy(gameObject);
throw new InvalidOperationException("Attempted to initialize a singleton twice.");
}
s_instance = this;
}
public void Create(string msg) {
Instantiate(m_popupPrefab, transform, false).GetComponent<Popup>().Message = msg;
}