Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Singleton<T> : BaseBehaviour where T : MonoBehaviour
- {
- protected static T _instance;
- /**
- Returns the instance of this singleton.
- */
- public static T Instance
- {
- get
- {
- if (_instance == null)
- {
- _instance = (T)FindObjectOfType(typeof(T));
- if (_instance == null)
- {
- var o = new GameObject("#Singleton<" + typeof(T).Name + ">");
- _instance = o.AddComponent<T>();
- }
- }
- return _instance;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement