IEnumerator LoadDelay() { yield return(0); Q_Inventory playerInventory = Q_GameMaster.Instance.inventoryManager.playerInventory; PlayerInventoryManager playerInventoryManager = Q_GameMaster.Instance.inventoryManager.playerInventoryManager; InventorySaveData saveData = Q_GameMaster.Instance.inventoryManager.itemDataBase.saveData; GameObject equipmentContainer = Q_GameMaster.Instance.inventoryManager.m_EquipmentContainer; foreach (var item in saveData.playerInventoryItems) { for (int i = 0; i < item.amount; i++) { playerInventory.AddItem(item.item.ID); } } for (int i = 0; i < saveData.playerAttributes.Count; i++) { playerInventoryManager.playerAttributes[i].currentValue = saveData.playerAttributes[i].currentValue; playerInventoryManager.playerAttributes[i].minValue = saveData.playerAttributes[i].minValue; playerInventoryManager.playerAttributes[i].maxValue = saveData.playerAttributes[i].maxValue; } for (int i = 0; i < saveData.playerCurrencies.Count; i++) { playerInventoryManager.playerCurrencies[i].amount = saveData.playerCurrencies[i].amount; } for (int i = 0; i < saveData.onEquipmentItems.Count; i++) { playerInventory.AddItem(saveData.onEquipmentItems[i]).WearEquipmentItemWithoutChangeAttribute(); } }
public void AddItemSelf() { for (int i = 0; i < amount; i++) { inv.AddItem(item.ID); } Destroy(gameObject); }
IEnumerator ItemAdd(int id, int amount) { yield return(0); Q_Inventory inv = GetComponent <Q_Inventory>(); inv.AddItem(id, amount); }
void ReplaceEquipmentItem(Transform itemParent) { if (itemParent.childCount != 0) { Transform itemReplaced = itemParent.GetChild(0); GameObjectData itemdata = itemReplaced.transform.GetComponent <GameObjectData>(); Q_GameMaster.Instance.inventoryManager.playerInventoryManager.ClearEquipmentAttributeByItemAttribute(itemdata.item.equipmentItemAttributes); inv.AddItem(itemdata.item, slot, amount); Destroy(itemReplaced.gameObject); } }
public override void OnInspectorGUI() { base.OnInspectorGUI(); Q_Inventory m_Inventory = target as Q_Inventory; EditorGUILayout.LabelField("Add Item"); itemID = Mathf.Clamp(EditorGUILayout.IntField("Item ID", itemID), 0, 99999); if (GUILayout.Button("Add Item")) { m_Inventory.AddItem(itemID); } }
//用于实现制作CD的 IEnumerator AddCraftingItem(ItemData itemdata) { int amount = itemdata.amountToCraft; CostIngredients(itemdata.m_CraftingBluePrint.ingredients, amount); PlayerInventoryManager.UpdatePlayerCurrency(itemdata.m_CraftingBluePrint.craftingPrices, -1 * amount); //Debug.Log(amount); for (int i = 0; i < amount; i++) { StartCD(itemdata.slot, itemdata.m_CraftingBluePrint.craftingTime); if (itemdata.m_CraftingBluePrint.CDAllWhenCrafting) { AllStartCD(itemdata.m_CraftingBluePrint.craftingTime); } yield return(new WaitForSeconds(itemdata.m_CraftingBluePrint.craftingTime)); int chance = Random.Range(0, 100); if (chance < itemdata.m_CraftingBluePrint.successChance * 100) { Debug.Log("Crafting Success"); //废用的,直接加到玩家背包里,他们说不好 playerInventory.AddItem(itemdata.item.ID); //现在是在指定合成地点掉落 //Instantiate(Q_GameMaster.Instance.inventoryManager.itemDataBase.getItemByID(itemdata.item.ID).m_object, craftingSpawningPosition.position + spawnOffset, Quaternion.identity); itemdata.inputField.text = (--itemdata.amountToCraft).ToString(); } else { Debug.Log("Crafting Failed"); } } itemdata.amountToCraft = 1; itemdata.isCrafting = false; itemdata.inputField.text = (itemdata.amountToCraft).ToString(); }
public void OnDrop(PointerEventData eventData) { ItemData droppedItem = eventData.pointerDrag.GetComponent <ItemData>(); if (!droppedItem) { return; } if (!droppedItem.inv) { return; } if (droppedItem.inv.tag == "Equipment") { return; } if ((droppedItem.inv.tag == "Inventory" || inv.tag == "SkillBar")) { if (droppedItem.inv.ReturnCoolingState(droppedItem.slot)) { //Q_GameMaster.Instance.inventoryManager.SetInformation(Q_GameMaster.Instance.inventoryManager.infoManager.cantMoveWhenCD); return; } } string tag = eventData.pointerCurrentRaycast.gameObject.tag; if (tag == "Storage" || tag == "Inventory" || tag == "SkillBar") { //Debug.Log(eventData.pointerCurrentRaycast.gameObject.tag); if (inv.items[slotID].ID == -1) { if (droppedItem.inv == inv) { if (droppedItem.inv.items[droppedItem.slot] != null) { droppedItem.inv.items[droppedItem.slot] = Item.CreateInstance <Item>(); } inv.items[slotID] = droppedItem.item; if (tag == "Inventory" || tag == "SkillBar") { inv.cds[slotID] = inv.cds[droppedItem.slot]; inv.cds[droppedItem.slot] = new CoolDown(); } droppedItem.slot = slotID; } else { inv.AddItem(droppedItem.item, slotID, droppedItem.amount); droppedItem.ClearItem(); } } else if ((inv.tag == "Inventory" || inv.tag == "SkillBar") && inv.ReturnCoolingState(slotID)) { return; } else if ((droppedItem.inv.tag == "Inventory" || droppedItem.inv.tag == "SkillBar") && droppedItem.inv.ReturnCoolingState(droppedItem.slot)) { return; } else { Transform item = null; int chileNum = transform.childCount; if (chileNum == 1) { item = transform.GetChild(0); } else if (chileNum == 2) { item = transform.GetChild(1); } ItemData data = null; if (item) { data = item.GetComponent <ItemData>(); } if (droppedItem.inv == inv) { if (!item) { return; } //Debug.Log("Switch"); if (data) { data.slot = droppedItem.slot; } item.transform.SetParent(data.inv.slots[droppedItem.slot].transform); item.transform.position = data.inv.slots[droppedItem.slot].transform.position; data.inv.items[droppedItem.slot] = data.item; inv.items[slotID] = droppedItem.item; if (inv.tag == "Inventory" || inv.tag == "SkillBar") { inv.cds[droppedItem.slot] = new CoolDown(data.cd, data.item.coolDown); droppedItem.inv.cds[slotID] = new CoolDown(droppedItem.cd, droppedItem.item.coolDown); } droppedItem.slot = slotID; droppedItem.transform.SetParent(transform); droppedItem.transform.position = transform.position; //data.inv = droppedItem.inv; //item.GetComponent<ItemDrag>().inv = droppedItem.inv; //droppedItem.inv = inv; //droppedItem.GetComponent<ItemDrag>().inv = inv; } else { if (data.item == droppedItem.item && data.item.isStackable && inv.CheckSlot(slotID) > droppedItem.amount) { droppedItem.ClearItem(); data.amount += droppedItem.amount; data.UpdataText(); } else { data.ClearItem(); droppedItem.ClearItem(); int temp = data.slot; data.slot = droppedItem.slot; droppedItem.slot = temp; droppedItem.inv.AddItem(data.item, data.slot, data.amount); inv.AddItem(droppedItem.item, droppedItem.slot, droppedItem.amount); } } } } }