11 private static MonoBehaviour _instance;
34 T[] scene = FindObjectsOfType<T>();
36 if(scene !=
null && scene.Length > 0)
40 for(
int i = 1; i < scene.Length; i++)
42 pb_ObjectUtility.Destroy(scene[i]);
47 GameObject go =
new GameObject();
48 string type_name = typeof(T).ToString();
49 int i = type_name.LastIndexOf(
'.') + 1;
50 go.name = (i > 0 ? type_name.Substring(i) : type_name) +
" Singleton";
51 T inst = go.AddComponent<T>();
54 _instance = (MonoBehaviour) inst;
58 Object.DontDestroyOnLoad(_instance.gameObject);
70 get {
return (T) _instance; }
83 Object.DontDestroyOnLoad(_instance.gameObject);
87 pb_ObjectUtility.Destroy(this.gameObject);
virtual void Initialize()
virtual bool dontDestroyOnLoad
Override to maintain an instance of this object across level loads.
static T nullableInstance