コード例 #1
0
    IEnumerator LoadData(int index)
    {
        string folder = string.Empty;

        switch (index)
        {
        case 1: folder = folder1; break;

        case 2: folder = folder2; break;

        case 3: folder = folder3; break;

        default: folder = autoSaveFolder; break;
        }
        if (System.IO.File.Exists(Application.persistentDataPath + folder + "/Data"))
        {
            bool     dataHealth = false;
            string[] data       = new string[13];
            data = System.IO.File.ReadAllLines(Application.persistentDataPath + folder + "/Data", System.Text.Encoding.UTF8);
            int     ID   = 0;
            float   time = 0;
            Vector3 pos  = new Vector3();
            try
            {
                ID = int.Parse(Encryption.Dencrypt(data[3], globalKey));
                //Debug.Log(ID);
                time = float.Parse(Encryption.Dencrypt(data[4], globalKey));
                //Debug.Log(time);
                pos = Newtonsoft.Json.JsonConvert.DeserializeObject <Vector3>(Encryption.Dencrypt(data[5], globalKey));
                //Debug.Log(pos);
                dataHealth = (ID == 100001 || ID == 100002 || ID == 100003) &&
                             MyTools.CompareMD5(Application.persistentDataPath + folder + PlayerInfoManager.DataName, Encryption.Dencrypt(data[6], globalKey)) &&
                             MyTools.CompareMD5(Application.persistentDataPath + folder + BagInfo.DataName, Encryption.Dencrypt(data[7], globalKey)) &&
                             MyTools.CompareMD5(Application.persistentDataPath + folder + WarehouseInfo.DataName, Encryption.Dencrypt(data[8], globalKey)) &&
                             MyTools.CompareMD5(Application.persistentDataPath + folder + PlayerSkillManager.DataName1, Encryption.Dencrypt(data[9], globalKey)) &&
                             MyTools.CompareMD5(Application.persistentDataPath + folder + PlayerSkillManager.DataName2, Encryption.Dencrypt(data[10], globalKey)) &&
                             MyTools.CompareMD5(Application.persistentDataPath + folder + ShopManager.DataName, Encryption.Dencrypt(data[11], globalKey)) &&
                             MyTools.CompareMD5(Application.persistentDataPath + folder + TalkManager.DataName, Encryption.Dencrypt(data[12], globalKey));
            }
            catch
            {
                dataHealth = false;
            }
            if (dataHealth)
            {
                yield return(StartCoroutine(SceneLoader.Instance.LoadScene("WorldMap")));

                switch (ID)
                {
                case 100001: PlayerSelector.Instance.characterType = PlayerCharacterType.Boy; break;

                case 100002: PlayerSelector.Instance.characterType = PlayerCharacterType.Girl; break;

                case 100003: PlayerSelector.Instance.characterType = PlayerCharacterType.LittleGirl; break;
                }
                yield return(StartCoroutine(PlayerSelector.Instance.InitCharacter()));

                yield return(new WaitUntil(() => PlayerInfoManager.Instance.isInit && PlayerSkillManager.Instance && PlayerLocomotionManager.Instance));

                PlayerInfoManager.Instance.LoadPlayerInfo(Application.persistentDataPath + folder, globalKey, true);
                PlayerSkillManager.Instance.LoadFromFile(Application.persistentDataPath + folder, globalKey, true);
                ShopManager.Instance.LoadFromFile(Application.persistentDataPath + folder, globalKey, true);
                PlayerLocomotionManager.Instance.playerController.transform.position = pos;
                FindObjectOfType <MalbersAnimations.Animal>().transform.position     = pos;
                TimeLineManager.Instance.LoadTime(time);
                TalkManager.Instance.Load(Application.persistentDataPath + folder, globalKey, true);
            }
            else
            {
                Debug.Log("存档损坏");
            }
        }
        else
        {
            Debug.Log("存档不存在");
        }
    }