You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
27 lines
430 B
27 lines
430 B
using UnityEngine; |
|
|
|
namespace Utils |
|
{ |
|
public class MonoSingleton<T> : MonoBehaviour where T : MonoSingleton<T> { |
|
|
|
private static T _instance; |
|
|
|
public static T Instance |
|
{ |
|
get |
|
{ |
|
if (_instance == null) |
|
{ |
|
var gobj = new GameObject(typeof(T).ToString()); |
|
_instance = gobj.AddComponent<T>(); |
|
_instance.Init(); |
|
} |
|
return _instance; |
|
} |
|
} |
|
|
|
protected virtual void Init() |
|
{ |
|
} |
|
} |
|
}
|
|
|