본문 바로가기
개발 (Game)/(2021) Unity RTS 포트폴리오

[Day 17] LinQ+람다를 활용한 국방력 순위 및 일반화 오브젝트 풀링 유닛 구매 구현

by 진현개발일기 2021. 7. 29.

[2021. 07. 19, Thu]

 

[오늘 한 일]

let me run through the works ive done today

1. 국가마다 병종 별 보유 하는 유닛의 수를 비교하여 국방력 순위를 표시했다. (Linq + 람다식 활용)

   (Ranked all of nations among one another pursuant to the number of personnels with 3 MOS)

     *MOS = Military Occupational Specialty.

 

2. 국방UI에서 유닛을 구매할 수 있다. (제너릭 오브젝트 풀링 활용)

   (You can conscript able-bodied in the nation via Military UI)

[국가 스크립트. WorldBuilding.cs]

 

플레이어를 포함한 모든 나라의 병종별 국방력 순위를 구현하기 위해 랭크매니저 스크립트를 만들었다.

In order to handle the ranks of conventional forces per MOS among all the other nations by the number of personnels, ive come up with a script RankManager.cs.

[랭크관리자. RankManager.cs]

 

구조는 이렇다. 모든 국가들은 Start 이벤트 함수에서 게임매니저에 있는 액션에 체인을 걸어준다.

This is how it works, every nations kicks off with chaining to an Action Func, which is in charge of making a head count of personnels, that exsits in GameManager.cs

 

적의 턴이 끝나면 모든 국가들은, 방금 체인을 걸었던, 자국의 병종별 유닛 숫자를 계산하는 함수를 실행하고

Once the enemies-turn over, the aforementioned func is played.

 

랭크 관리자에게 유닛의 숫자(스크립트 수가 아닌 부대 인원이다.) 데이터를 전송한다. 

Off the record, the head is not meaning of 'the number of the Scripts' but 'the number of Personnels' in PLT(or Battalion↑)

 

랭크 관리자에서는  딕셔너리<국가, 유닛 숫자>를 3개의 리스트(병사, 야포, 탱크)를 보유하고있는데 매 턴이 끝날 때마다 모든 국가들이 본인이 알아서, 방금 말했던 함수로, 자국의 유닛 수를 재설정해준다.

RankManager contains List<Dictionary<Nation, Head of Personnels>> that handle the ranks in 3 MOS of all nations and they are updated by themselves.

 

 

설정이 끝난다면 Linq기능 중 OrderByDescending을 통해 오름차순으로 정렬을 해준다.  확인을 해봤는데. 반환 자료형이 IOrderedEnumerable<KeyValuePair<국가, 유닛수>> 였다. 그래서 이 KeyValuePair들을 다시 딕셔너리 형태로 바꿔줘야해서 ToDictionary로 대입해줬다.

After update datas, those are sorted by descending making a use in one of Funcs in LinQ, OrderByDescending. Now that the return type is different from Dictionary, i had to use ToDictionary().

 

정렬된 딕셔너리에서 어떤 국가든 몇 번째 순위에 있는지 확인할 수 있도록 MyIndex라는 함수를 만들었다.

To check the rank of certain nation, ive come up with a Return func as well.

 

 

정렬 성공 전 1
정렬 성공 후1
정렬 성공 전 2
정렬 성공 후 2
GameManager.cs  Action 델리게이트다.
공동 숫자는 인덱스 순서대로 처리된다.

[군사 유닛 구매 UI]

[Purchasing Unit UI, conscription system]

오브젝트 풀링을 제너릭화하여서 사용하였다.
Conscription.cs (1)
Conscription.cs (2)

  ▲ 입력을 하고 있을 때 계속 실행이 되고있는 것이 아니라 숫자가 바뀔 때 한 번 씩만 실행되도록한다.

수량을 수정할 때만 실행된다.