public abstract class GenericSingleTon<T> : MonoBehaviour where T : MonoBehaviour
{
private static T _instance;
public static T instance
{
get
{
if (_instance == null)
{
T[] objectList = Resources.FindObjectsOfTypeAll<T>();
if (objectList.Length > 0)
(objectList[0] as GenericSingleTon<T>).Awake();
}
return _instance;
}
}
private void Awake()
{
if (_instance == null)
_instance = this as T;
}
}
'Unity' 카테고리의 다른 글
[Unity/Event] 변수 변경시 정해진 이벤트 호출하기 (0) | 2020.10.19 |
---|---|
[Unity] Generic DontDestroyOnLoad (0) | 2020.10.05 |
[Unity/UI] Image로 Fade In, Fade Out 효과 (2) | 2020.10.05 |
[Unity/UI] 유저가 정해진 버튼만 클릭할 수 있게 하기 (0) | 2020.08.26 |
[Unity/UI] RectTransform 정리 (0) | 2020.08.26 |