12345678910111213141516171819202122232425262728293031 |
- using System.Collections;
- using UnityEngine;
- namespace GFGGame.Launcher
- {
- public class SingletonMonoBase <T> : MonoBehaviour where T : SingletonMonoBase<T>
- {
- private static T _intance;
- public static T Instance
- {
- get
- {
- if (_intance == null)
- {
- GameObject gObj = GameObject.Find("SingletonObject");
- if(gObj == null)
- {
- gObj = new GameObject("SingletonObject");
- }
- _intance = gObj.GetComponent<T>();
- if(_intance == null)
- {
- _intance = gObj.AddComponent<T>();
- }
- }
- return _intance;
- }
- }
- }
- }
|