Discussion and help for Easy Save 3
Kosta
Posts: 6 Joined: Wed Jan 01, 2020 3:58 pm
Post
by Kosta » Wed Jan 01, 2020 4:06 pm
I have a custom list for my inventory items.
Now I don't know how to save and load custom list (items).
I guess it needs something like this?
Code: Select all
void SaveInventory()
{
foreach (var i in inventoryItems)
{
ES3.Save<ItemManager>("ItemData", i); // I dont think this is good way to sava list ...???
}
}
void LoadInventory()
{
inventoryItems.Clear();
inventoryItems.Add(ES3.Load("ItemData")); // Not working
//How to load saved data and put that into list (inventoryItems)?
}
I tried to find a tutorial or solution online but there is nothing about it...
Kosta
Posts: 6 Joined: Wed Jan 01, 2020 3:58 pm
Post
by Kosta » Thu Jan 02, 2020 1:39 pm
Hi,
Thanks for your reply.
I try with that but it not working.
Error: NotSupportedException: ES3Type.type is null when trying to create an ES3Type for System.Collections.Generic.List`1[ItemManager], possibly because the element type is not supported.
Code: Select all
void SaveInventory()
{
ES3.Save<List<ItemManager>>("InventoryData", inventoryItems);
}
void LoadInventory()
{
inventoryItems.Clear();
if(ES3.KeyExists("InventoryData"))
{
inventoryItems = ES3.Load<List<ItemManager>>("InventoryData");
}
else
{
SaveInventory();
}
}
Joel
Moodkie Staff
Posts: 4849 Joined: Wed Nov 07, 2012 10:32 pm
Post
by Joel » Thu Jan 02, 2020 2:14 pm
Hi there,
Please could you show me your ItemManager class so I can understand why it is not supported?
All the best,
Joel
Kosta
Posts: 6 Joined: Wed Jan 01, 2020 3:58 pm
Post
by Kosta » Thu Jan 02, 2020 2:25 pm
Code: Select all
using System;
using UnityEngine;
[System.Serializable]
public class ItemManager : IComparable<ItemManager>
{
public ItemType.category itemCategory;
public ItemType.type itemType;
public ItemType.usage itemUsage;
[Tooltip("How much hp (or any other consume) effect on player status. +10hp or -10hp etc...")]
public float itemConsumeAmount;
public Sprite icon;
public bool stackable = false;
public int maxStackable = 8;
[TextArea] public string itemDescription;
public float itemDurability;
[TextArea] public string itemContribution;
public ItemManager(ItemType.category _itemCategory, ItemType.type _itemType,
ItemType.usage _itemUsage, Sprite _icon, bool _stackable, int _maxStackable,
string _itemDescription, float _itemDurability, string _itemContribution, float _itemConsumeAmount)
{
itemCategory = _itemCategory;
itemType = _itemType;
itemUsage = _itemUsage;
icon = _icon;
stackable = _stackable;
maxStackable = _maxStackable;
itemDescription = _itemDescription;
itemDurability = _itemDurability;
itemContribution = _itemContribution;
itemConsumeAmount = _itemConsumeAmount;
}
public int CompareTo(ItemManager other)
{
if(other == null)
{
return 1;
}
return 0;
}
}
Kosta
Posts: 6 Joined: Wed Jan 01, 2020 3:58 pm
Post
by Kosta » Thu Jan 02, 2020 4:03 pm
Thanks a lot!
Empty constructor solves my problem.