본문 바로가기
VR 팀프로젝트/[GroundZero] 제작 일지

GroundZero 제작일지 - Lobby Scene 데이터 연동 및 연출 R&D

by 잰쟁 2023. 12. 27.
728x90

 

▼구현할 부분 - LobbyScene : Upgrades 창

 

 

▼구현할 목록

-  각 아이콘 버튼을 누른 후 Upgrade 버튼을 누르면 그에 해당하는 데이터 업데이트 시키기(데이터 연동)

 

   → Upgrade 버튼을 누를때 마다 레벨이 증가하고, 증가한 레벨에 따라 upgrade에 필요한 재화가 달라짐

       (LV_1: 5000  /  LV_2 : 10000  /  LV_3 : 150000  /  LV_4 : 20000  /  LV_5이상(만렙) : FULLY UPGRADE)

 

-  각 아이콘 버튼을 누르면 그에 해당하는 upgrade 이름과 내용 UI로 보여주기

   → 1~6번 : 업그레이드 버튼 /  7~9번 : Locked 버튼


 

▼ 각 업그레이드 버튼 누르면 업그레이드 이름과 설명 보여주기

TestUI Scene 생성하여 아래와 같이 구성잡기

 

- UpgradeScreen

   - title_txt : UPGRADE 창 이름

   - description : 업그레이드 버튼에 대한 이름 및 업그레이드 내용 설명

   - upgradeBtn : 업그레이드를 시켜주는 버튼

   - grid : 업그레이드 버튼들

 

 

- JSON 파일 만들어주기

  - upgradeData : upgrade 이름 및 내용

  - upgradeAmountData : upgrade의 변경값

 

upgradeData                                                                                             upgradeAmountData

 

 

 

 

TestUIMain1 스크립트

 

void Start()
{
	for (int i = 0; i < upgradebtns.Length; i++)
    {
        int index = i;
	//..레벨이 6보다 크면 LOCKED창 활성화 
        if (index >= 6)
        {
            upgradebtns[index].onClick.AddListener(() =>
            {
                this.upgradeName_txt.text = null;
                this.locked.SetActive(true);
                this.description.SetActive(false);
                this.selectedBtn = upgradebtns[index];
            });
        }
        
        //..레벨이 6이하이면 설명창 활성화
        else if (index <= 5)
        {
            upgradebtns[index].onClick.AddListener(() =>
            {
                this.locked.SetActive(false);
                this.description.SetActive(true);
                this.upgradeName_txt.text = upgradeData[index].name;

                //..아이콘 이미지 버튼을 누를때 마다 각 Desc에 업그레이드 값 넣어서 보여주기
                for(int i = 0; i < 4; i++)
                {
                    string desc = string.Format(upgradeData[index].desc, this.dic1[index][i]);
                    Debug.LogFormat("<color=green>{0}</color>",desc);
                    upgradeDesc_txt[i].text = desc;
                    Debug.Log(upgradeDesc_txt[i].text);                            
                }                                                   

                this.scrapAmount_txt.text = this.scrap.ToString();
                this.selectedBtn = upgradebtns[index];
            });
        }
    }

}

 

 

▼ 중간 완성 : 버튼 누르면 업그레이드 내용 보여주기, Lock 되어있는 것은 LOCKED 글자 보여주기

 

 


▶ 각 업그레이드 버튼의 레벨에 따라 필요한 재화값 및 데이터 변경해주기

 

위에서 upgrade 변경값을 json으로 만들어 주었지만... 사용하기 어려울 것 같아 우선은

각 버튼마다 변경값이 다 달라서 우선 각자 배열로 만들어 준 후 사전에 담아 꺼내서 쓰는 방식으로 구현해보았다.

(json으로 만든 파일은 이후에 사용함!!)

 

레벨 6이하인 부분에 아래와 같이 레벨별로 재화값을 변경해주도록 수정해보았다.

 

 

void Start()
{
	//..사전에 배열 넣어주기 (key값: int)
	dic1.Add(0, this.arrPlayerHealth);
    dic1.Add(1, this.arrDamage);
    dic1.Add(2, this.arrHealAmount);
    dic1.Add(3, this.arrCanAmount);
    dic1.Add(4, this.arrShieldPower);
    dic1.Add(5, this.arrScrapAmount);

    //..시작시 레벨을 1로 맞추기
    for (int i = 0; i <level.Length; i++)
    {
        this.level[i] = 1;
    }

    DataManager.Instance.LoadUpgradeData();

    List<UpgradeData> upgradeData = DataManager.Instance.GetUpgradeDatas();

    //-----------------------------LJE----------------------------------
    DataManager.Instance.LoadUpgradeAmountData();

    listUpgradeAmountData = DataManager.Instance.GetUpgradeAmountDatas();


    for (int i = 0; i < upgradebtns.Length; i++)
    {
        int index = i;

        if (index >= 6)
        {
            upgradebtns[index].onClick.AddListener(() =>
            {
                this.upgradeName_txt.text = null;
                this.locked.SetActive(true);
                this.description.SetActive(false);
                this.selectedBtn = upgradebtns[index];
            });
        }
        else if (index <= 5)
        {
            upgradebtns[index].onClick.AddListener(() =>
            {
                this.locked.SetActive(false);
                this.description.SetActive(true);

                //..레벨에 따라서 scrap값 및 UI 텍스트 변경
                if (this.level[index] == 1)
                {
                    this.scrap = 5000;
                    this.NotFullUpgrade();
                }
                else if (this.level[index] == 2)
                {
                    this.scrap = 10000;
                    this.NotFullUpgrade();              
                }
                else if (this.level[index] == 3)
                {
                    this.scrap = 15000;
                    this.NotFullUpgrade();
                }
                else if (this.level[index] == 4)
                {
                    this.scrap = 20000;
                    this.NotFullUpgrade();
                }
                else if (this.level[index] > 4)
                {
                    this.FullUpgrade();
                }

                this.upgradeName_txt.text = upgradeData[index].name;

                //..아이콘 이미지 버튼을 누를때 마다 각 Desc에 업그레이드 값 넣어서 보여주기
                for(int i = 0; i < 4; i++)
                {
                    string desc = string.Format(upgradeData[index].desc, this.dic1[index][i]);
                    Debug.LogFormat("<color=green>{0}</color>",desc);
                    upgradeDesc_txt[i].text = desc;
                    Debug.Log(upgradeDesc_txt[i].text);                            
                }                                                   

                this.scrapAmount_txt.text = this.scrap.ToString();
                this.selectedBtn = upgradebtns[index];
            });
        }
    }

}

 

 

업그레이드 버튼을 눌렀을 때 레벨에 맞게 데이터 값 변경

//...upgradeBtn 버튼 누르면 실행
    public void OnClick()
    {
        //선택한 버튼이 첫 번째 버튼일 때
        if (this.selectedBtn == upgradebtns[0])
        {
            //레벨에 따라 데이터 값이 변경
            if (this.level[0] == 1)
            { 
                playerData.playerHp += listUpgradeAmountData[0].level_1;
                Debug.LogFormat("<color=black>{0}</color>", playerData.playerHp);
                this.level[0]++;
            }
            else if (this.level[0] == 2)
            {
                playerData.playerHp += listUpgradeAmountData[0].level_2;
                Debug.LogFormat("<color=black>{0}</color>", playerData.playerHp);
                this.level[0]++;
            }
            else if (this.level[0] == 3)
            {
                playerData.playerHp += listUpgradeAmountData[0].level_3;
                Debug.LogFormat("<color=black>{0}</color>", playerData.playerHp);
                this.level[0]++;
            }
            else if (this.level[0] == 4)
            {
                playerData.playerHp += listUpgradeAmountData[0].level_4;
                Debug.LogFormat("<color=black>{0}</color>", playerData.playerHp);
                Debug.Log(this.level[0]);
                this.level[0]++;
            }
        }
        else if (this.selectedBtn == upgradebtns[1])
        {
            if (this.level[1] == 1)
            {
                Debug.LogFormat("<color=red>{0}</color>", playerData.currGunId);
                var a = (double)(listUpgradeAmountData[1].level_1) / 100 * dicGunData[playerData.currGunId].gunDamage;
                dicGunData[playerData.currGunId].gunDamage += (int)a;
                Debug.LogFormat("<color=yellow>{0}</color>", dicGunData[playerData.currGunId].gunDamage);
                this.level[1]++;
            }
            else if (this.level[1] == 2)
            {
                var a = (double)(listUpgradeAmountData[1].level_2) / 100 * dicGunData[playerData.currGunId].gunDamage;
                dicGunData[playerData.currGunId].gunDamage += (int)a;
                Debug.LogFormat("<color=yellow>{0}</color>", dicGunData[playerData.currGunId].gunDamage);
                this.level[1]++;
            }
            else if (this.level[1] == 3)
            {
                var a = (double)(listUpgradeAmountData[1].level_3) / 100 * dicGunData[playerData.currGunId].gunDamage;
                dicGunData[playerData.currGunId].gunDamage += (int)a;
                Debug.LogFormat("<color=yellow>{0}</color>", dicGunData[playerData.currGunId].gunDamage);
                this.level[1]++;
            }
            else if (this.level[1] == 4)
            {
                var a = (double)(listUpgradeAmountData[1].level_4) / 100 * dicGunData[playerData.currGunId].gunDamage;
                dicGunData[playerData.currGunId].gunDamage += (int)a;
                Debug.LogFormat("<color=yellow>{0}</color>", dicGunData[playerData.currGunId].gunDamage);
                level[1]++;
            }
        }
        else if (this.selectedBtn == upgradebtns[2])
        {
            if (this.level[2] == 1)
            {
                listUpgradeObjectData[0].healGauge += listUpgradeAmountData[2].level_1;
                Debug.Log(listUpgradeObjectData[0].healGauge);
                this.level[2]++;
            }
            else if (this.level[2] == 2)
            {
                listUpgradeObjectData[0].healGauge += listUpgradeAmountData[2].level_2;
                Debug.Log(listUpgradeObjectData[0].healGauge);
                this.level[2]++;
            }
            else if (this.level[2] == 3)
            {
                listUpgradeObjectData[0].healGauge += listUpgradeAmountData[2].level_3;
                Debug.Log(listUpgradeObjectData[0].healGauge);
                this.level[2]++;
            }
            else if (this.level[2] == 4)
            {
                listUpgradeObjectData[0].healGauge += listUpgradeAmountData[2].level_4;
                Debug.Log(listUpgradeObjectData[0].healGauge);
                this.level[2]++;
            }
        }
        else if (this.selectedBtn == upgradebtns[3])
        {
            if (this.level[3] == 1)
            {
                listUpgradeObjectData[0].amount = listUpgradeAmountData[3].level_1;
                Debug.Log(listUpgradeObjectData[0].amount);
                this.level[3]++;
            }
            else if (this.level[3] == 2)
            {
                listUpgradeObjectData[0].amount = listUpgradeAmountData[3].level_2;
                Debug.Log(listUpgradeObjectData[0].amount);
                this.level[3]++;
            }
            else if (this.level[3] == 3)
            {
                listUpgradeObjectData[0].amount = listUpgradeAmountData[3].level_3;
                Debug.Log(listUpgradeObjectData[0].amount);
                this.level[3]++;
            }
            else if (this.level[3] == 4)
            {
                listUpgradeObjectData[0].amount = listUpgradeAmountData[3].level_1;
                Debug.Log(listUpgradeObjectData[0].amount);
                this.level[3]++;
            }
        }
        else if (this.selectedBtn == upgradebtns[4])
        {
            if (this.level[4] == 1)
            {
                var gauge = (double)(listUpgradeAmountData[5].level_1) / 100 * playerData.shiledGauge;
                playerData.shiledGauge += (int)gauge;
                Debug.Log(playerData.shiledGauge);
                this.level[4]++;
            }
            else if (this.level[4] == 2)
            {
                var gauge = (double)(listUpgradeAmountData[5].level_2) / 100 * playerData.shiledGauge;
                playerData.shiledGauge += (int)gauge;
                Debug.Log(playerData.shiledGauge);
                this.level[4]++;
            }
            else if (this.level[4] == 3)
            {
                var gauge = (double)(listUpgradeAmountData[5].level_3) / 100 * playerData.shiledGauge;
                playerData.shiledGauge += (int)gauge;
                Debug.Log(playerData.shiledGauge);
                this.level[4]++;
            }
            else if (this.level[4] == 4)
            {
                var gauge = (double)(listUpgradeAmountData[5].level_4) / 100 * playerData.shiledGauge;
                playerData.shiledGauge += (int)gauge;
                Debug.Log(playerData.shiledGauge);
                this.level[4]++;
            }
        }
        else if (this.selectedBtn == upgradebtns[5])
        {
            if (this.level[5] == 1)
            {
                var amount = (double)(listUpgradeAmountData[5].level_1) / 100 * listUpgradeObjectData[1].amount;
                listUpgradeObjectData[1].amount += (int)amount;
                Debug.Log(listUpgradeObjectData[1].amount);
                this.level[5]++;
            }
            else if (this.level[5] == 2)
            {
                var amount = (double)(listUpgradeAmountData[5].level_2) / 100 * listUpgradeObjectData[1].amount;
                listUpgradeObjectData[1].amount += (int)amount;
                Debug.Log(listUpgradeObjectData[1].amount);
                this.level[5]++;
            }
            else if (this.level[5] == 3)
            {
                var amount = (double)(listUpgradeAmountData[5].level_3) / 100 * listUpgradeObjectData[1].amount;
                listUpgradeObjectData[1].amount += (int)amount;
                Debug.Log(listUpgradeObjectData[1].amount);
                this.level[5]++;
            }
            else if (this.level[5] == 4)
            {
                var amount = (double)(listUpgradeAmountData[5].level_4) / 100 * listUpgradeObjectData[1].amount;
                listUpgradeObjectData[1].amount += (int)amount;
                Debug.Log(listUpgradeObjectData[1].amount);
                this.level[5]++;
            }
        }
    }

 


오류 발생

 

 

- JSON파일을 역직렬화 하는 과정에서 오류가 하나 발생했다..

- 스크립트를 자세히 보니 어이없는 실수를 하였다,,ㅎ,,

변경 전

 

- using Newtonsoft.Json; 을 추가하지 않고 역직렬화를 하려고 했다.

- 다른 using Meta.WitAi.Json;이 자동으로 추가되어서 별다른 스크립트 오류가 나지 않아 발견이 늦었다ㅜㅡㅜ

변경 후

 

원래대로 using Newtonsoft.Json;를 추가하고 실행한 결과 로그가 잘 나온다~!