コード例 #1
0
        /// <summary>
        /// Method for inserting item into inventory
        /// </summary>
        /// <param name="inputItemData">the item to insert</param>
        /// <returns>bool corresponding to whether or not the insert was successful</returns>
        public bool Insert(string inputItemData, int Count = 1)
        {
            ItemDataBase itemDatabase = (ItemDataBase)ScriptableObject.CreateInstance(typeof(ItemDataBase));
            bool         FirstInsert  = false;

            //if the item is not null
            if (inputItemData != null)
            {
                //if the inventory contains the item already and the item is not unique, then increment
                //the item count, otherwise actually insert into the map, increment size
                if (!itemMap.ContainsKey(inputItemData))
                {
                    itemMap.Add(inputItemData, itemDatabase.database[inputItemData]);
                    size++;
                    FirstInsert = true;
                }

                if (!itemDatabase.database[inputItemData].Unique)
                {
                    if (FirstInsert == true)
                    {
                        Count--;
                    }

                    itemMap[inputItemData].Count += Count;
                }

                return(true);
            }

            return(false);
        }
コード例 #2
0
        /// <summary>
        /// Method which is called implicitly by Unity on start up
        /// </summary>
        public void Awake()
        {
            //creation of the Inventory and the ItemDataBase
            ItemInventory = Resources.Load <Inventory>("ScriptableObjects/Inventories/PlayerInventory");
            itemDatabase  = Resources.Load <ItemDataBase>("ScriptableObjects/ItemDataBase");
            //Dragon = Resources.Load<DragonData>("ScriptableObjects/Dragons");
            GlobalFlags.PlayerInventory = ItemInventory;


            Player.ItemUsed = string.Empty;

            //Initially draws the inventory slots
            CreateInventorySlot();
        }