2024/02/03 3

Section 11. Coroutine

코루틴을 사용하면 이전에 함수에서 진행 중이던 상황을 저장했다가 복원하여 그대로 이어서 수행하게 할 수 있다 * yield break; 를 하게 되면 함수를 완전히 빠져나오게 된다 // 코루틴 사용 예 StartCoroutine("CoExplodeAfterSeconds", 4.0f); IEnumerator CoExplodeAfterSeconds(float seconds) { Debug.Log("Explode Enter"); yield return new WaitForSeconds(seconds); Debug.Log("Explode Execute!"); } // 코루틴 사용 및 삭제 Coroutine co = StartCoroutine("CoExplodeAfterSeconds", 4.0f); StartCo..

Section 10. Object Pooling - Pool Manager

오브젝트를 재사용 하기 위해 pool을 사용한다(소규모 게임에서는 굳이 필요 없으나, 규모가 커지고 성능을 높여야 할 때 유용) 풀링할 객체 vs 안 할 객체 구분법 : 특정 컴포넌트의 존재 여부로 판단한다 Assets > Scripts > Managers > Poolable.cs public class Poolable : MonoBehaviour { public bool isUsing; } 객체를 구별하는 용도의 컴포넌트로 사용한다 Assets > Scripts > Managers > PoolManager.cs (Resource Manager를 보조하는 역할로 사용) public class PoolManager { class Pool { public GameObject Original { get; pr..

Section 9. Sound - Sound Manager(2)

Effect의 경우, 같은 effect를 여러 번 불러오게 되면, 불러올 때마다 manager를 호출하는 게 부하를 줄 수 있으므로 캐싱을 해둔다 public class SoundManager { Dictionary _audioClips = new Dictionary(); public void Init() { // Init } // Scene 이동 시 캐싱된 audio source&clip 초기화 public void Clear() { foreach (AudioSource audioSource in _audioSources) { audioSource.clip = null; audioSource.Stop(); } _audioClips.Clear(); } public void Play(string path,..