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.
67 lines
1.4 KiB
67 lines
1.4 KiB
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
namespace UltraCombos
|
|
{
|
|
public abstract class Singleton<T> : MonoBehaviour where T : Component
|
|
{
|
|
|
|
#region Fields
|
|
|
|
/// <summary>
|
|
/// The instance.
|
|
/// </summary>
|
|
private static T instance;
|
|
|
|
#endregion
|
|
|
|
#region Properties
|
|
|
|
/// <summary>
|
|
/// Gets the instance.
|
|
/// </summary>
|
|
/// <value>The instance.</value>
|
|
public static T Instance
|
|
{
|
|
get
|
|
{
|
|
if (instance == null)
|
|
{
|
|
instance = FindObjectOfType<T>();
|
|
if (instance == null)
|
|
{
|
|
GameObject obj = new GameObject();
|
|
obj.name = typeof(T).Name;
|
|
instance = obj.AddComponent<T>();
|
|
}
|
|
}
|
|
return instance;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Methods
|
|
|
|
/// <summary>
|
|
/// Use this for initialization.
|
|
/// </summary>
|
|
protected virtual void Awake()
|
|
{
|
|
if (instance == null)
|
|
{
|
|
instance = this as T;
|
|
DontDestroyOnLoad(gameObject);
|
|
}
|
|
else
|
|
{
|
|
Destroy(gameObject);
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
}
|
|
}
|
|
|
|
|