当前位置: 首页> 游戏> 单机 > Unity发布webgl之后修改StreamingAssets 内的配置文件读取到的还是之前的配置文件的解决方案

Unity发布webgl之后修改StreamingAssets 内的配置文件读取到的还是之前的配置文件的解决方案

时间:2025/7/9 14:36:29来源:https://blog.csdn.net/GoodCooking/article/details/140315893 浏览次数:0次

问题描述

unity发布webgl之后,修改在StreamingAssets 中的配置信息,修改之后读取的还是之前的配置信息

读取配置文件的代码IEnumerator IE_WebGL_LoadWebSocketServerCopnfig(){var uri = new System.Uri(Path.Combine(Application.streamingAssetsPath, @"Config\WebServerConfig.txt"));Debug.Log("输出加载路径:" + uri);UnityWebRequest webRequest = UnityWebRequest.Get(uri);yield return webRequest.SendWebRequest();if (webRequest.result == UnityWebRequest.Result.ConnectionError){Debug.LogError("输出报错:" + webRequest.error);}else{var strings = webRequest.downloadHandler.text.Split(':');Debug.Log("加载WebSocketServer配置信息:" + strings[0] + ":" + int.Parse(strings[1]));}}

读取配置文件
在这里插入图片描述

修改配置文件之后再次读取,读取到的是修改之前的。
在这里插入图片描述

解决方案

设置UnityWebRequest 发送的请求头,设置Cache-Control请求头为no-cache来确保每次请求都不会从缓存中读取数据。

    IEnumerator IE_WebGL_LoadWebSocketServerCopnfig(){var uri = new System.Uri(Path.Combine(Application.streamingAssetsPath, @"Config\WebServerConfig.txt"));Debug.Log("输出加载路径:" + uri);UnityWebRequest webRequest = UnityWebRequest.Get(uri);webRequest.SetRequestHeader("Cache-Control", "no-cache");//设置无缓存yield return webRequest.SendWebRequest();if (webRequest.result == UnityWebRequest.Result.ConnectionError){Debug.LogError("输出报错:" + webRequest.error);}else{var strings = webRequest.downloadHandler.text.Split(':');Debug.Log("加载WebSocketServer配置信息:" + strings[0] + ":" + int.Parse(strings[1]));}}

在这里插入图片描述

在这里插入图片描述

关键字:Unity发布webgl之后修改StreamingAssets 内的配置文件读取到的还是之前的配置文件的解决方案

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

责任编辑: