Пример #1
0
    public void ReadTxt()
    {
        string dataPath = Application.persistentDataPath + "/notice.json";
        string infoPath = Application.persistentDataPath + "/Info.txt";

        if (File.Exists(dataPath) && File.Exists(infoPath))        //验证文件是否存在
        {
            string info     = MD5HashFromFile.GetMD5HashFromFile(dataPath);
            string readinfo = File.ReadAllText(infoPath);
            if (info == readinfo)           //验证MD5是否一致
            {
                var txt = File.ReadAllText(dataPath);
                ReadJson(txt);
            }
            else
            {
                Debug.Log("文件被修改,重新从服务器拉取");
                _Notice.Take(false);
            }
        }
        else
        {
            Debug.Log("文件不存在,重新从服务器拉取");
            _Notice.Take(false);
        }
    }
Пример #2
0
    IEnumerator Notifications(bool New)
    {
        using (UnityWebRequest getnotice = UnityWebRequest.Get(url))
        {
            getnotice.timeout = 10;
            yield return(getnotice.SendWebRequest());

            if (getnotice.isHttpError || getnotice.isNetworkError)
            {
                Debug.LogError("错误:无法连接至服务器");
            }
            else
            {
                byte[] results  = getnotice.downloadHandler.data;
                string dataPath = Application.persistentDataPath + "/notice.json";       //公告缓存路径
                string infoPath = Application.persistentDataPath + "/Info.txt";          //MD5储存路径,对比时用
                Debug.Log("正在处理内容,请稍等");
                File.WriteAllText(dataPath, getnotice.downloadHandler.text);             //写入文件
                string info = MD5HashFromFile.GetMD5HashFromFile(dataPath);              //获取文件MD5
                Debug.Log("该公告MD5为:" + info);
                File.WriteAllText(infoPath, info);
                button.interactable = true;
                if (New)
                {
                    notifications.SetActive(true);
                    _NoticeRead.ReadTxt();
                }
                Debug.Log("公告读取完成");
            }
        }
    }