public void RemoveEquip() { savedEquipmentTexture = null; currentImage.sprite = null; equipedItemOb = null; transform.GetChild(0).gameObject.SetActive(false); isEquiped = false; //while user unequipped the item set the bool to false if (currentEquipmentName == "OilLight") { itemEquiped["OilLight"] = false; } if (currentEquipmentName == "crutchEquiped1") { itemEquiped["Crutch"] = false; } }
public void AddItem(string name, bool inheritOB) { GameObject itemObj = new GameObject(name); //Create the GameObject imageObjects.Add(itemObj); length++; Image image = itemObj.AddComponent <Image>(); //Add the Image Component script BackpackItem handler = itemObj.AddComponent <BackpackItem>(); //Add item-drag component handler.itemScale = scaleAmount; //物品判定 handler.canSpell = canSpellDictionary[name]; handler.canEquip = canEquipDictionary[name]; handler.canInteract = canInteractDictionary[name]; image.sprite = textureDictionary[name]; //Set the Sprite of the Image Component on the new GameObject itemObj.tag = "BackpackItem"; RectTransform item_transform = itemObj.GetComponent <RectTransform>(); item_transform.SetParent(go.itemHolder.transform); //Assign the newly created Image GameObject as a Child of the Parent Panel, Canvas/Main UI. item_transform.SetAsFirstSibling(); //更改物品的位置于背包UI内 if (length <= (currPageNumber + 1) * countPerPage && length > currPageNumber * countPerPage) { GameObject locationObj = go.itemPositionHolder.transform.GetChild(length - 1).gameObject; item_transform.anchoredPosition = locationObj.GetComponent <RectTransform>().anchoredPosition; } else { GameObject locationObj = go.extraItemHolder; item_transform.anchoredPosition = locationObj.GetComponent <RectTransform>().anchoredPosition; } //物品类型角标设置 GameObject itemIcon = new GameObject("ItemCanSpell"); Image itemIconImg = itemIcon.AddComponent <Image>(); itemIconImg.raycastTarget = false; if (handler.canSpell) { itemIconImg.sprite = spellIcon; } else { itemIconImg.sprite = collectIcon; } RectTransform itemIconTransform = itemIcon.GetComponent <RectTransform>(); itemIconTransform.SetParent(itemObj.transform); itemIconTransform.sizeDelta = new Vector2(20, 20); itemIconTransform.anchoredPosition = new Vector2(20, -20); // if (name.CompareTo("Heavenly Water") == 0) { // item_transform.sizeDelta = new Vector2(60, 35); // } else if (name.CompareTo("Changable Soil") == 0) { // item_transform.anchoredPosition = item_transform.anchoredPosition + new Vector2(0, 5); // item_transform.sizeDelta = new Vector2(45, 40); // } //check if Crutch is found if (name == "OilLight") { oilLightFound = true; } //继承Ob相关属性 if (inheritOB) { ObItem backpackItemOb = itemObj.AddComponent <ObItem>(); backpackItemOb.correspondingOB = go.ob.GetComponent <ObManagement>().transferToBackpackItemOB; backpackItemOb.correspondingOB.GetComponent <ObDisplay>().isPicked = true; itemObj.SetActive(this.gameObject.activeSelf); } }
//将ObItem的信息从Item放到Ob Canvas中 public void GetObItemData(ObItem clickObjectOb) { this.correspondingOB = clickObjectOb.correspondingOB; }
public void Equip(GameObject equipmentItem) { isLightWeighted = false; savedEquipmentTexture = equipmentItem.GetComponentInChildren <Image>().sprite; print(backpackDisp); equipLocatePage = backpackDisp.currPageNumber; transform.GetChild(0).gameObject.SetActive(true); if (currentImage != null) { PutEquipmentTexture(); } currentEquipmentName = equipmentItem.name; isEquiped = true; //继承背包装备的obitem.cs if (equipmentItem.GetComponent <ObItem>() != null) { equipedItemOb = gameObject.AddComponent <ObItem>(); equipedItemOb.correspondingOB = equipmentItem.GetComponent <ObItem>().correspondingOB; } if (currentEquipmentName == "Crutch") { int state = equipmentItem.GetComponent <ObItem>().correspondingOB.GetComponent <ObDisplay>().currentState; //while user equipped the crutch, set the bool to true itemEquiped["Crutch"] = true; if (firstTimeEquiped.ContainsKey("Crutch") && !firstTimeEquiped["Crutch"]) { if (state == 1) { TipsDialog.PrintDialog("FirstCrutchBroken"); } else { TipsDialog.PrintDialog("FirstCrutchFixed"); } firstTimeEquiped["Crutch"] = true; } } else if (currentEquipmentName == "轻身符") { isLightWeighted = true; } else if (currentEquipmentName == "OilLight") { //while user equipped the OilLight, set the bool to true itemEquiped["OilLight"] = true; if (firstTimeEquiped.ContainsKey("OilLight") && !firstTimeEquiped["OilLight"]) { int state = equipmentItem.GetComponent <ObItem>().correspondingOB.GetComponent <ObDisplay>().currentState; firstTimeEquiped["OilLight"] = true; if (SceneManager.GetActiveScene().name == "WaterLevelWell") { TipsDialog.PrintDialog("FirstLightWell"); } else { TipsDialog.PrintDialog("FirstLight"); } } } print("just equip " + equipedItemOb); }