示例#1
0
        //保存人物背包信息
        public static void SavePackageData(Inventtory data)
        {
            InventtoryList _myItems = null;
            string         filePath = Application.dataPath + @"/Resources/Settings/package.json";

            if (!File.Exists(filePath))
            {
                _myItems = new InventtoryList();
                _myItems._myItems.Add(data);
            }
            else
            {
                bool bFind = false;
                _myItems = PlayerIO.getPackItems();
                for (int i = 0; i < _myItems._myItems.Count; ++i)
                {
                    Inventtory saveData = _myItems._myItems[i];
                    if (data.Slot == saveData.Slot)
                    {
                        saveData.id     = data.id;
                        saveData.Count  = data.Count;
                        saveData.Damage = data.Damage;
                        bFind           = true;
                        break;
                    }
                }
                if (!bFind)
                {
                    _myItems._myItems.Add(data);
                }
            }

            FileInfo     file = new FileInfo(filePath);
            StreamWriter sw   = file.CreateText();
            string       json = JsonMapper.ToJson(_myItems);

            sw.WriteLine(json);
            sw.Close();
            sw.Dispose();
        }
示例#2
0
 // Use this for initialization
 void Start()
 {
     saveBtn.onClick.AddListener(delegate() {
         Items.save(PlayerIO.getPackItems());
     });
 }