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.
61 lines
828 B
61 lines
828 B
using UnityEngine;
|
|
|
|
namespace UltraCombos
|
|
{
|
|
public abstract class Singleton<T> : MonoBehaviour where T : Component
|
|
{
|
|
|
|
#region Fields
|
|
|
|
private static T instance;
|
|
|
|
[SerializeField]
|
|
private bool persistance = true;
|
|
|
|
#endregion
|
|
|
|
#region Properties
|
|
|
|
public static T Instance
|
|
{
|
|
get
|
|
{
|
|
if (instance == null)
|
|
{
|
|
instance = FindFirstObjectByType<T>();
|
|
if (instance == null)
|
|
{
|
|
var go = new GameObject();
|
|
go.name = typeof(T).Name;
|
|
instance = go.AddComponent<T>();
|
|
}
|
|
}
|
|
return instance;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Methods
|
|
|
|
protected virtual void Awake()
|
|
{
|
|
if (instance == null)
|
|
{
|
|
instance = this as T;
|
|
if (persistance)
|
|
{
|
|
DontDestroyOnLoad(gameObject);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
Destroy(gameObject);
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
}
|
|
|
|
}
|
|
|