如何更有效地将字典数据或数组列表数据保存到playerprefs?

刘丹尼斯

有谁知道如何将字典数据或数组列表数据更有效地保存到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中,以便退出游戏并继续播放继续数据时可以继续调用数据?

Umair M

一个准确的答案是

“不要将更大的数据保存到PlayerPrefs中”

PlayerPrefs 用于保存较小的值,例如游戏设置等。在PlayerPrefs中保存这种配置是一种很好的方法。

在保存大型数据时,例如对象列表或嵌套字典。建议将其存储到文件中。

我应该如何解析数据对象并将其保存到文件中?

  1. 有不同的方法可以做到这一点。其中之一是使用序列化数据对象,然后使用BinaryFormatter将其保存到文件中System.IO有关实现此目标的快速教程,请参考:TutsPlus:如何在Unity中保存和加载播放器的进度

  2. 同样,这只是一种实现方式。您也可以使用其他方法。Unity的新JSON序列化器对您来说是另一个不错的选择。

  3. 如果要使用XML而不是XML序列化JSON,那么XML序列化器是一个不错的选择。

希望这可以帮助。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

Spark Streaming:如何有效地将foreachRDD数据保存到Mysql数据库中?

来自分类Dev

如何更有效地将数据框重塑为新形式(R)?

来自分类Dev

如何有效地将字典中的数据添加到数据框中?

来自分类Dev

Android解析。更有效地获取数据?

来自分类Dev

R:更有效地子集数据

来自分类Dev

Android解析。更有效地获取数据?

来自分类Dev

如何有效地将数据框中的条目映射到字典

来自分类Dev

如何有效地将字典的条目转换为数据框

来自分类Dev

如何有效地将字典的条目转换为数据框

来自分类Dev

如何将数据框分为两列并根据组数更有效地计算行数

来自分类Dev

如何使用 PHP 更有效地将 csv 文件导入 MySQL 数据库?

来自分类Dev

如何有效地将树结构保存在数据库中?

来自分类Dev

使用数据框子集更有效地将Python用于循环

来自分类Dev

如何有效地将数组解码为pandas数据框中的列

来自分类Dev

如何更有效地修改熊猫数据框列

来自分类Dev

将具有定义的数据字典的字符串有效地解析为列表

来自分类Dev

将数据帧列表中的数据有效地重新排列到 R 中的数组中?

来自分类Dev

如何使用两个规则有效地将数据帧子集化为列表列表

来自分类Dev

如何有效地将数据帧子集划分为多个块以传递给列表列表

来自分类Dev

更有效地展平和压缩数组

来自分类Dev

我如何定义哪个函数更有效地将数组与自定义模型进行比较

来自分类Dev

如何有效地将数据异步异步地填充到winform DataGridView中?

来自分类Dev

如何在python 3中有效地将原始字节写入numpy数组数据

来自分类Dev

在Racket中更有效地将列表写入文件

来自分类Dev

在Racket中更有效地将列表写入文件

来自分类Dev

如何有效地规范导入数据?

来自分类Dev

如何有效地计算数据

来自分类Dev

Angular:如何有效地检索数据

来自分类Dev

如何有效地重新索引csv数据?

Related 相关文章

  1. 1

    Spark Streaming:如何有效地将foreachRDD数据保存到Mysql数据库中?

  2. 2

    如何更有效地将数据框重塑为新形式(R)?

  3. 3

    如何有效地将字典中的数据添加到数据框中?

  4. 4

    Android解析。更有效地获取数据?

  5. 5

    R:更有效地子集数据

  6. 6

    Android解析。更有效地获取数据?

  7. 7

    如何有效地将数据框中的条目映射到字典

  8. 8

    如何有效地将字典的条目转换为数据框

  9. 9

    如何有效地将字典的条目转换为数据框

  10. 10

    如何将数据框分为两列并根据组数更有效地计算行数

  11. 11

    如何使用 PHP 更有效地将 csv 文件导入 MySQL 数据库?

  12. 12

    如何有效地将树结构保存在数据库中?

  13. 13

    使用数据框子集更有效地将Python用于循环

  14. 14

    如何有效地将数组解码为pandas数据框中的列

  15. 15

    如何更有效地修改熊猫数据框列

  16. 16

    将具有定义的数据字典的字符串有效地解析为列表

  17. 17

    将数据帧列表中的数据有效地重新排列到 R 中的数组中?

  18. 18

    如何使用两个规则有效地将数据帧子集化为列表列表

  19. 19

    如何有效地将数据帧子集划分为多个块以传递给列表列表

  20. 20

    更有效地展平和压缩数组

  21. 21

    我如何定义哪个函数更有效地将数组与自定义模型进行比较

  22. 22

    如何有效地将数据异步异步地填充到winform DataGridView中?

  23. 23

    如何在python 3中有效地将原始字节写入numpy数组数据

  24. 24

    在Racket中更有效地将列表写入文件

  25. 25

    在Racket中更有效地将列表写入文件

  26. 26

    如何有效地规范导入数据?

  27. 27

    如何有效地计算数据

  28. 28

    Angular:如何有效地检索数据

  29. 29

    如何有效地重新索引csv数据?

热门标签

归档