Commit fda84f05 authored by 15박보승's avatar 15박보승

SingletonBehaviour 추가

parent e098f997
fileFormatVersion: 2
guid: 5bc10e17adc09f34d8d61ffefb655889
guid: 0157d683def24ef4cabaa85d3d4dae38
folderAsset: yes
DefaultImporter:
externalObjects: {}
......
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SingletonBehaviour<T> : MonoBehaviour where T : MonoBehaviour
{
private static T _inst = null;
public static T inst
{
get
{
if (_inst == null)
{
if (FindObjectsOfType<T>().Length > 1)
Debug.LogError("More than one");
else if (FindObjectOfType<T>() != null)
_inst = FindObjectOfType<T>();
else
{
GameObject go = new GameObject();
go.name = typeof(T).Name;
_inst = go.AddComponent<T>();
}
}
return _inst;
}
}
public void SetStatic()
{
if (_inst != null)
DontDestroyOnLoad(_inst.gameObject);
}
}
fileFormatVersion: 2
guid: 0f664c2cd668e604ca073ee9f5635893
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment