1234567891011121314151617181920212223 |
- using System;
- using UnityEngine;
- public class SingletonBase<T> : MonoBehaviour where T : MonoBehaviour
- {
- public static T Instance
- {
- get
- {
- if (SingletonBase<T>.instance == null)
- {
- SingletonBase<T>.instance = (T)((object)UnityEngine.Object.FindObjectOfType(typeof(T)));
- if (SingletonBase<T>.instance == null)
- {
- Debug.LogError("An instance of " + typeof(T) + " is needed in the scene, but there is none.");
- }
- }
- return SingletonBase<T>.instance;
- }
- }
- private static T instance;
- }
|