public GameObject testPrefab;
IObjectPool<GameObject> testPool;
void Awake()
{
// defaultSize, double-release 방지, maxSize도 설정 가능
testPool = new ObjectPool<GameObject>(CreateItem, OnGet, OnRelease, OnDestroyItem);
}
// 풀에서 새 아이템 필요할 때 호출됨
private GameObject CreateItem() { return Instantiate(testPrefab); }
private void OnGet(GameObject gameObject) { gameObject.SetActive(true); }
private void OnRelease(GameObject gameObject) { gameObject.SetActive(false); }
private void OnDestroyItem(GameObject gameObject) { Destroy(gameObject); }
유니티 내장 오브젝트 풀링 시스템
private void OnGet(GameObject gameObject)
{
gameObject.SetActive(true);
StartCoroutine(CoRelease(gameObject));
}
private IEnumerator CoRelease(GameObject gameObject)
{
yield return new WaitForSeconds(1f);
testPool.Release(gameObject);
}
void Update()
{
if (Input.GetKeyDown(KeyCode.F))
{
testPool.Get();
}
}
Get Release 테스트해본 코드
https://www.youtube.com/watch?v=Fj2DeO31oF4
(30분 ~ 끝)
Rpc : 다른 이에게 어떤 것을 실행하라 명령 혹은 지시
ServerRpc : Client -> Server
ObserverRpc : Server -> All Clients
TargetRpc : Server -> Single client
보통 클라가 특정 클라에게 어떤 행동 하게 하려면
Client -> ServerRpc -> TargetRpc
ObserverRpc는 host에는 전달되지만 dedi server에는 전달 안된다
SyncVar는 server auth (서버만 변경 가능)
클라가 Owner여도 서버에 요청해야 결과 받을 수 있다
클라가 직접 다른 클라에 뿌리면 반응은 빠르지만 치팅에 취약
서버 불안정 극복 방법
수직적 확장
수평적 확장
성능만 좋고 확장성 나쁘면 사용자 수 늘어날수록 연산 처리 시간 오래 걸림
확장성만 좋으면 게임 사용자 수 상관 없이 처리 시간 일정하게 큼
게임 서버 성능 높이기
서버 관리 도구
데이터베이스 소프트웨어 장점