public void StartCaching(IList <ContentManifest.BundleEntry> sortedBundles, PrecacheComplete callback, bool cacheInBackground = false)
 {
     caching          = true;
     background       = cacheInBackground;
     completeCallback = callback;
     CoroutineRunner.StartPersistent(CacheBundles(sortedBundles), this, "BundlePrecacheManager.cacheBundles()");
 }
Exemplo n.º 2
0
        private AssetRequest <TAsset> loadAsync <TAsset>(string key, AssetLoadedHandler <TAsset> handler = null) where TAsset : class
        {
            ContentManifest.AssetEntry entry = getAssetEntry(key);
            TAsset indexedAsset = getIndexedAsset <TAsset>(entry.Key);
            AssetRequest <TAsset> assetRequest;
            CoroutineReturn       value;

            if (indexedAsset != null)
            {
                assetRequest = new IndexedAssetRequest <TAsset>(entry.Key, indexedAsset);
                if (handler != null)
                {
                    CoroutineRunner.StartPersistent(waitOneFrameBeforeCallingHandler(key, indexedAsset, handler), this, "waitOneFrameBeforeCallingHandler");
                }
            }
            else if (!activeRequests.TryGetValue(entry.Key, out value))
            {
                activeRequestHandlers.Add(entry.Key, new List <object>());
                assetRequest = loadAsyncEntry(ref entry, handler);
                activeRequests.Add(entry.Key, assetRequest);
            }
            else
            {
                if (handler != null)
                {
                    activeRequestHandlers[entry.Key].Add(handler);
                }
                assetRequest = (AssetRequest <TAsset>)value;
            }
            if (assetRequest == null)
            {
                Log.LogError(this, "Failed to load " + key);
            }
            return(assetRequest);
        }
Exemplo n.º 3
0
        public override AssetRequest <TAsset> LoadAsync <TAsset>(string deviceList, ref ContentManifest.AssetEntry entry, AssetLoadedHandler <TAsset> handler = null)
        {
            if (bundleManager.IsUnmounting(entry.BundleKey))
            {
                bundleManager.CancelUnmount(entry.BundleKey);
            }
            AssetRequest <TAsset> assetRequest;

            if (bundleManager.IsMounted(entry.BundleKey))
            {
                BundleMount bundle = bundleManager.GetBundle(entry.BundleKey);
                if (entry.Extension.Equals("unity"))
                {
                    assetRequest          = new SceneAssetBundleRequest <TAsset>(entry.Key, entry.BundleKey, null);
                    assetRequest.Finished = true;
                }
                else
                {
                    assetRequest = bundle.LoadAsync(entry.Key, entry.AssetPath, handler);
                }
            }
            else
            {
                AsyncAssetBundleRequest <TAsset> asyncAssetBundleRequest = ((!entry.Extension.Equals("unity")) ? new AsyncAssetBundleRequest <TAsset>(entry.Key, null) : new SceneAssetBundleRequest <TAsset>(entry.Key, entry.BundleKey, null));
                assetRequest = asyncAssetBundleRequest;
                CoroutineRunner.StartPersistent(loadBundleAndDependenciesAsync(deviceList, entry, asyncAssetBundleRequest, handler), this, "loadBundleAndDependenciesAsync");
            }
            return(assetRequest);
        }
Exemplo n.º 4
0
        public override AssetRequest <TAsset> LoadAsync <TAsset>(string deviceList, ref ContentManifest.AssetEntry entry, AssetLoadedHandler <TAsset> handler = null)
        {
            AssetBundleCreateWrapper          assetBundleCreateWrapper = new AssetBundleCreateWrapper(null);
            AsyncBundleCreateRequest <TAsset> result = new AsyncBundleCreateRequest <TAsset>(entry.Key, assetBundleCreateWrapper);

            CoroutineRunner.StartPersistent(waitForBundleToCreate(entry.Key, assetBundleCreateWrapper, handler), this, "waitForBundleToCreate");
            return(result);
        }
Exemplo n.º 5
0
        public override AssetRequest <TAsset> LoadAsync <TAsset>(string deviceList, ref ContentManifest.AssetEntry entry, AssetLoadedHandler <TAsset> handler = null)
        {
            AssetRequestWrapper <TAsset> request           = new AssetRequestWrapper <TAsset>(null);
            AsyncAssetRequest <TAsset>   asyncAssetRequest = new AsyncAssetRequest <TAsset>(entry.Key, request);

            CoroutineRunner.StartPersistent(waitForFileStreamAssetToLoad(asyncAssetRequest, entry.AssetPath, handler), this, "waitForFileStreamAssetToLoad");
            return(asyncAssetRequest);
        }
 public void StartCaching(PrecacheComplete callback, bool cacheInBackground = false)
 {
     completeRatio    = 0f;
     caching          = true;
     background       = cacheInBackground;
     completeCallback = callback;
     CoroutineRunner.StartPersistent(CacheBundles(), this, "BundlePrecacheManager.cacheBundles()");
 }
        public override AssetRequest <TAsset> LoadAsync <TAsset>(string deviceList, ref ContentManifest.AssetEntry entry, AssetLoadedHandler <TAsset> handler = null)
        {
            StreamingAssetBundleWrapper streamingAssetBundleWrapper = new StreamingAssetBundleWrapper();
            AsyncStreamingAssetBundleRequest <TAsset> result        = new AsyncStreamingAssetBundleRequest <TAsset>(entry.Key, streamingAssetBundleWrapper);

            CoroutineRunner.StartPersistent(loadBundleFromStreamingAssets(entry, streamingAssetBundleWrapper, handler), this, "loadBundleFromStreamingAssets");
            return(result);
        }
Exemplo n.º 8
0
 public static void SetMouseButton(int index, bool?isPressed, Vector3?position)
 {
     if (isPressed.HasValue && isPressed != instance.fakeLeftMouseButtonDown)
     {
         CoroutineRunner.StartPersistent(fakeMouseButtonStateChange(), instance, "mouseButtonChange");
     }
     instance.fakeLeftMouseButtonDown = isPressed;
     instance.fakeMousePosition       = position;
 }
        public override AssetRequest <TAsset> LoadAsync <TAsset>(string deviceList, ref ContentManifest.AssetEntry entry, AssetLoadedHandler <TAsset> handler = null)
        {
            gcsAccessTokenService = Service.Get <IGcsAccessTokenService>();
            string bundlePath = UriUtil.Combine(baseUri, entry.Key);
            AssetBundleWwwWrapper          assetBundleWwwWrapper = new AssetBundleWwwWrapper(bundlePath, gcsAccessTokenService);
            AsyncBundleWwwRequest <TAsset> result = new AsyncBundleWwwRequest <TAsset>(entry.Key, assetBundleWwwWrapper);

            CoroutineRunner.StartPersistent(waitForBundleToLoad(assetBundleWwwWrapper, handler, entry.IsCacheOnly), this, "Local_waitForBundleToLoad");
            return(result);
        }
Exemplo n.º 10
0
        public ICoroutine StartAndAddPersistent(IEnumerator enumerator, object owner, string debugName)
        {
            ICoroutine coroutine = CoroutineRunner.StartPersistent(enumerator, owner, debugName);

            if (!coroutine.Disposed)
            {
                Add(coroutine);
            }
            return(coroutine);
        }
Exemplo n.º 11
0
        public override AssetRequest <TAsset> LoadAsync <TAsset>(string deviceList, ref ContentManifest.AssetEntry entry, AssetLoadedHandler <TAsset> handler = null)
        {
            string bundlePath = UriUtil.Combine(baseUri, entry.Key);
            AssetBundleWwwWrapper          assetBundleWwwWrapper = new AssetBundleWwwWrapper(bundlePath, gcsAccessTokenService);
            AsyncBundleWwwRequest <TAsset> result = new AsyncBundleWwwRequest <TAsset>(entry.Key, assetBundleWwwWrapper);
            uint result2 = 0u;

            if (entry.UserData != null && entry.UserData is ContentManifest.BundleEntry && !uint.TryParse(((ContentManifest.BundleEntry)entry.UserData).Crc, out result2))
            {
                result2 = 0u;
            }
            CoroutineRunner.StartPersistent(waitForBundleToLoad(assetBundleWwwWrapper, result2, handler), this, "waitForBundleToLoad");
            return(result);
        }
Exemplo n.º 12
0
        public static AssetRequest <TAsset> Load(ref ContentManifest.AssetEntry entry, AssetLoadedHandler <TAsset> handler = null)
        {
            ResourceRequest resourceRequest = Resources.LoadAsync(entry.Key, typeof(TAsset));

            if (resourceRequest.isDone && resourceRequest.asset == null)
            {
                throw new ArgumentException("Asset could not be loaded. Is the key correct? Key = " + entry.Key);
            }
            AsyncAssetResourceRequest <TAsset> asyncAssetResourceRequest = new AsyncAssetResourceRequest <TAsset>(entry.Key, resourceRequest);

            if (handler != null)
            {
                CoroutineRunner.StartPersistent(waitForLoadToFinish(entry.Key, asyncAssetResourceRequest, handler), typeof(AsycnResourceLoader <TAsset>), "waitForLoadToFinish");
            }
            return(asyncAssetResourceRequest);
        }
Exemplo n.º 13
0
        public AsyncAssetBundleRequest <TAsset> LoadAsync <TAsset>(string key, string assetPath, AssetLoadedHandler <TAsset> handler = null) where TAsset : class
        {
            AsyncAssetBundleRequest <TAsset> asyncAssetBundleRequest;

            if (activeRequests.TryGetValue(key, out var value))
            {
                asyncAssetBundleRequest = (AsyncAssetBundleRequest <TAsset>)value;
            }
            else
            {
                asyncAssetBundleRequest = new AsyncAssetBundleRequest <TAsset>(key, null);
                activeRequests[key]     = asyncAssetBundleRequest;
                CoroutineRunner.StartPersistent(waitForAssetToLoad(key, assetPath, asyncAssetBundleRequest, handler), this, "waitForAssetToLoad");
            }
            LastLoadFrame = Time.frameCount;
            return(asyncAssetBundleRequest);
        }
Exemplo n.º 14
0
        private AssetRequest <TAsset> loadAsyncEntry <TAsset>(ref ContentManifest.AssetEntry entry, AssetLoadedHandler <TAsset> handler = null) where TAsset : class
        {
            bool flag = entry.Extension.Equals("unity");

            if (!flag)
            {
                assetIndex.Reserve(entry.Key);
            }
            try
            {
                AssetRequest <TAsset> assetRequest = deviceManager.LoadAsync(entry.DeviceList, ref entry, handler);
                CoroutineRunner.StartPersistent(waitForLoadToFinish(assetRequest, flag), this, "waitForLoadToFinish");
                return(assetRequest);
            }
            catch (Exception)
            {
                assetIndex.Remove(entry.Key);
                throw;
            }
        }
Exemplo n.º 15
0
 private IEnumerator cacheBundles(IList <ContentManifest.BundleEntry> sortedBundles, bool ignorePriority)
 {
     for (int i = 0; i < sortedBundles.Count; i++)
     {
         completeRatio = (float)(i - numCurrentDownloads) / (float)sortedBundles.Count;
         uint maxConcurrentDownloads = (background ? config.MaxConcurrentBackgroundDownloads : config.MaxConcurrentForegroundDownloads);
         while (numCurrentDownloads >= maxConcurrentDownloads)
         {
             maxConcurrentDownloads = (background ? config.MaxConcurrentBackgroundDownloads : config.MaxConcurrentForegroundDownloads);
             yield return(null);
         }
         if (!caching)
         {
             break;
         }
         ContentManifest.BundleEntry bundle = sortedBundles[i];
         if (ignorePriority || bundle.Priority > 0)
         {
             CoroutineRunner.StartPersistent(downloadBundle(bundle), this, "BundlePrecacheManager.downloadBundle()");
             continue;
         }
         break;
     }
     if (sortedBundles.Count > 0)
     {
         while (numCurrentDownloads > 0)
         {
             completeRatio = (float)(sortedBundles.Count - numCurrentDownloads) / (float)sortedBundles.Count;
             yield return(null);
         }
         completeRatio = (float)(sortedBundles.Count - numCurrentDownloads) / (float)sortedBundles.Count;
     }
     if (caching && completeCallback != null)
     {
         completeCallback();
     }
     yield return(null);
 }
Exemplo n.º 16
0
 public BundlePrecacheManager(ContentManifest contentManifest)
 {
     SetManifest(contentManifest);
     CoroutineRunner.StartPersistent(loadConfig(), this, "BundlePrecacheManager.loadConfig()");
 }