Esempio n. 1
0
    // Use this for initialization
    void Start()
    {
        //Caching.ClearCache();
        Caching.compressionEnabled = true;
        var clist = new List <string>();

        Caching.GetAllCachePaths(clist);

        for (int i = 0; i < clist.Count; i++)
        {
            print("cacheCount: " + Caching.cacheCount + " \n\r <color=red>占用缓存路径:" + clist[i] + "</color>");
            local_cacheBundle_path = clist[i];
            print("<color=red>persistentDataPath:</color> " + Application.persistentDataPath);
            print("<color=red>dataPath:</color> " + Application.dataPath);
            print("<color=red>temporaryCachePath:</color> " + Application.temporaryCachePath);
            print("<color=red>streamingAssetsPath:</color> " + Application.streamingAssetsPath);
        }
        //Caching.ClearCache();
        //return;

        //string pathSaveAt = "file:///"+Application.persistentDataPath+ "/iOS/";
        //string pathSaveAt = "file://" + Path.Combine(Application.dataPath, "iOS");

        //string pathSaveAt = GetPath() + "/iOS/";
        //if (!Directory.Exists(pathSaveAt))
        //{
        //    Directory.CreateDirectory(pathSaveAt);
        //}

        StartCoroutine(Initial_DownLoadAssetBundle(PLATFORM));

        StartCoroutine(LoadFromFile("a", "Workshop Set"));
        StartCoroutine(LoadFromFile("b", "Cube"));
    }
Esempio n. 2
0
    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);
    }
Esempio n. 3
0
    private void setLocalCache()// no useful in dll lib, only useful in UnityEngine Project
    {
        var clist = new List <string>();

        Caching.GetAllCachePaths(clist);

        for (int i = 0; i < clist.Count; i++)
        {
            print("cacheCount: " + Caching.cacheCount + " \n\r <color=red>占用缓存路径:" + clist[i] + "</color>");
            local_cacheBundle_path = clist[i];
            print("<color=red>persistentDataPath:</color> " + Application.persistentDataPath);
            print("<color=red>dataPath:</color> " + Application.dataPath);
            print("<color=red>temporaryCachePath:</color> " + Application.temporaryCachePath);
            print("<color=red>streamingAssetsPath:</color> " + Application.streamingAssetsPath);
        }
    }
    public static int GetAllCachePaths_s(IntPtr l)
    {
        int result;

        try
        {
            List <string> cachePaths;
            LuaObject.checkType <List <string> >(l, 1, out cachePaths);
            Caching.GetAllCachePaths(cachePaths);
            LuaObject.pushValue(l, true);
            result = 1;
        }
        catch (Exception e)
        {
            result = LuaObject.error(l, e);
        }
        return(result);
    }
    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);
    }
Esempio n. 6
0
    void Awake()
    {
        Debug.Log($"Current cache: {Caching.defaultCache.path}");

        var cachePaths = new List <string>();

        Caching.GetAllCachePaths(cachePaths);
        foreach (var cachePath in cachePaths)
        {
            Debug.Log($"Cache path: {cachePath}");
        }

        Addressables.ResourceManager.ResourceProviders.Add(new FirebaseStorageAssetBundleProvider());
        Addressables.ResourceManager.ResourceProviders.Add(new FirebaseStorageJsonAssetProvider());
        Addressables.ResourceManager.ResourceProviders.Add(new FirebaseStorageHashProvider());

        // Make sure to continue on MAIN THREAD for addressables initialization
        Firebase.FirebaseApp.CheckAndFixDependenciesAsync().ContinueWithOnMainThread(task => {
            var dependencyStatus = task.Result;
            if (dependencyStatus == Firebase.DependencyStatus.Available)
            {
                // Create and hold a reference to your FirebaseApp,
                // where app is a Firebase.FirebaseApp property of your application class.
                //   app = Firebase.FirebaseApp.DefaultInstance;

                Debug.Log("FIREBASE INIT FINISHED");
                FirebaseAddressablesManager.IsFirebaseSetupFinished = true;

                // Set a flag here to indicate whether Firebase is ready to use by your app.
            }
            else
            {
                UnityEngine.Debug.LogError(System.String.Format(
                                               "Could not resolve all Firebase dependencies: {0}", dependencyStatus));
                // Firebase Unity SDK is not safe to use here.
            }
        });
    }
Esempio n. 7
0
        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);
        }
Esempio n. 8
0
    public async UniTask Initialize()
    {
        // Get built-in catalog first
        BundleCatalog builtInCatalog;

        using (var request = UnityWebRequest.Get(BuiltInCatalogPath))
        {
            await request.SendWebRequest();

            var text = Encoding.UTF8.GetString(request.downloadHandler.data);
            builtInCatalog = new BundleCatalog(JObject.Parse(text));
        }

        // Then the cached catalog
        if (File.Exists(CachedCatalogPath))
        {
            Debug.Log($"[BundleManager] Reading cached catalog from {CachedCatalogPath}");
            using (var request = UnityWebRequest.Get("file://" + CachedCatalogPath))
            {
                var valid = true;
                try
                {
                    await request.SendWebRequest();

                    if (request.isHttpError || request.isNetworkError)
                    {
                        throw new Exception(request.error);
                    }
                    var text = Encoding.UTF8.GetString(request.downloadHandler.data);
                    Catalog = new BundleCatalog(JObject.Parse(text));
                    foreach (var bundleName in builtInCatalog.GetEntryNames())
                    {
                        if (!Catalog.ContainsEntry(bundleName))
                        {
                            valid = false;
                            break;
                        }

                        var cachedVersion  = Catalog.GetEntry(bundleName).version;
                        var builtInVersion = builtInCatalog.GetEntry(bundleName).version;
                        if (builtInVersion > cachedVersion)
                        {
                            Debug.Log($"[BundleManager] Bumping {bundleName} from {cachedVersion} to {builtInVersion}");
                            Catalog.SetEntry(bundleName, Catalog.GetEntry(bundleName).JsonDeepCopy().Also(it => it.version = builtInVersion));
                        }
                    }
                }
                catch (Exception e)
                {
                    Debug.LogWarning(e);
                    valid = false;
                }

                if (!valid)
                {
                    Debug.Log($"[BundleManager] Invalid cached catalog! Using built-in catalog");
                    Catalog = builtInCatalog;
                }
            }
        }
        else
        {
            Catalog = builtInCatalog;
        }

        var cachePaths = new List <string>();

        Caching.GetAllCachePaths(cachePaths);
        cachePaths.ForEach(it => Debug.Log($"[BundleManager] Cache path: {it}"));

        // Always cache built in bundles
        foreach (var bundle in builtInCatalog.GetEntryNames())
        {
            if (IsCached(bundle) && IsUpToDate(bundle))
            {
                Debug.Log($"[BundleManager] Built-in bundle {bundle} is cached and up-to-date (version {Catalog.GetEntry(bundle).version})");
                continue;
            }
            await LoadBundle(bundle, true, false);

            Release(bundle);
        }
    }