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

            ExtractSerializedInventory(serializedInventory);
            MMEventManager.TriggerEvent(new MMInventoryEvent(MMInventoryEventType.InventoryLoaded, null, this.name, null, 0, 0));
        }
Exemple #2
0
        /// <summary>
        /// Saves the inventory to a file
        /// </summary>
        public virtual void SaveInventory()
        {
            SerializedInventory serializedInventory = new SerializedInventory();

            FillSerializedInventory(serializedInventory);
            SaveLoadManager.Save(serializedInventory, gameObject.name + _saveFileExtension, _saveFolderName);
        }
Exemple #3
0
 /// <summary>
 /// Fills the serialized inventory for storage
 /// </summary>
 /// <param name="serializedInventory">Serialized inventory.</param>
 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;
         }
     }
 }
Exemple #4
0
        /// <summary>
        /// Extracts the serialized inventory from a file content
        /// </summary>
        /// <param name="serializedInventory">Serialized inventory.</param>
        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)
                {
                    Content[i]          = Resources.Load <InventoryItem>(_resourceItemPath + serializedInventory.ContentType[i]).Copy();
                    Content[i].Quantity = serializedInventory.ContentQuantity[i];
                }
                else
                {
                    Content[i] = null;
                }
            }
        }