|
Post by jrackley on Jul 7, 2017 5:19:56 GMT
Can anyone spot what I am doing wrong here? I am trying to save the inventory and load it with easy save 2. It works once in awhile but mostly not,lol!
for saving I have the following in my method...
#region ---Save Inventory---- for (int i = 0; i < vItemManager.instance.inventory.items.Count; i++) { items.Add(new InventoryItemsData(vItemManager.instance.inventory.items[i].id, vItemManager.instance.inventory.items[i].amount)); } writer.Write(this.items); and then for loading I have...
#region ---Load Inventory--- // Clear Starting Items for (int i = 0; i < vItemManager.instance.items.Count; i++) { vItemManager.instance.LeaveItem(vItemManager.instance.items[i], vItemManager.instance.items[i].amount); }
this.items = reader.ReadList<InventoryItemsData>(); foreach (InventoryItemsData item in items) { Debug.Log("ITEM ID" + item.ID + "ITEM AMOUNT " + item.Amount); var reference = new ItemReference(item.ID); reference.id = item.ID; reference.amount = item.Amount; Debug.Log("REFERENCE ID " + reference.id + " REFERENCE AMOUNT " + reference.amount); vItemManager.instance.AddItem(reference);
} The console debug shows the items and amounts when first entering playmode, but then if I stop and hit play again they are gone out of the inventory.
Thanks to anyone that spots what I am doing wrong here in advance.
|
|
|
Post by jrackley on Jul 7, 2017 21:46:02 GMT
Ahah! pretty sure I figured it out, had the wrong UI in somehow,lol! doing more tests now.
|
|
cyhak
Full vMember
Posts: 80
|
Post by cyhak on Jul 18, 2018 16:45:21 GMT
Hi, jrackley can you help me with a simple save load item system ? I would pay you. I am a noob
I use this to get all weapon id's :
foreach (var ItemReference in itemManager.items) {
Debug.Log (ItemReference.id);
}
I dont know how to save this ids into player prefs ? If i manage this i want to add the weapons per this script:
if (itemManager) { var reference = new ItemReference (3); reference.amount = 1; reference.autoEquip = true; itemManager.AddItem (reference);
|
|