Ejemplo n.º 1
0
    public bool Save()
    {
        using (FileStream fs = ZetanUtility.OpenFile(Application.persistentDataPath + "/" + dataName, FileMode.Create))
        {
            try
            {
                BinaryFormatter bf = new BinaryFormatter();

                SaveData data = new SaveData();

                SaveTime(data);
                SaveBag(data);
                SaveBuilding(data);
                SaveMaking(data);
                SaveWarehouse(data);
                SaveQuest(data);
                SaveDialogue(data);
                SaveTrigger(data);
                SaveActions(data);
                SaveMapMark(data);

                bf.Serialize(fs, data);
                ZetanUtility.Encrypt(fs, encryptKey);

                fs.Close();

                MessageManager.Instance.New("保存成功!");
                return(true);
            }
            catch (Exception ex)
            {
                throw ex;
                Debug.LogWarning(ex.Message);
                if (fs != null)
                {
                    fs.Close();
                }
                MessageManager.Instance.New("保存失败!");
                return(false);
            }
        }
    }
Ejemplo n.º 2
0
    public void Load()
    {
        using (FileStream fs = ZetanUtility.OpenFile(Application.persistentDataPath + "/" + dataName, FileMode.Open))
        {
            try
            {
                BinaryFormatter bf = new BinaryFormatter();

                SaveData data = bf.Deserialize(ZetanUtility.Decrypt(fs, encryptKey)) as SaveData;

                fs.Close();

                StartCoroutine(LoadAsync(data));
            }
            catch (Exception ex)
            {
                if (fs != null)
                {
                    fs.Close();
                }
                Debug.LogWarning(ex.Message);
            }
        }
    }