using System.Collections; using System.Collections.Generic; using UnityEngine; public class ResourceLoadPanel : MonoBehaviour where T : ResourceLoadPanel { private static T instance; public static T GetInstance { get { if (instance == null) { string path = "UI/" + typeof(T); GameObject obj = Resources.Load(path); if(!GameObject.Find("Canvas").transform) { return null; } GameObject clone = Instantiate(obj, GameObject.Find("Canvas").transform); clone.transform.SetAsLastSibling(); clone.name = typeof(T).ToString(); //clone.transform.position = Vector3.zero; instance = clone.GetComponent(); if (!clone.GetComponent()) { clone.AddComponent(); } } //if (!instance.gameObject.activeSelf) // instance.gameObject.SetActive(true); return instance; } } public static T GetActiveInstance { get { if (instance == null) { string path = "UI/" + typeof(T); GameObject obj = Resources.Load(path); GameObject clone = Instantiate(obj, GameObject.Find("Canvas").transform); clone.transform.SetAsLastSibling(); clone.name = typeof(T).ToString(); //clone.transform.position = Vector3.zero; instance = clone.GetComponent(); } if (!instance.gameObject.activeSelf) instance.gameObject.SetActive(true); return instance; } } }