void Soil() { Soil soil = gameObject.transform.Find("plant").gameObject.GetComponent <Soil>(); Debug.Log(itemType.ToString()); if (soil.harvestTime) { soil.HarvestTime(itemType); itemType = Item.ItemType.None; } else { switch (UIStatics.CURRENT_PICK) { case "Timba": if (isClicked) { BucketCommand(); } break; // didilig case "Pala": if (itemType == Item.ItemType.None && isClicked) { PopUpSystem.Instance.PopUpSeedBox(gameObject); } break; } } }
private void Display() { for (int i = 0; i < ((int)Item.ItemType.NUMBER_OF_ITEM_TYPES); ++i) { Item.ItemType type = ((Item.ItemType)(i)); string name = ((type == Item.ItemType.Undefined) ? "All" : type.ToString()); if (GUI.Button(new Rect(9.5f * scr.x, (3.25f + i * 0.3f) * scr.y, 3f * scr.x, 0.25f * scr.y), name)) { SetFilter(type); } } if (filteredInv.Count < 35) { for (int i = 0; i < filteredInv.Count; ++i) { if (GUI.Button(new Rect(0.5f * scr.x, (i + 1) * 0.25f * scr.y, 3f * scr.x, 0.25f * scr.y), filteredInv[i].Name)) { selectedItem = filteredInv[i]; } } } else { // Movable scroll position scrollPos = // Start of the viewable area GUI.BeginScrollView ( // Our View Window new Rect(0f, 0.25f * scr.y, 3.75f * scr.x, 8.5f * scr.y), // Our current scroll position scrollPos, // Scroll Zone (extra space) new Rect(0f, 0f, 0f, 8.5f * scr.y + ((filteredInv.Count - 34) * (0.25f * scr.y))), // Can we see the horizontal bar? false, // Can we see the vertical bar? true ); for (int i = 0; i < filteredInv.Count; ++i) { if (GUI.Button(new Rect(0.5f * scr.x, i * 0.25f * scr.y, 3f * scr.x, 0.25f * scr.y), filteredInv[i].Name)) { selectedItem = filteredInv[i]; } } // End the scroll space GUI.EndScrollView(); } }
//CALL FROM INVENTORY public static void UpdateToolBarItems() { int i = 0; foreach (Image slot in slots) { if (slot.gameObject.transform.childCount > 0) { Debug.Log(slot.gameObject.transform.GetChild(0).gameObject.name); Destroy(slot.transform.GetChild(0).gameObject); } if (Inventory.myItems.ContainsKey(i)) { Item.ItemType itemType_ = Inventory.myItems[i].itemType; int itemValue_ = Inventory.myItems[i].itemValue; GameObject itemChild = new GameObject(); itemChild.name = "Item => " + itemType_.ToString(); itemChild.transform.SetParent(slot.gameObject.transform); Image itemSprite = itemChild.AddComponent <Image>(); itemSprite.sprite = Item.items[itemType_].itemSprite; itemSprite.raycastTarget = false; RectTransform rect = itemChild.GetComponent <RectTransform>(); rect.localPosition = Vector2.zero; rect.localScale = new Vector2(.26f, .47f); //_______________________________________ GameObject valueGameObject = new GameObject(); valueGameObject.name = "Value => " + itemType_.ToString(); valueGameObject.transform.SetParent(itemChild.transform); Text valueTxt = valueGameObject.AddComponent <Text>(); RectTransform rectTransform = valueGameObject.GetComponent <RectTransform>(); rectTransform.localScale = new Vector2(.12f, .12f); rectTransform.sizeDelta = new Vector2(3240, 2240); rectTransform.localPosition = new Vector2(45, -45); valueTxt.raycastTarget = false; valueTxt.color = Color.white; valueTxt.fontStyle = FontStyle.Bold; valueTxt.alignment = TextAnchor.MiddleCenter; valueTxt.fontSize = 300; valueTxt.font = arial; valueTxt.text = Inventory.myItems[i].itemValue.ToString(); } i++; } }
public void SetSlimeMode(Item.ItemType itemType) { if (slimeMode == itemType) { return; } ParticleManager.ShowParticle((int)destination.x, (int)destination.z, E_PARTICLE_TYPE.ADD); slimeMode = itemType; Debug.Log("SetSlimeMode : " + itemType.ToString()); // if (itemType == Item.ItemType.empty) { // for (int f = (int)Item.ItemType.empty; f <= (int)Item.ItemType.poison; f++) { // PlayerItemList[f] = 0; // } // } else { // for (int f = (int)Item.ItemType.milk; f <= (int)Item.ItemType.poison; f++) { // PlayerItemList[f] = 0; // } // PlayerItemList[(int)itemType] = 1; // } Item _item = ItemManager.GetItemData(slimeMode); switch (slimeMode) { case Item.ItemType.butter: subMode1 = Item.ItemType.milk; subMode2 = Item.ItemType.oil; break; case Item.ItemType.yogurt: subMode1 = Item.ItemType.milk; subMode2 = Item.ItemType.acid; break; case Item.ItemType.poison: subMode1 = Item.ItemType.oil; subMode2 = Item.ItemType.acid; break; default: subMode1 = Item.ItemType.empty; subMode2 = Item.ItemType.empty; break; } Material ReplaceMat = MaterialMap[(int)itemType]; playerInstance.GetComponentInChildren <SkinnedMeshRenderer>().material = ReplaceMat; UIManger.instance.UpdateSlimeMode(); }
public void updateValues(Item.ItemType type) { itemName.Clear(); List <Item> items = GetAllItemsOfType(type); for (int i = 0; i < items.Count; i++) { itemName.Add(items[i].Name); } myInventoryUI.updateUI(items.Count, type.ToString(), itemName); }
public static string GenerateItemSelect(string itemString) { Item.ItemType itemType = Item.ItemType.Cake; if (!Enum.TryParse(itemString, true, out itemType)) { itemType = Item.ItemType.Cake; } GUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Item:", GUILayout.Width(40)); itemType = (Item.ItemType)EditorGUILayout.EnumPopup(itemType); GUILayout.EndHorizontal(); return(itemType.ToString()); }
void SetItems() { foreach (KeyValuePair <int, MyItemValues> myItem in myItems) { Item.ItemType itemType_ = myItem.Value.itemType; int itemValue_ = myItem.Value.itemValue; GameObject itemChild = new GameObject(); itemChild.name = "Item => " + itemType_.ToString(); itemChild.transform.SetParent(slots[myItem.Key].transform); Image itemSprite = itemChild.AddComponent <Image>(); itemSprite.sprite = Item.items[itemType_].itemSprite; itemSprite.raycastTarget = false; RectTransform rect = itemChild.GetComponent <RectTransform>(); rect.localPosition = Vector2.zero; rect.localScale = new Vector2(.5f, .47f); //_______________________________________ GameObject valueGameObject = new GameObject(); valueGameObject.name = "Value => " + itemType_.ToString(); valueGameObject.transform.SetParent(itemChild.transform); Text valueTxt = valueGameObject.AddComponent <Text>(); RectTransform rectTransform = valueGameObject.GetComponent <RectTransform>(); rectTransform.localScale = new Vector2(.12f, .12f); rectTransform.sizeDelta = new Vector2(3240, 2240); rectTransform.localPosition = new Vector2(45, -45); valueTxt.raycastTarget = false; valueTxt.color = Color.white; valueTxt.fontStyle = FontStyle.Bold; valueTxt.alignment = TextAnchor.MiddleCenter; valueTxt.fontSize = 300; valueTxt.font = arial; valueTxt.text = itemValue_.ToString(); // Debug.Log(myItem.Key + " " + itemType_.ToString() + " " + itemValue_.ToString()); } Debug.Log("INVENTORY UPDATED"); ToolBar.UpdateToolBarItems(); }
private void DisplaySortButtons() { Rect sortButtonAreaSize = sortButtonArea.GetComponent <RectTransform>().rect; float buttonHeight = sortButtonAreaSize.height / ((float)((int)Item.ItemType.NUMBER_OF_ITEM_TYPES)); for (int i = 0; i < ((int)Item.ItemType.NUMBER_OF_ITEM_TYPES); ++i) { GameObject sortButton = Instantiate <GameObject>(buttonPrefab, sortButtonArea.transform); RectTransform rt = sortButton.GetComponent <RectTransform>(); rt.anchoredPosition = new Vector2(0f, -(i * buttonHeight)); rt.sizeDelta = new Vector2(sortButtonAreaSize.width, buttonHeight); Item.ItemType type = ((Item.ItemType)(i)); string name = ((type == Item.ItemType.Undefined) ? "All" : type.ToString()); sortButton.GetComponentInChildren <Text>().text = name; sortButton.GetComponent <Button>().onClick.AddListener(() => SetFilter(type)); } }
private void CreateItemButton(Item.ItemType itemType, Sprite itemSprite, string itemName, int itemCost, string itemElement, int positionIndex, string description) { Transform shopItemTransform = Instantiate(ShopItemTemplate, Container); shopItemTransform.GetComponent <ShopItemUI>().SetDescription(description); shopItemTransform.gameObject.SetActive(true); shopItemTransform.gameObject.name = itemType.ToString(); RectTransform shopItemRectTransform = shopItemTransform.GetComponent <RectTransform>(); PositionButton(shopItemRectTransform, positionIndex); //Set shop item texts and icons shopItemTransform.Find("nameText").GetComponent <TextMeshProUGUI>().SetText(itemName); shopItemTransform.Find("cost").GetComponent <TextMeshProUGUI>().SetText(itemCost.ToString()); shopItemTransform.Find("itemImage").GetComponent <Image>().sprite = itemSprite; if (itemElement == "General") { shopItemTransform.Find("soul_Image").GetComponent <Image>().sprite = GameAssets.i.GeneralSoul; } else if (itemElement == "Fire") { shopItemTransform.Find("soul_Image").GetComponent <Image>().sprite = GameAssets.i.FireSoul; } else if (itemElement == "Water") { shopItemTransform.Find("soul_Image").GetComponent <Image>().sprite = GameAssets.i.WaterSoul; } else if (itemElement == "Earth") { shopItemTransform.Find("soul_Image").GetComponent <Image>().sprite = GameAssets.i.EarthSoul; } else if (itemElement == "Air") { shopItemTransform.Find("soul_Image").GetComponent <Image>().sprite = GameAssets.i.AirSoul; } Button shopBtn = shopItemTransform.GetComponent <Button>(); shopBtn.onClick.AddListener(() => TryBuyItem?.Invoke(itemType, itemCost, itemElement)); }
public void loadItems(Item.ItemType type) { Object[] itemsInFolder = Resources.LoadAll("Items/" + type.ToString() + "/"); Vector2 screenPos = new Vector2(buttonOffset.x, -buttonOffset.y); int childs = shopPanel.transform.childCount; for (int i = 0; i < childs; i++) { Destroy(shopPanel.transform.GetChild(i).gameObject); } for (int i = 0; i < itemsInFolder.Length; i++) { GameObject btn = ButtonFactory.createButton(itemsInFolder[i].name, new Vector2(buttonSize, buttonSize), Paths.ItemSprite + type + "/" + itemsInFolder[i].name, screenPos, true); btn.transform.SetParent(shopPanel.transform); RectTransform btnRect = btn.GetComponent <RectTransform>(); Button btnButton = btn.GetComponent <Button>(); btnRect.pivot = new Vector2(0, 1); btnRect.anchorMin = new Vector2(0, 1); btnRect.anchorMax = new Vector2(0, 1); btnRect.localScale = new Vector3(1, 1, 1); btnRect.anchoredPosition3D = new Vector3(0, 0, 0); btnRect.anchoredPosition = screenPos; if (btnRect.anchoredPosition.x >= shopPanelRectTransform.rect.width) { screenPos = new Vector3(buttonOffset.x, btnRect.anchoredPosition.y - btnRect.sizeDelta.y - buttonOffset.y - 10, 0); btnRect.anchoredPosition = screenPos; } screenPos += new Vector2(btnRect.sizeDelta.x + buttonOffset.x, 0); btnButton.onClick.AddListener(delegate() { createItem.CreateItem(btn.name, type); }); shopPanel.GetComponent <RectTransform>().sizeDelta = new Vector2(0, -btnRect.anchoredPosition.y + btnRect.sizeDelta.y + buttonOffset.y); /* * GameObject buttonGO = new GameObject(); * RectTransform buttonRT = buttonGO.AddComponent<RectTransform>(); * buttonRT.SetParent(shopPanel.transform); * * buttonGO.name = itemsInFolder[i].name; * * buttonRT.sizeDelta = new Vector2(buttonSize, buttonSize); * * buttonRT.pivot = new Vector2(0, 1); * buttonRT.anchorMin = new Vector2(0, 1); * buttonRT.anchorMax = new Vector2(0, 1); * * buttonRT.anchoredPosition = screenPos; * * if (buttonRT.anchoredPosition.x >= shopPanelRectTransform.rect.width) * { * screenPos = new Vector2(buttonOffset.x, buttonRT.anchoredPosition.y - buttonRT.sizeDelta.y - buttonOffset.y-10); * buttonRT.anchoredPosition = screenPos; * } * screenPos += new Vector2(buttonRT.sizeDelta.x + buttonOffset.x, 0); * * Button buttonBU = buttonGO.AddComponent<Button>(); * buttonBU.onClick.AddListener(() => {createItem.CreateMyItem(buttonGO.name,type); }); * Image buttonIM = buttonGO.AddComponent<Image>(); * buttonIM.sprite = Resources.Load<Sprite>("Items_Images/" + type + "/" + itemsInFolder[i].name); * // Button Label * GameObject label = new GameObject(); * RectTransform labelRT = label.AddComponent<RectTransform>(); * labelRT.SetParent(buttonGO.transform); * labelRT.anchoredPosition = new Vector2(buttonRT.sizeDelta.x/2, -buttonRT.sizeDelta.y-15); * Text labelText = label.AddComponent<Text>(); * labelText.font = Resources.Load<Font>("Fonts/Andale Mono"); * labelText.text = itemsInFolder[i].name; * labelText.color = Color.black; */ } }
//set item type for inventory items public void SetItemType(Item.ItemType type) { statName.text = "ıtem type"; statValue.text = type.ToString(); }