๐ŸŽฎUnity

[Unity] ์‹ค์Šต_ObjectPool

taesooya 2022. 7. 31.

ObjectPool

  • ๋ฉ”๋ชจ๋ฆฌ ๋‹จํŽธํ™”/ํŒŒํŽธํ™” Memory Fragmentation ํ˜„์ƒ ๋ฐœ์ƒ ⇒
GameObject factory = Resources.Load<GameObject>(name); //Generic
GameObject factory = (GameObject)Resources.Load(name); //Typecast
GameObject factory = Resources.Load(name) as GameObject;
  • ์ž๋ฃŒ๊ตฌ์กฐ
    • ๋ฐฐ์—ด : ์—ฐ์†๋œ ๊ณต๊ฐ„
      • 1์ฐจ์› ๋ฐฐ์—ด, 2์ฐจ์› ๋ฐฐ์—ด, 3์ฐจ์› ๋ฐฐ์—ด ...
      • index
      int[] a = new int[5];
              for (int i = 0; i < a.Length; i++)
              {
                  a[i] = 0;
              }
      
    • ๋ฆฌ์ŠคํŠธ :
      • index
      int count = 5;
              List<int> list = new List<int>();
              for (int i = 0; i < count; i++)
              {
                  list.Add(0);
              }
      // list.insert
      // list.Remove
      // list.Removeat
      
      • value type - ๊ฐ’ ํ˜•์‹
      • reference type - ์ฐธ์กฐ ํ˜•์‹ (์ฃผ์†Œ ๊ธฐ์–ต)
    • ํ•ด์‹œ
      • index ์ •๋ณด(์ •์ˆ˜, ๋ฌธ์ž etc.) → ๊ฐ€๊ณต(ํ•ด์‹œํ•จ์ˆ˜) → ๋ฒˆํ˜ธ๋กœ ๋ฝ‘์•„ ๋ƒ„

 

HACKS
๐Ÿ’ก Alt + Enter ⇒ Generate Method
๐Ÿ’ก Ctrl + Click ⇒ Move to Method
๐Ÿ’ก internal - Public in same assembly / private in different assembly

 

 

๋Œ“๊ธ€