//Buy item private void BuyItem(GameObject item) { int itemId = item.GetComponent <IDScript>().id; int itemType = -1; ShopItem shopItem = null; if (item.tag == "Computer") { shopItem = ComputerList.FindItem(itemId); itemType = 0; } else if (item.tag == "GraphicCard") { shopItem = GraphicCardList.FindItem(itemId); itemType = 1; } else if (item.tag == "Asic") { shopItem = AsicList.FindItem(itemId); itemType = 2; } if (shopItem != null) { if (gameStatManager.IsEnoughCash(shopItem.GetPrice())) { gameStatManager.DeductCash(shopItem.GetPrice()); gameStatManager.AddSpeed(shopItem.GetSpeed()); gameStatManager.AddWatt(shopItem.GetWatt()); if (itemType == 0) { gameStatManager.AddComputer(itemId); } else if (itemType == 1) { gameStatManager.AddGrahpicCard(itemId); } else if (itemType == 2) { gameStatManager.AddAsic(itemId); } else { Debug.Log("Error: [ItemContainerManager][BuyItem][Cannot get itemType]"); } statusText.color = Color.green; statusText.text = "Model [" + shopItem.GetModel() + "] purchase successful!"; } else { statusText.color = Color.red; statusText.text = "Not enough cash to buy model [" + shopItem.GetModel() + "]"; } } }
private void AddItem() { //Computer int id = 0; foreach (Computer item in ComputerList.GetList()) { //Set attributes GameObject newItem = Instantiate(itemFrame, computerGrid.transform); newItem.GetComponent <IDScript>().id = id++; newItem.tag = "Computer"; //Set displays newItem.transform.Find("Model").GetComponent <Text>().text = item.GetModel(); newItem.transform.Find("Image").GetComponent <Image>().sprite = item.GetImage(); newItem.transform.Find("Value").GetComponent <Text>().text = item.GetSpeed().ToString() + "\n" + item.GetWatt().ToString(); newItem.transform.Find("Price").GetComponent <Text>().text = "$" + item.GetPrice(); //Set button events Button itemButton = newItem.GetComponent <Button>(); itemButton.onClick.AddListener(() => BuyItem(newItem)); } //Graphic card id = 0; foreach (GraphicCard item in GraphicCardList.GetList()) { GameObject newItem = Instantiate(itemFrame, graphicCardGrid.transform); newItem.GetComponent <IDScript>().id = id++; newItem.tag = "GraphicCard"; newItem.transform.Find("Model").GetComponent <Text>().text = item.GetModel(); newItem.transform.Find("Image").GetComponent <Image>().sprite = item.GetImage(); newItem.transform.Find("Value").GetComponent <Text>().text = item.GetSpeed().ToString() + "\n" + item.GetWatt().ToString(); newItem.transform.Find("Price").GetComponent <Text>().text = "$" + item.GetPrice(); Button itemButton = newItem.GetComponent <Button>(); itemButton.onClick.AddListener(() => BuyItem(newItem)); } //Asic id = 0; foreach (Asic item in AsicList.GetList()) { GameObject newItem = Instantiate(itemFrame, asicGrid.transform); newItem.GetComponent <IDScript>().id = id++; newItem.tag = "Asic"; newItem.transform.Find("Model").GetComponent <Text>().text = item.GetModel(); newItem.transform.Find("Image").GetComponent <Image>().sprite = item.GetImage(); newItem.transform.Find("Value").GetComponent <Text>().text = item.GetSpeed().ToString() + "\n" + item.GetWatt().ToString(); newItem.transform.Find("Price").GetComponent <Text>().text = "$" + item.GetPrice(); Button itemButton = newItem.GetComponent <Button>(); itemButton.onClick.AddListener(() => BuyItem(newItem)); } }
private void ProcessItemList() { computerList = gameStatManager.GetComputerList(); graphicCardList = gameStatManager.GetGraphicCardList(); asicList = gameStatManager.GetAsicList(); //Initialize computerCount = new Dictionary <ShopItem, int>(); graphicCardCount = new Dictionary <ShopItem, int>(); asicCount = new Dictionary <ShopItem, int>(); //Computer foreach (int item in computerList) { Computer computer = ComputerList.FindItem(item); if (computerCount.ContainsKey(computer)) { //Already contains model computerCount[computer]++; } else { //No current model computerCount.Add(computer, 1); } } //Graphic card foreach (int item in graphicCardList) { GraphicCard graphicCard = GraphicCardList.FindItem(item); if (graphicCardCount.ContainsKey(graphicCard)) { //Already contains model graphicCardCount[graphicCard]++; } else { //No current model graphicCardCount.Add(graphicCard, 1); } } //Asic foreach (int item in asicList) { Asic asic = AsicList.FindItem(item); if (asicCount.ContainsKey(asic)) { //Already contains model asicCount[asic]++; } else { //No current model asicCount.Add(asic, 1); } } }