์›๋ฌธ : https://gall.dcinside.com/mgallery/board/view/?id=game_dev&no=28980&page=1

๋‹ค๋ฅธ ์งˆ๋ฌธ๊ธ€ : https://stackoverflow.com/questions/55296300/i-have-a-question-about-the-error-that-occurs-when-i-add-a-generic-based-class-t


Singleton์—์„œ _Instance์— AddComponent() ๋ฅผ ํ•  ๋•Œ ์ตœ์ƒ์œ„ ๋ถ€๋ชจ ํด๋ž˜์Šค๋ฅผ ์ฐธ์กฐํ•˜๋Š”๊ฒŒ ์•„๋‹Œ

PoolingManagerBaseย ๋ฅผ ๋ฐ”๋กœ ์ฐธ์กฐํ•ด์„œ ๋ฌธ์ œ๊ฐ€ ์ƒ๊ธด๊ฑฐ์˜€๋„ค์š”..


PoolingManagerBase๋Š” ์ œ๋„ค๋ฆญ ๊ธฐ๋ฐ˜์ด๊ณ  ์œ ๋‹ˆํ‹ฐ์—์„  ์ œ๋„ค๋ฆญ ๊ธฐ๋ฐ˜ ์ปดํฌ๋„ŒํŠธ๋Š” ์ง€์›ํ•˜์ง€ ์•Š์œผ๋‹ˆ

AddComponent(System.Type)์˜ ํ˜•ํƒœ๋กœ ์‚ฌ์šฉํ•ด์•ผ ์˜๋„ํ•œ ๋Œ€๋กœ ๋™์ž‘ํ–ˆ์–ด์š”


๋ฐ”๋€ Singleton ํด๋ž˜์Šค์˜ ์ฝ”๋“œ๋Š” ์•„๋ž˜์ฒ˜๋Ÿผ ์ ์—ˆ์Šต๋‹ˆ๋‹ค


public abstract class Singleton < T> : CComponent where T : MonoBehaviour { private static T _Instance = null; private static Type _InstanceType = null; public static T Instance { get { if (_Instance == null) { GameObject gObject = new GameObject(typeof(T).ToString()); _Instance = gObject.AddComponent(_InstanceType) as T; DontDestroyOnLoad(gObject); } return _Instance; } } public static T Create(Type tType) { _InstanceType = tType; return Instance; } }

์‹ฑ๊ธ€ํ†ค์˜ Instance ์ฐธ์กฐ ์ „์— Create(typeof(T))๋ฅผ ๋จผ์ € ์จ์•ผํ•˜๋Š” ๋ฒˆ๊ฑฐ๋กœ์›€์ด ์žˆ์ง€๋งŒ


๊ฒฐ๊ณผ์ ์œผ๋กœ ๋ฌธ์ œ๋Š” ํ•ด๊ฒฐ ๋˜์—ˆ์–ด์š”!