public void AddBait(string uid, GameObject obj) { DataSingleton.Instance.BuyBait(uid); PlayerBait playerBait = DataSingleton.Instance.FindPlayerBaitFromBait(uid); if (playerBait == null) { transform.GetComponentInChildren <Text>().text = "0개"; } else { transform.GetComponentInChildren <Text>().text = playerBait.count.ToString() + "개"; } }
public bool Active() //active SelectBait { activeCnt = -1; select = -1; //load playerBait data List <PlayerBait> playerBaits = DataSingleton.Instance.GetPlayerBaits(); if (playerBaits.Count == 0) { CantFishing(); return(false); } canSelectIndex.Clear(); string playerwearBaitUID = DataSingleton.Instance.GetPlayerWearBait(); for (int i = 0; i < itemCnt; i++) { string UID = items[i].GetUID(); PlayerBait playerBait = playerBaits.Find(x => x.baitID == UID); if (playerBait != null && playerBait.count > 0) { activeCnt++; canSelectIndex.Add(i); //player가 착용한 bait인 경우 if (playerwearBaitUID == playerBait.UIDCODE) { select = activeCnt; rectTransform.localPosition = new Vector3(-select * 220, rectTransform.localPosition.y , rectTransform.localPosition.z); } items[i].SetValue(playerBait.count, playerBait.UIDCODE); items[i].gameObject.SetActive(true); } else { items[i].gameObject.SetActive(false); } } //active가능한 미끼가 없는경우 if (activeCnt == -1) { CantFishing(); return(false); } //선택된 미끼가 없는 경우 0번 미끼 선택 if (select == -1) { int index = canSelectIndex[0]; DataSingleton.Instance.SetPlayerWearBait(items[index].GetPlayerBaitUID()); select = 0; } CanFishing(false); return(true); }
void Start() { for (int i = 0; i < 3; i++) { string UID = StoreBaitArray[i].GetComponent <StoreDataSetting>().UIDCODE; string baitID = StoreBaitArray[i].GetComponent <StoreDataSetting>().baitID; string image = DataSingleton.Instance.BaitImage(UID); string name = DataSingleton.Instance.BaitName(baitID); int cost = DataSingleton.Instance.BaitCost(UID); string data = DataSingleton.Instance.BaitDetailData(UID); int pow = DataSingleton.Instance.BaitPower(baitID); int spd = DataSingleton.Instance.BaitSpeed(baitID); int all = DataSingleton.Instance.BaitAllure(baitID); StoreBaitArray[i].transform.GetComponentInChildren <Image>().sprite = Resources.Load <Sprite>(image); PlayerBait playerBait = DataSingleton.Instance.FindPlayerBaitFromBait(baitID); if (playerBait == null) { StoreBaitArray[i].transform.GetComponentInChildren <Text>().text = "0개"; } else { StoreBaitArray[i].transform.GetComponentInChildren <Text>().text = playerBait.count.ToString() + "개"; } StoreBaitArray[i].transform.GetChild(1).GetComponent <Text>().text = name; StoreBaitArray[i].transform.GetChild(2).GetComponent <Text>().text = "가격 " + cost; StoreBaitArray[i].transform.GetChild(3).GetComponent <Text>().text = data; StoreBaitArray[i].transform.GetChild(4).GetComponent <Text>().text = "힘" + pow + " 속도" + spd + " 매력도" + all; int coinCount = 0; string uid = "01000"; if (i == 1) { coinCount = 100; uid = "01001"; } else if (i == 2) { coinCount = 500; uid = "01002"; } StoreBaitArray[i].GetComponentInChildren <Button>().onClick.AddListener(() => { sound_single.Instance.PlayCoin(); coin.SetCoinReduce(coinCount); }); Transform tra = StoreBaitArray[i].transform; StoreBaitArray[i].GetComponentInChildren <Button>().onClick.AddListener(() => { DataSingleton.Instance.BuyBait(uid); PlayerBait baitPlayer = DataSingleton.Instance.FindPlayerBaitFromBait(uid); if (baitPlayer == null) { Debug.Log("null"); tra.GetComponentInChildren <Text>().text = "0개"; } else { Debug.Log(baitPlayer.count); tra.GetComponentInChildren <Text>().text = baitPlayer.count.ToString() + "개"; } }); } }