2016-07-19 3 views
1

辞書データや配列リストデータをより効率的に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に保存すると、ゲームを終了して継続データを再生するときにデータを呼び出すことができますか?

+0

Playerprefには特定のデータタイプしか保持できません。これは、あなたがファイル(txtまたはバイナリ)を書いたり読んだりする方が速くて効率的だと言われています。 – Cabrra

+0

オブジェクトをJSONに解析し、ファイルに保存します。 –

+0

こんにちは@UmairM、私はこのNewtonsoft.Json.Serializationを見つけました。それをjsonに変換することができます。しかし、私はそれを統一の中でどのように呼び出すのか分かりません。私はnewtonを使用して入力しようとしましたが、ファイル名newtonを使用していません。アイデアはありますか? –

答えて

0

正確な答えは

PlayerPrefs「PlayerPrefsに大きなデータを保存しない」ことになるがゲームの設定のような小さな値を保存するために使用されるなどの保存PlayerPrefsにおける構成のこの種は、それを行う良い方法。

しかし

それがオブジェクトまたはネストされた辞書のリストのような大規模なデータを保存しています。それをファイルに保存することをお勧めします。

データオブジェクトをどのように解析してファイルに保存する必要がありますか?

  1. これにはさまざまな方法があります。それらの1つはBinaryFormatterを使用してデータオブジェクトをシリアライズし、System.IOを使用してファイルに保存しています。これを達成するための簡単なチュートリアルでは、TutsPlus: How to Save and Load Your Players' Progress in Unity

  2. を参照してください。これもやはりこれを行う方法の1つに過ぎません。他の方法も使用できます。 Unityの新しいJSON Serializerはあなたにとってもう一つの良い選択肢です。

  3. JSONの代わりにXMLを使用したい場合は、XML Serializerをお勧めします。

希望します。

+0

こんにちは@Umair、私はそれを試してみます。私に問題があるなら、私は再び尋ねます。あなたはすでにそれを考え出したようなあなたの推薦コードセーブデータをしようとしているときに感謝 –

+0

こんにちは@Umairが、私は問題を抱えて、あなたがこのリンクをチェックしてくださいでした[リンク](http://stackoverflow.com/q/38473144/6521156)のおかげ –

+0

のようです: ) –

関連する問題