열차 목업의 내부 확인용 프로젝트
smchoi
2024-07-24 ff74c0073046f0e086eb7d355950bda39937c92c
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 UnityEngine;
using System.Collections;
 
 
public abstract class Singleton<T> : MonoBehaviour where T : Singleton<T>
{
    private static T g_Instance = default(T);
    public static T Inst
    {
        get
        {
            if (g_Instance == null)
            {
                T t = GameObject.FindObjectOfType(typeof(T)) as T;
                g_Instance = t;
 
                if (t == null)
                {
                    string strName = typeof(T).ToString();
                    GameObject go = new GameObject(string.Format("[{0}]", strName));
                    g_Instance = go.AddComponent<T>();
                }
            }
 
            return g_Instance;
        }
 
        set { g_Instance = value; }
    }
 
    public virtual void Awake()
    {
        //DontDestroyOnLoad(this);
    }
}