有谁知道如何将字典数据或数组列表数据更有效地保存到playerprefs?
例如,我有一个课程项目:
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
// Make Class Item
public class item {
public string itemName;
public int itemID;
public string itemDesc;
public string itemIcon;
public GameObject itemModel;
public int itemTime;
public int hightprice;
public int stdprice;
public int itemStock;
public int harvest;
public RawTree rawTree;
public ItemType itemType;
public ItemProd itemProd;
public ItemLocation itemLocation;
public ItemMerchant itemMerchant;
public int Lvlunlock;
private string baseName;
public int spawnRate;
public int minqtySpawnBuy;
public int maxqtySpawnBuy;
public int minqtySpawnSell;
public int maxqtySpawnSell;
public int itemExp;
public enum ItemType {
Raw,
Admirable,
Valuable
}
public enum RawTree {
BigTree,
SmallTree,
Field,
None
}
public enum ItemProd {
Corps,
Dairy,
JuiceJamMaker,
Kitchen,
Bakery,
CraftHouse,
ChickenCoop,
FishingSpotMountain,
CowPasture,
LunaMine,
PigPen,
FishingSpotLake,
TropicalWood,
SheepPasture,
FishingSpotSea,
Beebox,
HomeIndustry,
Merchant
}
public enum ItemLocation {
Home,
Orchard,
Forest
}
public enum ItemMerchant {
Margaret,
Lucy,
Bobby,
Roger,
Grace
}
public item (string name, int ID, string desc, int harvestx, int time, int stdpricex, int hightpricex, int stock, int Lvlunlockx, RawTree RawTree, ItemType type, ItemProd prod, string folderx, ItemLocation location, ItemMerchant merchant, int rate, int minspawnBuy, int maxspawnBuy, int minspawnSell, int maxspawnSell, int Exp) {
itemName = name;
itemID = ID;
itemDesc = desc;
harvest = harvestx;
itemTime = time;
stdprice = stdpricex;
hightprice = hightpricex;
itemStock = stock;
Lvlunlock = Lvlunlockx;
rawTree = RawTree;
itemType = type;
itemProd = prod;
itemIcon = folderx;
itemLocation = location;
itemMerchant = merchant;
spawnRate = rate;
minqtySpawnBuy = minspawnBuy;
maxqtySpawnBuy = maxspawnBuy;
minqtySpawnSell = minspawnSell;
maxqtySpawnSell = maxspawnSell;
itemExp = Exp;
}
public item() {
}
}
然后,我将创建一个列表项:
public List<item> items = new List<item> ();
第一:如何将物品保存到更有效的播放器中?
例如我在字典上有数据:
public Dictionary <string, Dictionary <string, int> > productSellMargaret;
第二:如何更有效地将productSellMargaret产品保存到Playerprefs中?
如何将它们都保存到playerprefs中,以便退出游戏并继续播放继续数据时可以继续调用数据?
一个准确的答案是
“不要将更大的数据保存到PlayerPrefs中”
PlayerPrefs
用于保存较小的值,例如游戏设置等。在PlayerPrefs中保存这种配置是一种很好的方法。
但
在保存大型数据时,例如对象列表或嵌套字典。建议将其存储到文件中。
我应该如何解析数据对象并将其保存到文件中?
有不同的方法可以做到这一点。其中之一是使用序列化数据对象,然后使用BinaryFormatter
将其保存到文件中System.IO
。有关实现此目标的快速教程,请参考:TutsPlus:如何在Unity中保存和加载播放器的进度
同样,这只是一种实现方式。您也可以使用其他方法。Unity的新JSON序列化器对您来说是另一个不错的选择。
希望这可以帮助。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句