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

[Day 12-1] 정치 법 변경 적용 완료

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

[2021. 07. 23, Fri]

 

▼Measure (제도)

제도 클라스는 국가의 법 상태를 보유하고있다.

Measure class contains the whole status of laws of a country.

 

 

 

플레이어 국가의 전체적인 법, 경제 정보를 갖고있을 클래스를 하나 만들었다.

I made a class which holds the data as to the meausre and financial status of Player Nation.

 

 

1. 플레이어가 국가를 선택하고 게임 시작을 했을 때 한 번 실행된다. 그리고 선택한 국가에 따른 초기 법 설정을 해준다.

1. it works once when player start the game with nation selected.

   + Dipose the default values of measure depending on what country he chose.

한국 선택시 (Korea)
중국 (China)
인도(India)

 

정치 UI에서 법 개정 UI를 열었을 때 해당 국가의 현재 법 상황을 보여줘야한다. 그러므로 현재 법 상태에 따른 Value 값을 반환해줘야한다.

Player gotta see current status when he stepped in Law Revising. So I made the func below to return values.

 

실험용
성공했다. 합법=0, 불법=1
UI에서 각각의 법을 바꿀때 tempMeasure에 바꾼 값이 저장된다.

 

LawRevising(bool confirm);

위의 두 함수는 플레이어가 UI에서 법을 막 바꿔놓고 취소를 눌렀을 때 tempMeasure 값을 다시 기존의 값으로 초기화 시키는 것이다.

the role of two funcs above is to default tempMeausre's values after player turn off the Measure UI.

 

그런데 문제가 있다. UI에서 나갔는데도 내가 수정한 값이 그대로 저장되어있는 것이다.

but ive got an issue that tempMeasure is holding values I changed even when I canceled.

 

디버깅을 통해 원인을 파악했다. 플레이어가 법을 수정을 할 때 실제 법 까지 바뀌는 것이다.

i figured out the cause that tempMeasure is connected with nationStat.(still dunno why btw)

 

class -> struct 실험
struct로 바뀌니깐 적용이 되었다.

솔직히 지금도 좀 이해가 안간다. 깊은 복사와 얕은 복사의 개념은 내가 인자로 받은 변수의 값을 바꿀려고 할 때 

적용되는 개념이고, 실제 법을 바꿔주는 함수 또한 실행되지 않았었다.

it's way frustrating 'cause I reckon the difference of Deep Copy from Shallow Copy is the thing I need to concern only when Im about to change the parameter values... Neither the func that changes nationStas' values even didnt work. I feel like i need to study more.

 

[+ 이 때 얕은 복사에 대해 덜 공부가 되어있는 상태였다. 글 밑에 다시 공부하여 struct -> class로 바꾸고 nationStat.LawRevise()함수에 인자로 새로운 법 클라스를 만들어서 넣어줬다.]

: struct 대신 class를 계속 사용하려고 했던 이유가 있다. struct로 두면 스택 메모리에 할당이되므로 가비지 컬렉터의 수집 대상이 아니라서 좋긴 하지만, 일단 변수의 크기가 크다. 그리고 Measure의 현재 상태를 담아 리스트로 반환하는 메서드 또한 추가해줘야한다. 이러한 변수를 모든 나라 별로 하나 씩 가지고 있는데 스택 메모리에 할당하는 것이 부적합할 것같다는 개인적인 생각으로 (정답이 아닐 수 있음) 꼭 힙 메모리에 할당하고싶었다. struct는 추후에 경제 안정성, 정치 안정성에 구현할 계획이다.

 

 

[ 코드 실행 순서 Working Order Review]

1. 플레이어가 국가를 선택했을 때 해당 국가의 초기 법 정보를 받아온다.

1. Get datas of default values in Measure depending on country that Player chose.

 

2. 법 개정 UI를 열었을 때 현재 법 현황을 알려준다.

2. Show the current status of laws.

3. 플레이어가 법을 설정하는 것은 실제 법이 아닌 임시 법이다.

3. Chaing values of dropdown lead to the same interaction with TempMeasure, not real measure.

 

4. UI를 끈다면 tempmeasure 값은 기존의 법으로 변경된다.

4. Imposes default values in the Measure class when Player cancels the changes.

PlayerManager -> LawRevising()

 

 

 

5. UI에서 confirm 을 누른다면 변경한 값으로 실제 제도가 바뀐다.

5. Once confirmed, the real measure is changed with values that Player has set in advance

 

 

이제는 실행이 잘 된다.

Now it works well with no issue.

 

 

[+ 수 정 ]

 ㅋㅋㅋㅋㅋㅋㅋ 너무 부끄럽다; 얕은 복사로 계속 하고있어놓고 왜 계속 안될까 했었다.. 

What a shame.. I was humiliating myself wondering why it was not working even though I did 'Shallow Copy' lol

 

 

얕은 복사 -> 깊은 복사로 바꿔서 성공했다. 

728x90