프로젝트 Common 스크립트 추가

This commit is contained in:
aube.lee
2025-01-21 22:53:52 +09:00
parent 8c2341ff7e
commit 3bb9913d16
38 changed files with 1672 additions and 121 deletions

View File

@@ -0,0 +1,47 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
namespace TON
{
public class SingletonBase<T> : MonoBehaviour where T : class
{
public static T Singleton
{
get
{
return _instance.Value;
}
}
private static readonly Lazy<T> _instance = new Lazy<T>(() =>
{
T instance = FindObjectOfType(typeof(T)) as T;
if (instance == null)
{
GameObject obj = new GameObject(typeof(T).Name);
instance = obj.AddComponent(typeof(T)) as T;
#if UNITY_EDITOR
if (EditorApplication.isPlaying)
{
DontDestroyOnLoad(obj);
}
#else
DontDestroyOnLoad(obj);
#endif
}
return instance;
});
protected virtual void Awake()
{
DontDestroyOnLoad(gameObject);
}
}
}