-
[๊ตฌํ] ์ ๋ํฐ๋ก ์ฝ๊ฒ ์์ ๊ตฌํํ๊ธฐUNITY/PROJECT 2021. 12. 8. 18:39
https://dowlsovo.tistory.com/84
[๊ตฌํ] ์ฝ๊ฒ ์ธ๋ฒคํ ๋ฆฌ ๊ตฌํํ๊ธฐ 1
์ธ๋ฒคํ ๋ฆฌ์ ๋ฃ์ด์ผ ํ๋ ์์ดํ ๊ฐ์๊ฐ ์์ฃผ ๋ง์ง๋ ์์ ๊ฒฝ์ฐ ์ข์ ๋ฐฉ๋ฒ์ธ ๊ฒ ๊ฐ๋ค. 1. ์์ดํ ์ ๋ณด json์ ์ฅ ์์ดํ์ ๊ฒจ๋ฅํ์ฌ ์ด๋ ๊ฒ ์ผ๋๋ฐ ๊ผญ ์ด๋ ๊ฒ ์ํด๋ ๋๋ค [ { "Item": [
dowlsovo.tistory.com
https://dowlsovo.tistory.com/85
[๊ตฌํ] ์ฝ๊ฒ ์ธ๋ฒคํ ๋ฆฌ ๊ตฌํํ๊ธฐ 2
1. ์ธ๋ฒคํ ๋ฆฌ ์๋จ ์นดํ ๊ณ ๋ฆฌ ์ค์์น ๊ฐ ๋ฒํผ์๋ SetIndex๋ผ๋ ํจ์๋ฅผ ๋ฃ์ด ์ค๋ค. ๋๋ฅธ ๋ฒํผ์ด ๋ช ๋ฒ์ธ์ง๋ฅผ ํ๋ผ๋ฏธํฐ๋ก ๋ฐ์ ํด๋น ์์ ๋ง๋ ์นดํ ๊ณ ๋ฆฌ๋ก ๋ณ๊ฒฝํ๋ค. public class SelectIndex : MonoBehaviour { pu
dowlsovo.tistory.com
์๋ค๋ฅผ ๋ณด๊ณ ์์ผ ์ดํด๊ฐ ๋ ๊ฒ์ด๋ค!
์์ ๊ณผ ์ธ๋ฒคํ ๋ฆฌ๋ ๊ฒน์น๋ ๋ถ๋ถ์ด ๊ฝค ์์ด ๋นผ๋ ๋ถ๋ถ์ด ๋ง์ ๊ฒ์ด๋ค.
1. ์์ ์ ์์ดํ ๋ถ๋ฌ์ค๊ธฐ
์ญ์ ๋ชจ๋ ์์ดํ ๋ค์ ๋ฏธ๋ฆฌ ๋ง๋ค์ด์ค๋ค.
๋์ ์ ์ด๋ฒ์ Item์ count๋ ์๋ค. ํ์๊ฐ ์๊ธฐ ๋๋ฌธ
๊ทธ๋ฆฌ๊ณ ScrollView์ฐ๋ ๊ฒ ๊น์ง ๋๊ฐ๋ค.
๊ทธ๋ฆฌ๊ณ LoadStore์คํฌ๋ฆฝํธ๋ฅผ ๋ง๋ ๋ค.
public class LoadStoreItems : LoadItems { ... //์คํ ์ด ์์ดํ ๋ก๋ public override void Refresh() { goods = GameObject.FindGameObjectsWithTag(selectIndex.index.ToString()); itemCount = GetComponent<ItemSaveLoad>().GetItemCount(); int selectIndexNum = (int)selectIndex.index; if (selectIndexNum == ((int)InventoryIndex.Item)) { for (int i = 0; i < goods.Length; i++) { goods[i].transform.SetParent(inventorySlotBox.transform); } } else { for (int i = 0; i < goods.Length; i++) { int id = goods[i].GetComponent<ItemInfo>().id - 1; if (!itemCount.have[selectIndexNum -1].haveList[id]) { goods[i].transform.SetParent(inventorySlotBox.transform); } } } ExpandInventory(); } ... }
์์ดํ ์ ๋ฌด์กฐ๊ฑด ๋ค ์ฌ๋กฏ์ผ๋ก ๋ค์ด๊ฐ๊ณ ,
ํค์ด, ์์์ ๊ตฌ๋งคํ์ง ์์ ๊ฒ๋ง ๋ค์ด๊ฐ๋ค.
2. ๊ตฌ๋งค ์ฐฝ ๋ง๋ค๊ธฐ
์์งํ ์ด๊ฑด ๋ ธ๊ฐ๋ค๋ค. ๊ทธ๋์ ์ฝ๋๋ ์๋ตํ๊ฒ ๋ค.
๊ทธ๋ฅ ์ ๋ฒ ์์ดํ ์ ๋ณด json์์ ์ ๋ณด ์ป์ด์์ ํด๋ฆด ๋๋ง๋ค ์ธํ ํด์ setActiveํ๋ฉด ๋๋ค.
3. ๊ตฌ๋งค ๊ตฌํ
๋ญ๊ฐ ๋ณต์กํ ๋ณด์ ๊ทธ๋ฐ๊ฒ ๋ค์ด๊ฐ์ผ ํ ๊ฒ ๊ฐ๊ธด ํ๋ฐ...
๊ทธ๊ฒ๊น์ง ๋๋ ์ ๋ชจ๋ฅธ๋ค ํคํท
์ผ๋จ ๊ทธ๋ฅ ๊ตฌํํ๋ค.
public class StoreSystem : MonoBehaviour { public Slider itemCountToBuySlider; private ShowGoodsInfo showInfo; private ItemSaveLoad saveLoad; private int priceToPay; private void Start() { showInfo = GetComponent<ShowGoodsInfo>(); saveLoad = GetComponent<ItemSaveLoad>(); } public void Buy() { ItemCount itemCount = saveLoad.GetItemCount(); int id = showInfo.GetID(); int selectIndexNum = (int)GetComponent<SelectIndex>().index; if(priceToPay == 0) priceToPay = showInfo.GetPrice(); //์์ดํ ๊ฒฐ์ if (selectIndexNum == ((int)InventoryIndex.Item)) itemCount.itemCounts[id] += ((int)itemCountToBuySlider.value); //์์, ํค์ด ๊ฒฐ์ else itemCount.have[selectIndexNum - 1].haveList[id] = true; PlayerInfo.AddCoin(-1 * priceToPay); saveLoad.SaveUpdate(itemCount); //์ด๊ธฐํ itemCountToBuySlider.value = 1; showInfo.itemInfoPanel.SetActive(false); } //์์ดํ ์ฌ๋ผ์ด๋ ๊ฐ์ ๊ฐ์ ธ์ค๊ธฐ public void ValueChangeCheck() { priceToPay = showInfo.GetPrice() * ((int)itemCountToBuySlider.value); showInfo.SettingPriceFormula((int)itemCountToBuySlider.value, priceToPay); } }
๊ฐ์ ๋ฐ์ ํด์ ์ ์ฅํ๋ ์ฝ๋๋ค.
์ด๋ ๊ฒ ์คํ ์ด๊น์ง ๋!
'UNITY > PROJECT' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[๊ตฌํ] ์ ๋ํฐ๋ก ์ฝ๊ฒ ์ธ๋ฒคํ ๋ฆฌ ๊ตฌํํ๊ธฐ 2 (0) 2021.12.08 [๊ตฌํ] ์ ๋ํฐ๋ก ์ฝ๊ฒ ์ธ๋ฒคํ ๋ฆฌ ๊ตฌํํ๊ธฐ 1 (0) 2021.12.08 [๊ตฌํ] ์ ๋ํฐ ํ ์คํธ ํ์ดํ ํจ๊ณผ (0) 2021.12.07 [๊ตฌํ] json ์ด์ฉ ์ ๋ํฐ ๋ด ๋ํ ๊ฐ๋จํ๊ฒ ๊ตฌํํ๊ธฐ 3 (0) 2021.12.07 [๊ตฌํ] json ์ด์ฉ ์ ๋ํฐ ๋ด ๋ํ ๊ฐ๋จํ๊ฒ ๊ตฌํํ๊ธฐ 2 (0) 2021.12.07