辞書データや配列リストデータをより効率的にplayerprefsに保存する方法を知っている人はいますか?例えば辞書データまたは配列リストデータをplayerprefsにもっと効果的に保存する方法は?
私はクラスのアイテムを持っている:
public List<item> items = new List<item>();
まず: どのようにあなたがよりeffecient 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 Dictionary <string, Dictionary <string, int> > productSellMargaret;
第二:より効率的にplayerprefsするproductSellMargaretを保存する方法 ?
これらを両方ともplayerprefsに保存すると、ゲームを終了して継続データを再生するときにデータを呼び出すことができますか?
Playerprefには特定のデータタイプしか保持できません。これは、あなたがファイル(txtまたはバイナリ)を書いたり読んだりする方が速くて効率的だと言われています。 – Cabrra
オブジェクトをJSONに解析し、ファイルに保存します。 –
こんにちは@UmairM、私はこのNewtonsoft.Json.Serializationを見つけました。それをjsonに変換することができます。しかし、私はそれを統一の中でどのように呼び出すのか分かりません。私はnewtonを使用して入力しようとしましたが、ファイル名newtonを使用していません。アイデアはありますか? –