public static void SaveInventoryData()
        {
            Q_Inventory       m_PlayerInventory = Q_GameMaster.Instance.inventoryManager.playerInventory;
            InventorySaveData m_SaveData        = Q_GameMaster.Instance.inventoryManager.itemDataBase.saveData;
            List <Item>       items             = m_PlayerInventory.items;
            List <GameObject> slots             = m_PlayerInventory.slots;

            m_SaveData.playerInventoryItems.Clear();

            for (int i = 0; i < items.Count; i++)
            {
                if (items[i].ID != -1)
                {
                    int amount = slots[i].transform.GetChild(0).GetComponent <ItemData>().amount;
                    m_SaveData.playerInventoryItems.Add(new ItemToSave(items[i], amount));
                }
            }

            List <PlayerCurrency> playerCurrencies = Q_GameMaster.Instance.inventoryManager.playerInventoryManager.playerCurrencies;

            m_SaveData.playerCurrencies.Clear();
            for (int i = 0; i < playerCurrencies.Count; i++)
            {
                m_SaveData.playerCurrencies.Add(new CurrencyToSave(playerCurrencies[i].currency, playerCurrencies[i].amount));
            }

            List <PlayerAttribute> playerAttributes = Q_GameMaster.Instance.inventoryManager.playerInventoryManager.playerAttributes;

            m_SaveData.playerAttributes.Clear();
            for (int i = 0; i < playerAttributes.Count; i++)
            {
                m_SaveData.playerAttributes.Add(new PlayerAttribute(playerAttributes[i].playerAttribute, playerAttributes[i].currentValue, playerAttributes[i].minValue, playerAttributes[i].maxValue));
            }

            m_SaveData.onEquipmentItems.Clear();
            GameObject equipmentContainer = Q_GameMaster.Instance.inventoryManager.m_EquipmentContainer;

            for (int i = 0; i < equipmentContainer.transform.childCount; i++)
            {
                if (equipmentContainer.transform.GetChild(i).childCount == 2)
                {
                    ItemData data = equipmentContainer.transform.GetChild(i).GetChild(1).GetComponent <ItemData>();
                    m_SaveData.onEquipmentItems.Add(data.item.ID);
                }
            }


            Debug.Log("Successfully Save Inventory Data");
        }
        public void Load()
        {
            //Player
            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;

            for (int i = 0; i < equipmentContainer.transform.childCount; i++)
            {
                if (equipmentContainer.transform.GetChild(i).childCount == 2)
                {
                    ItemData data = equipmentContainer.transform.GetChild(i).GetChild(1).GetComponent <ItemData>();
                    data.UnwearItemWithoutAdd();
                }
            }

            playerInventory.ClearAllItems();

            StartCoroutine(LoadDelay());
        }
        public void SortItem()
        {
            List <ItemToSort> itemsToSort = new List <ItemToSort>();
            Q_Inventory       inv         = GetComponent <Q_Inventory>();

            if (inv.tag == "Inventory")
            {
                for (int i = 0; i < inv.slots.Count; i++)
                {
                    if (inv.ReturnCoolingState(i))
                    {
                        return;
                    }
                }
            }

            foreach (var slot in inv.slots)
            {
                if (slot.transform.childCount > 0)
                {
                    ItemData data = slot.transform.GetChild(0).GetComponent <ItemData>();
                    itemsToSort.Add(new ItemToSort(data.item, data.amount));
                    data.ClearItem();
                }
            }

            List <Variety> itemSortingOrders = Q_GameMaster.Instance.inventoryManager.itemSortingManager.itemSortingOrders;

            foreach (var sortType in itemSortingOrders)
            {
                foreach (var itemToSort in itemsToSort)
                {
                    if (itemToSort.item.variety == sortType)
                    {
                        StartCoroutine(ItemAdd(itemToSort.item.ID, itemToSort.amount));
                    }
                }
            }
        }
예제 #4
0
 //private Vector2 offset;
 private void Start()
 {
     itemData = GetComponent <ItemData>();
     inv      = itemData.inv;
 }