public Loader( string downloadRoot, IAssetBundleDatabase database) { string storageCacheRoot = null; #if UNITY_EDITOR || UNITY_STANDALONE_OSX storageCacheRoot = Application.dataPath + "/.."; #elif UNITY_STANDALONE_WIN || UNITY_STANDALONE_LINUX storageCacheRoot = Application.dataPath; #endif if (storageCacheRoot != null) { storageCacheRoot += "/AssetBundleCache/"; Directory.CreateDirectory(storageCacheRoot); Caching.currentCacheForWriting = Caching.AddCache(storageCacheRoot); } _database = database; _downloadRoot = downloadRoot; _abHandles = new Dictionary <string, AssetBundleHandle>(); _notReferencedAbHandles = new List <AssetBundleHandle>(); _loadingHandles = new Dictionary <string, AssetHandle>(); _completeHandles = new Dictionary <string, AssetHandle>(); _tmpHandleList = new List <AssetHandle>(); _unloadingAssetHandles = new List <AssetHandle>(); _lock = new object(); }
public static void SetupCachePath() { try { if (!Caching.GetCacheByPath(CachePath).valid) { if (!Directory.Exists(CachePath)) { Directory.CreateDirectory(CachePath); } Cache newCache = Caching.AddCache(CachePath); //Set current cache for writing to the new cache if the cache is valid if (newCache.valid) { Caching.currentCacheForWriting = newCache; } } } catch (Exception ex) { Debug.Log(ex.Message); } }
void Start() { if (!Directory.Exists(_cachePath)) { Directory.CreateDirectory(_cachePath); } Caching.currentCacheForWriting = Caching.AddCache(_cachePath); Addressables.InitializeAsync().Completed += InitCompletedCallback; }
IEnumerator CoPrepare(Mode mode) { if (_writer != null) { while (_writer.restBytes > 0) // 書き込み待ち { yield return(null); } _writer.Dispose(); _writer = null; } var cache = Caching.GetCacheByPath(_cachePath); if (cache.valid) { Caching.RemoveCache(cache); } DeleteCache(_cachePath); try { System.IO.Directory.CreateDirectory(_cachePath); } catch (System.Exception e) { Debug.LogException(e); } if (mode == Mode.UnityWebRequestAssetBundle) { while (!Caching.ready) { yield return(null); } cache = Caching.AddCache(_cachePath); Caching.currentCacheForWriting = cache; } System.GC.Collect(); for (int i = 0; i < 60; i++) // frametimeWatcherのmaxを吐き出させる { yield return(null); } _totalFileCount = _metaData.Length; _doneFileCount = 0; _doneBytes = 0; _maxSpike = 0; _time = 0f; _maxMemory = 0; }
void ClearCacheExample() { Directory.CreateDirectory("Cache1"); Directory.CreateDirectory("Cache2"); Directory.CreateDirectory("Cache3"); Caching.AddCache("Cache1"); Caching.AddCache("Cache2"); Caching.AddCache("Cache3"); bool success = Caching.ClearCache(); if (!success) { Debug.Log("Unable to clear cache"); } }
public static int AddCache_s(IntPtr l) { int result; try { string cachePath; LuaObject.checkType(l, 1, out cachePath); Cache cache = Caching.AddCache(cachePath); LuaObject.pushValue(l, true); LuaObject.pushValue(l, cache); result = 2; } catch (Exception e) { result = LuaObject.error(l, e); } return(result); }
//================================= // 関数 //================================= public RuntimeManifestLoader(IManifestConfig config, RuntimePlatform platform) { m_versionLoader = config.BuildVersionLoader(platform); var location = config.GetSaveStorage(platform); var dirPath = location.BasePath; if (!Directory.Exists(dirPath)) { Directory.CreateDirectory(dirPath); } var cache = Caching.GetCacheByPath(dirPath); if (cache.valid) { m_cache = cache; return; } m_cache = Caching.AddCache(dirPath); }
public LoadMgr() { if (ConstantData.EnableCache) { Caching.compressionEnabled = false; string path = ConstantData.UnpackPath; FileHelper.CreateFileDirectory(path); UnityEngine.Cache cache = Caching.GetCacheByPath(path); if (!cache.valid) { cache = Caching.AddCache(path); } Caching.currentCacheForWriting = cache; } else { if (ConstantData.EnablePatch) { AddSearchPath(ConstantData.PatchPath); } if (ConstantData.EnableCustomCompress) { AddSearchPath(ConstantData.UnpackPath); } } m_task = new LoaderTask(); m_cache = new AssetBundleCache(m_task); m_downloadOrCache = new DownloadOrCache(); Clear(); if (ConstantData.EnableAssetBundle) { //LoadVersion(); } }
private void SetupCache() { string folderName = "SnycedAssetBundle"; var path = System.IO.Path.Combine(Application.persistentDataPath, folderName); if (Directory.Exists(path) == false) { Directory.CreateDirectory(path); } Cache newCache = Caching.AddCache(path); if (newCache.valid) { Caching.currentCacheForWriting = newCache; } //delete oldest caching while (Caching.cacheCount > 5) { Caching.RemoveCache(Caching.GetCacheAt(1)); } }
/// <summary> /// Sets properties of the Caching system. /// </summary> /// <param name="id">The id of thei object.</param> /// <param name="dataStr">The JSON serialized CacheInitializationData object.</param> /// <returns>True if the initialization succeeded.</returns> public bool Initialize(string id, string dataStr) { #if ENABLE_CACHING var data = JsonUtility.FromJson <CacheInitializationData>(dataStr); if (data != null) { Caching.compressionEnabled = data.CompressionEnabled; var activeCache = Caching.currentCacheForWriting; if (!string.IsNullOrEmpty(data.CacheDirectoryOverride)) { var dir = Addressables.ResolveInternalId(data.CacheDirectoryOverride); if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } activeCache = Caching.GetCacheByPath(dir); if (!activeCache.valid) { activeCache = Caching.AddCache(dir); } Caching.currentCacheForWriting = activeCache; } if (data.LimitCacheSize) { activeCache.maximumAvailableStorageSpace = data.MaximumCacheSize; } else { activeCache.maximumAvailableStorageSpace = long.MaxValue; } #pragma warning disable 618 activeCache.expirationDelay = data.ExpirationDelay; #pragma warning restore 618 } #endif //ENABLE_CACHING return(true); }
IEnumerator DownloadAndCacheAssetBundle(string uri, string manifestBundlePath) { //Load the manifest AssetBundle manifestBundle = AssetBundle.LoadFromFile(manifestBundlePath); AssetBundleManifest manifest = manifestBundle.LoadAsset <AssetBundleManifest>("AssetBundleManifest"); //Create new cache string today = DateTime.Today.ToLongDateString(); Directory.CreateDirectory(today); Cache newCache = Caching.AddCache(today); //Set current cache for writing to the new cache if the cache is valid if (newCache.valid) { Caching.currentCacheForWriting = newCache; } //Download the bundle Hash128 hash = manifest.GetAssetBundleHash("bundleName"); UnityWebRequest request = UnityWebRequestAssetBundle.GetAssetBundle(uri, hash, 0); yield return(request.SendWebRequest()); AssetBundle bundle = DownloadHandlerAssetBundle.GetContent(request); //Get all the cached versions List <Hash128> listOfCachedVersions = new List <Hash128>(); Caching.GetCachedVersions(bundle.name, listOfCachedVersions); if (!AssetBundleContainsAssetIWantToLoad(bundle)) //Or any conditions you want to check on your new asset bundle { //If our criteria wasn't met, we can remove the new cache and revert back to the most recent one Caching.currentCacheForWriting = Caching.GetCacheAt(Caching.cacheCount); Caching.RemoveCache(newCache); for (int i = listOfCachedVersions.Count - 1; i > 0; i--) { //Load a different bundle from a different cache request = UnityWebRequestAssetBundle.GetAssetBundle(uri, listOfCachedVersions[i], 0); yield return(request.SendWebRequest()); bundle = DownloadHandlerAssetBundle.GetContent(request); //Check and see if the newly loaded bundle from the cache meets your criteria if (AssetBundleContainsAssetIWantToLoad(bundle)) { break; } } } else { //This is if we only want to keep 5 local caches at any time if (Caching.cacheCount > 5) { Caching.RemoveCache(Caching.GetCacheAt(1)); //Removes the oldest user created cache } } }
private Cache AddCacheSafe(string cachePath) { var tryCache = Caching.GetCacheByPath(cachePath); return(tryCache.valid ? tryCache : Caching.AddCache(cachePath)); }
//public void LoadFromLocal() //{ // string path = ""; // path = "file://" + Application.persistentDataPath + "/ar-exp-saltbrochure-android"; // //path = "file://" + "C:/Users/sricciardi/Desktop/Projects/AR Projects/Salt-Generic-AR-App/Assets/AssetBundles/Android" + "/ar-exp-saltbrochure-android"; // Debug.Log(path); // StartCoroutine(LoadFromMemoryAsync(path)); //} IEnumerator DownloadAndCacheAB(string bundleURLPath, string manifestURLBundlePath) { //AssetBundle manifestBundle = AssetBundle.LoadFromFile(manifestBundlePath); //AssetBundleManifest manifest = manifestBundle.LoadAsset<AssetBundleManifest>("AssetBundleManifest"); string editorManifestFilePath = Application.dataPath + "/AssetBundles/Android/" + ABFileName + ".manifest"; string manifestFilePath = Path.Combine(Application.persistentDataPath, ABmanifestFileName); string bundleFilePath = Path.Combine(Application.persistentDataPath, ABFileName); Debug.Log("Unity Editor manifest path " + editorManifestFilePath); if (Application.isEditor) { DHmanifest = new DownloadHandlerFile(editorManifestFilePath); Debug.Log("I am running in the Unity Editor!"); } else { DHmanifest = new DownloadHandlerFile(manifestFilePath); } //DownloadHandlerFile dh = new DownloadHandlerFile(filePath); //DownloadHandlerAssetBundle DHAB = new DownloadHandlerAssetBundle(bundleFilePath); //DownloadHandler DHmanifest = new DownloadHandlerFile(manifestFilePath); // Correct! UWRmanifest = UnityWebRequest.Get(manifestURLBundlePath); //UWRbundle = UnityWebRequestAssetBundle.GetAssetBundle(bundleURLPath); //uwr.downloadHandler = dhAB; UWRmanifest.downloadHandler = DHmanifest; yield return(UWRmanifest.SendWebRequest()); //UWRbundle.downloadHandler = DHAB; //yield return UWRbundle.SendWebRequest(); //uwr.downloadHandler = dh; //yield return uwr.SendWebRequest(); if (UWRmanifest.isNetworkError || UWRmanifest.isHttpError) { Debug.Log("Network error trying to retrieve the manifest file!"); } else { Debug.Log("There was no Network error, so try to load the Asset Bundle from the local file"); AssetBundle manifestBundle = AssetBundle.LoadFromFile(manifestFilePath); AssetBundleManifest manifest = manifestBundle.LoadAsset <AssetBundleManifest>("AssetBundleManifest"); //Create new cache string today = DateTime.Today.ToLongDateString(); Directory.CreateDirectory(today); Cache newCache = Caching.AddCache(today); //Set current cache for writing to the new cache if the cache is valid if (newCache.valid) { Caching.currentCacheForWriting = newCache; } //Download the bundle Hash128 hash = manifest.GetAssetBundleHash(ABFileName); UnityWebRequest UWRbundleRequest = UnityWebRequestAssetBundle.GetAssetBundle(bundleURLPath, hash, 0); yield return(UWRbundleRequest.SendWebRequest()); AssetBundle UWRbundle = DownloadHandlerAssetBundle.GetContent(UWRbundleRequest); //Get all the cached versions List <Hash128> listOfCachedVersions = new List <Hash128>(); Caching.GetCachedVersions(UWRbundle.name, listOfCachedVersions); if (!AssetBundleContainsAssetIWantToLoad(UWRbundle)) { Caching.currentCacheForWriting = Caching.GetCacheAt(Caching.cacheCount); Caching.RemoveCache(newCache); Debug.Log("There is no Scene in the downloaded Asset Bundle."); for (int i = listOfCachedVersions.Count - 1; i > 0; i--) { //Load a different bundle from a different cache. UWRbundleRequest = UnityWebRequestAssetBundle.GetAssetBundle(bundleURLPath, listOfCachedVersions[i], 0); yield return(UWRbundleRequest.SendWebRequest()); UWRbundle = DownloadHandlerAssetBundle.GetContent(UWRbundleRequest); //Check and see if the newly loaded bundle from the cache meets your criteria. if (AssetBundleContainsAssetIWantToLoad(UWRbundle)) { //This is where I need to load the scene the correct way. break; } } } else { Debug.Log("I found the scene I am looking for in the downloaded version."); } } /* * if (uwr.isNetworkError || uwr.isHttpError) * { * Debug.Log(uwr.error); * } else * { * //Get Asset Bundle * AssetBundle bundle = DownloadHandlerAssetBundle.GetContent(uwr); * * isLoading = true; * * if (uwr.isDone) * { * * //AssetBundleManifest manifest = bundle.LoadAsset<AssetBundleManifest>(bundle.name); * Debug.Log("bundle name " + bundle.name); * Debug.Log("is Streamed Asset Bundle " + bundle.isStreamedSceneAssetBundle); * } * * * //AssetBundle manifestBundle = AssetBundle.LoadFromFile(manifestBundlePath); * //AssetBundleManifest manifest = bundle.LoadAssetAsync<AssetBundleManifest>(ABFileName); * //Debug.Log("manifest " + manifest); * * string[] assetBundlePaths = bundle.GetAllScenePaths(); * * if (assetBundlePaths != null) { * * //AssetBundleLoadOperation request = AssetBundleManager.LoadLevelAsync(sceneAssetBundle, levelName, isAdditive); * //if (request == null) * // yield break; * //yield return StartCoroutine(request); * * for (int i = 0; i < assetBundlePaths.Length; i++) * { * Debug.Log("string # " + i + " is " + assetBundlePaths[i]); * } * } */ //string filePath = Path.Combine(Application.persistentDataPath, ABFileName); //DownloadHandlerFile dh = new DownloadHandlerFile(filePath); //UnityWebRequest requestFile = UnityWebRequest.Get(url); //requestFile.downloadHandler = dh; //yield return requestFile.SendWebRequest(); //if (!requestFile.isHttpError && !requestFile.isNetworkError) //{ // Debug.Log("Download complete, attempting to load bundle."); // AssetBundle bundleFile = AssetBundle.LoadFromFile(filePath); // SceneManager.LoadScene(bundleFile.GetAllScenePaths()[0]); //} //else //{ // Debug.LogError(requestFile.responseCode + ": " + requestFile.error); //} // Load level from assetBundle. ////AssetBundleRequest asset = bundle.LoadAssetAsync<AssetBundleManifest>(ABFileName); //AssetBundleRequest asset = bundle.LoadAsset<AssetBundleManifest>(ABFileName); //yield return asset; ////Get the Asset Bundle Manifest //AssetBundleManifest loadedAssetMf = asset.asset as AssetBundleManifest; ////Get Hash128 from the AssetBundleManifest //Hash128 tempHash128 = loadedAssetMf.GetAssetBundleHash(ABFileName); ////Pass to the isVersionCached function //if (Caching.IsVersionCached(bundlePath, tempHash128)) //{ // isCached = true; // Debug.Log("Bundle is Cached"); //} else //{ // isLoading = true; // Debug.Log("Bundle is Downloading...."); //} ////Caching.IsVersionCached(bundlePath, tempHash128); }