Example #1
0
        // Tries to load the inventory if a file is present
        public virtual void LoadSavedInventory()
        {
            SerializedInventory serializedInventory = (SerializedInventory)SaveLoadManager.Load(typeof(SerializedInventory), gameObject.name + _saveFileExtension, _saveFolderName);

            ExtractSerializedInventory(serializedInventory);
            InventoryEvent.Trigger(InventoryEventType.InventoryLoaded, null, this.name, null, 0, 0);
        }
Example #2
0
        // Saves the inventory to a file
        public virtual void SaveInventory()
        {
            SerializedInventory serializedInventory = new SerializedInventory();

            FillSerializedInventory(serializedInventory);
            SaveLoadManager.Save(serializedInventory, gameObject.name + _saveFileExtension, _saveFolderName);
        }
Example #3
0
 // Fills the serialized inventory for storage
 protected virtual void FillSerializedInventory(SerializedInventory serializedInventory)
 {
     serializedInventory.InventoryType = InventoryType;
     //serializedInventory.DrawContentInInspector = DrawContentInInspector;
     serializedInventory.ContentType     = new string[Content.Length];
     serializedInventory.ContentQuantity = new int[Content.Length];
     for (int i = 0; i < Content.Length; i++)
     {
         if (!InventoryItem.IsNull(Content[i]))
         {
             serializedInventory.ContentType[i]     = Content[i].ItemID;
             serializedInventory.ContentQuantity[i] = Content[i].Quantity;
         }
         else
         {
             serializedInventory.ContentType[i]     = null;
             serializedInventory.ContentQuantity[i] = 0;
         }
     }
 }
Example #4
0
        // Extracts the serialized inventory from a file content
        protected virtual void ExtractSerializedInventory(SerializedInventory serializedInventory)
        {
            if (serializedInventory == null)
            {
                return;
            }

            InventoryType = serializedInventory.InventoryType;
            //DrawContentInInspector = serializedInventory.DrawContentInInspector;
            Content = new InventoryItem[serializedInventory.ContentType.Length];
            for (int i = 0; i < serializedInventory.ContentType.Length; i++)
            {
                if ((serializedInventory.ContentType[i] != null) && (serializedInventory.ContentType[i] != ""))
                {
                    Content[i]          = Resources.Load <InventoryItem>(_resourceItemPath + serializedInventory.ContentType[i]).Copy();
                    Content[i].Quantity = serializedInventory.ContentQuantity[i];
                }
                else
                {
                    Content[i] = null;
                }
            }
        }