untiy清除緩存目錄
直接放腳本
因?yàn)橛玫氖莾?nèi)嵌網(wǎng)頁(yè)插件,所以每次都要清除一下內(nèi)嵌網(wǎng)頁(yè)瀏覽器緩存,要不然會(huì)導(dǎo)致信息不同步.
導(dǎo)致網(wǎng)頁(yè)已經(jīng)更新,項(xiàng)目開(kāi)啟之后網(wǎng)頁(yè)不會(huì)更新.
using System.IO; using UnityEngine; using Vuplex.WebView; public class CacheManager : MonoBehaviour { // 獲取 Vuplex 緩存目錄 public static string GetVuplexCachePath() { //Debug.Log(Path.Combine(Application.persistentDataPath, "Vuplex.WebView", "chromium-cache", "Cache")); //return Path.Combine(Application.persistentDataPath, "Vuplex.WebView", "chromium-cache", "Cache"); return Path.Combine(Application.persistentDataPath, "Vuplex.WebView", "chromium-cache", "Cache"); } // 啟動(dòng)時(shí)清理選項(xiàng) [SerializeField] private bool clearCacheOnStart = false; void Awake() { if (clearCacheOnStart) { ClearAllCache(); } // 打印路徑信息,方便調(diào)試 //Debug.Log($"Company Name: {Application.companyName}"); //Debug.Log($"Product Name: {Application.productName}"); Debug.Log($"Persistent Data Path: {Application.persistentDataPath}"); } public void ClearAllCache() { string cachePath = GetVuplexCachePath(); if (Directory.Exists(cachePath)) { try { Directory.Delete(cachePath, true); Debug.Log("Cache cleared successfully"); } catch (System.Exception e) { Debug.LogError($"Failed to clear cache: {e.Message}"); } } // 同時(shí)調(diào)用 Vuplex 的清理方法 //Web.ClearAllData(); } }
直接運(yùn)行測(cè)試就好

浙公網(wǎng)安備 33010602011771號(hào)