Tanoda
pb_ScriptableObjectSingleton.cs
Go to the documentation of this file.
1using UnityEngine;
2
3namespace GILES
4{
8 public class pb_ScriptableObjectSingleton<T> : ScriptableObject where T : ScriptableObject
9 {
10 private static ScriptableObject _instance;
11
12 public static T instance
13 {
14 get
15 {
16 if(_instance == null)
17 {
18 _instance = (ScriptableObject) ScriptableObject.CreateInstance<T>();
19 }
20
21 return (T) _instance;
22 }
23 }
24
28 public static T nullableInstance
29 {
30 get { return (T) _instance; }
31 }
32
37 protected virtual void OnEnable()
38 {
39 if(_instance == null)
40 _instance = this;
41 else
42 pb_ObjectUtility.Destroy(this);
43 }
44 }
45}