summaryrefslogtreecommitdiff
path: root/Assets/Scripts/Utils/Singleton.cs
blob: a882238a2cf690a13882c1bf0c9a9cfb0e468486 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

using System;

public class SingletonMB<T> : MonoBehaviour where T : class
{
    protected static T s_Instance;
    public static T Instance
    {
        get { return s_Instance; }
    }

    protected virtual void Awake()
    {
        s_Instance = gameObject.GetComponent(typeof(T)) as T;
    }

}

public class Singleton<T> where T : class, new()
{
    private static T _instance;

    public static T Instance
    {
        get
        {
            if (_instance == null)
                _instance = Activator.CreateInstance<T>();
            return _instance;
        }
    }
}