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); } }
public static long GetAllCachedSize() { long cacheSize = 0; var cachePaths = new List <string>(); Caching.GetAllCachePaths(cachePaths); foreach (string cachePath in cachePaths) { var cache = Caching.GetCacheByPath(cachePath); cacheSize += cache.spaceOccupied; } return(cacheSize); }
public IEnumerator CacheInitializationObject_FullySetsCachingData() { #if ENABLE_CACHING //SaveData for cleanup CacheInitializationData preTestCacheData = new CacheInitializationData() { CacheDirectoryOverride = Caching.currentCacheForWriting.path, CompressionEnabled = Caching.compressionEnabled, ExpirationDelay = Caching.currentCacheForWriting.expirationDelay, MaximumCacheSize = Caching.currentCacheForWriting.maximumAvailableStorageSpace }; string cacheDirectoryOverride = "TestDirectory"; int expirationDelay = 4321; long maxCacheSize = 9876; bool compressionEnabled = !preTestCacheData.CompressionEnabled; CacheInitializationData cacheData = new CacheInitializationData() { CacheDirectoryOverride = cacheDirectoryOverride, CompressionEnabled = compressionEnabled, ExpirationDelay = expirationDelay, LimitCacheSize = true, MaximumCacheSize = maxCacheSize }; string json = JsonUtility.ToJson(cacheData); CacheInitialization ci = new CacheInitialization(); var handle = ci.InitializeAsync(m_Addressables.ResourceManager, "TestCacheInit", json); yield return(handle); Assert.AreEqual(cacheDirectoryOverride, Caching.currentCacheForWriting.path); Assert.AreEqual(expirationDelay, Caching.currentCacheForWriting.expirationDelay); Assert.AreEqual(compressionEnabled, Caching.compressionEnabled); Assert.AreEqual(maxCacheSize, Caching.currentCacheForWriting.maximumAvailableStorageSpace); //Cleanup Cache cache = Caching.GetCacheByPath(preTestCacheData.CacheDirectoryOverride); Caching.compressionEnabled = preTestCacheData.CompressionEnabled; cache.maximumAvailableStorageSpace = preTestCacheData.MaximumCacheSize; cache.expirationDelay = preTestCacheData.ExpirationDelay; Caching.currentCacheForWriting = cache; handle.Release(); #else yield return(null); Assert.Ignore(); #endif }
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; }
public static int GetCacheByPath_s(IntPtr l) { int result; try { string cachePath; LuaObject.checkType(l, 1, out cachePath); Cache cacheByPath = Caching.GetCacheByPath(cachePath); LuaObject.pushValue(l, true); LuaObject.pushValue(l, cacheByPath); 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 static void ClearAssetBundleCache() { //Get all cache paths... in Unity's unique way.... var cachePaths = new List<string>(); Caching.GetAllCachePaths(cachePaths); //what?! why?! WHY!?!? foreach (var s in cachePaths) { var cache = Caching.GetCacheByPath(cachePaths[0]); Logger.Log(("Cache location: " + s),Colors.Yellow); Logger.Log(("Cache was using: " + cache.spaceOccupied / 1024f / 1024f + " MB"),Colors.Yellow); cache.ClearCache(); Logger.Log("Cache cleared.",Colors.Yellow); } if (cachePaths.Count < 1) Logger.Log("Cache was empty.",Colors.Yellow); }
/// <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); }
public static bool InspectInspector() { var changed = false; if ("Coroutines [{0}]".F(QcAsync.GetActiveCoroutinesCount).enter(ref inspectedSection, 0).nl()) { QcAsync.InspectManagedCoroutines().nl(ref changed); } "Screen Shots".enter_Inspect(screenShots, ref inspectedSection, 1).nl(ref changed); "Json Inspector".enter_Inspect(jsonInspector, ref inspectedSection, 2).nl(); if ("ICfg Inspector".enter(ref inspectedSection, 3).nl()) { iCfgExplorer.Inspect(null).nl(ref changed); } if ("Gui Styles".enter(ref inspectedSection, 4).nl()) { PEGI_Styles.Inspect().nl(); } if ("Data".enter(ref inspectedSection, 5).nl()) { if (inspectedData == -1) { if ("Player Data Folder".Click().nl()) { QcFile.Explorer.OpenPersistentFolder(); pegi.SetCopyPasteBuffer(Application.persistentDataPath, sendNotificationIn3Dview: true); } if (Application.isEditor && "Editor Data Folder".Click().nl()) { QcFile.Explorer.OpenPath( "C:/Users/{0}/AppData/Local/Unity/Editor/Editor.log".F(Environment.UserName)); } } if ("Cache".enter(ref inspectedData, 1).nl()) { if ("Caching.ClearCache() [{0}]".F(Caching.cacheCount).ClickConfirm("clCach").nl()) { if (Caching.ClearCache()) { pegi.GameView.ShowNotification("Bundles were cleared"); } else { pegi.GameView.ShowNotification("ERROR: Bundles are being used"); } } List <string> lst = new List <string>(); Caching.GetAllCachePaths(lst); "Caches".edit_List(ref lst, path => { var c = Caching.GetCacheByPath(path); if (icon.Delete.Click()) { if (Caching.RemoveCache(c)) { pegi.GameView.ShowNotification("Bundle was cleared"); } else { pegi.GameView.ShowNotification("ERROR: Bundle is being used"); } } if (icon.Folder.Click()) { QcFile.Explorer.OpenPath(path); } if (icon.Copy.Click()) { pegi.SetCopyPasteBuffer(path); } path.write(); return(path); }); } } if ("Profiler".enter(ref inspectedSection, 6).nl()) { "Mono Heap Size Long {0}".F(Profiler.GetMonoHeapSizeLong().ToMegabytes()).nl(); "Mono Used Size Long {0}".F(Profiler.GetMonoUsedSizeLong().ToMegabytes()).nl(); "Temp Allocated Size {0}".F(Profiler.GetTempAllocatorSize().ToMegabytes()).nl(); "Total Allocated Memmory Long {0}".F(Profiler.GetTotalAllocatedMemoryLong().ToMegabytes()).nl(); "Total Unused Reserved Memmory Long {0}".F(Profiler.GetTotalUnusedReservedMemoryLong().ToMegabytes()).nl(); if ("Unload Unused Assets".Click().nl()) { Resources.UnloadUnusedAssets(); } } if ("Time & Audio".enter(ref inspectedSection, 7).nl()) { "Time.time: {0}".F(QcSharp.SecondsToReadableString(Time.time)).nl(); "AudioSettings.dspTime: {0}".F(QcSharp.SecondsToReadableString(AudioSettings.dspTime)).nl(); "Use it to schedule Audio Clips: audioSource.PlayScheduled(AudioSettings.dspTime + 0.5);".writeHint(); "Clip Duration: double duration = (double)AudioClip.samples / AudioClip.frequency;".writeHint(); "Time.unscaled time: {0}".F(QcSharp.SecondsToReadableString(Time.unscaledTime)).nl(); "Time.frameCount: {0}".F(Time.frameCount).nl(); var tScale = Time.timeScale; if ("Time.timescale".edit(ref tScale, 0f, 4f)) { Time.timeScale = tScale; } if (tScale != 1 && icon.Refresh.Click()) { Time.timeScale = 1; } pegi.nl(); "Time.deltaTime: {0}".F(QcSharp.SecondsToReadableString(Time.deltaTime)).nl(); "Time.realtimeSinceStartup {0}".F(QcSharp.SecondsToReadableString(Time.realtimeSinceStartup)).nl(); var fr = Application.targetFrameRate; if ("Frame-Rate".edit(ref fr).nl() && fr > 0) { Application.targetFrameRate = fr; } } return(changed); }
private Cache AddCacheSafe(string cachePath) { var tryCache = Caching.GetCacheByPath(cachePath); return(tryCache.valid ? tryCache : Caching.AddCache(cachePath)); }