Example #1
0
    public IEnumerator DownAssetImpl()
    {
        var downloadsize = Addressables.GetDownloadSizeAsync((IEnumerable)_updateKeys);

        yield return(downloadsize);

        Debug.Log("start download size :" + downloadsize.Result);
        DownloadPercent.text = "start download size :" + downloadsize.Result;

        if (downloadsize.Result > 0)
        {
            _isDownloading  = true;
            _downloadHandle =
                Addressables.DownloadDependenciesAsync((IEnumerable)_updateKeys, Addressables.MergeMode.Union);
            yield return(_downloadHandle);

            //await download.Task;
            Debug.Log("download result type " + _downloadHandle.Result.GetType());
            foreach (var item in _downloadHandle.Result as
                     List <UnityEngine.ResourceManagement.ResourceProviders.IAssetBundleResource> )
            {
                var ab = item.GetAssetBundle();
                foreach (var name in ab.GetAllAssetNames())
                {
                    Debug.Log("asset name " + name);
                }
            }

            Addressables.Release(_downloadHandle);
        }

        _isDownloading = false;
        Addressables.Release(downloadsize);
    }
    //
    // Download
    //

    public bool DownloadAssets(List <string> keys, ProgressCallback pg, DownloadCompleteCallback dl)
    {
        // Download the assets in the list and all their dependencies.

        if (running)
        {
            return(false);
        }
        running = true;

        dlProgressCallback = pg;
        dlCompleteCallback = dl;
        progressBase       = -1f;

        downloadHandle            = Addressables.DownloadDependenciesAsync(keys.ToArray(), Addressables.MergeMode.Union);
        downloadHandle.Completed += DownloadComplete;

        // Start coroutine for progress. Don't use coroutines for anything that can throw
        // an exception (which includes downloading unchecked keys), because it can't be trapped.
        // See https://www.jacksondunstan.com/articles/3718

        StartCoroutine(DownloadProgress());

        return(true);
    }
    public void LoadScene(string tag)
    {
        Debug.Log("Addressables Procedure Started for Loading Scene: " + tag + "@" + Time.time);
        Addressables.ClearDependencyCacheAsync(tag);
        Addressables.InitializeAsync().Completed += delegate {
            Debug.Log("Addressables.InitializeAsync.Completed:@" + Time.time);
            Addressables.GetDownloadSizeAsync(tag).Completed += delegate(AsyncOperationHandle <long> obj)
            {
                Debug.Log("Addressables.GetDownloadSizeAsync.Completed:@" + Time.time);
                float downloadSizeInMB = (float)obj.Result / 1024 / 1024;
                Debug.Log("GetDownloadSizeAsync: " + obj.Result + " bytes, which is " + downloadSizeInMB + " MB");

                if (size)
                {
                    size.text += System.Environment.NewLine + "Size of download: " + downloadSizeInMB.ToString();
                }

                Addressables.DownloadDependenciesAsync(tag).Completed += delegate(AsyncOperationHandle opDownloadDependencies)
                {
                    Debug.Log("Addressables.DownloadDependenciesAsync.Completed:" + opDownloadDependencies.Status + "@" + Time.time);
                    Addressables.LoadSceneAsync(tag).Completed += delegate(AsyncOperationHandle <SceneInstance> opLoadScene) {
                        Debug.Log("LoadSceneAsync.Completed: " + opLoadScene.Status + "@" + Time.time);
                        if (opLoadScene.Status == AsyncOperationStatus.Succeeded)
                        {
                        }
                    };
                };
            };
        };
    }
Example #4
0
        private IEnumerator DownloadFiles(List <string> catalogs)
        {
            foreach (string s in catalogs)
            {
                var handle = Addressables.GetDownloadSizeAsync(catalogs);
                while (!handle.IsDone)
                {
                    yield return(new WaitForFixedUpdate());
                }

                float catalogSize = handle.Result;
                float prevPercent = 0;
                var   newhandle   = Addressables.DownloadDependenciesAsync(catalogs);
                while (!newhandle.IsDone)
                {
                    prevPercent              = newhandle.PercentComplete;
                    m_currentDownloadedSize += catalogSize * (newhandle.PercentComplete - prevPercent);

                    m_updateCheckerView.UpdateDownloadInfos(
                        1 / (m_downloadSize / m_currentDownloadedSize),
                        m_currentDownloadedSize,
                        m_downloadSize
                        );

                    yield return(new WaitForFixedUpdate());
                }
            }

            OnDownloadComplete();
        }
Example #5
0
        IEnumerator UpdateAssets(object[] keys)
        {
            var sizeHandle = Addressables.GetDownloadSizeAsync(keys);

            yield return(sizeHandle);

/*            BootScreen.Instance.SetLabel("正在更新资源...");
 *          BootScreen.Instance.SetProgress(0);*/

            long totalDownloadSize = sizeHandle.Result;

            if (totalDownloadSize > 0)
            {
                var downloadHandle = Addressables.DownloadDependenciesAsync(keys, Addressables.MergeMode.Union);

                while (!downloadHandle.IsDone)
                {
                    float percent = downloadHandle.PercentComplete;

/*                    BootScreen.Instance.SetProgress(percent);
 *                  BootScreen.Instance.SetLabel(($"正在更新资源({(int)(totalDownloadSize * percent)}/{totalDownloadSize})..."));*/
                }
            }
            yield return(null);
        }
        private IEnumerator DownloadInner(AddressableDownloadLabelData downloadLabelData)
        {
            Debug.Log($"Addressable start to download {downloadLabelData.Label}");
            _currentLabel = downloadLabelData;

            var locations = Addressables.LoadResourceLocationsAsync(downloadLabelData.Label);

            yield return(locations);

            var getDownloadSize = Addressables.GetDownloadSizeAsync(locations.Result);

            yield return(getDownloadSize);

            _fullSize = (int)((float)getDownloadSize.Result / Mb);
            Debug.Log($"Addressable {downloadLabelData.Label} download size: {_fullSize}");

            if (_fullSize > 0)
            {
                var downloadLocations = Addressables.DownloadDependenciesAsync(locations.Result);
                while (!downloadLocations.IsDone)
                {
                    _progress       = downloadLocations.PercentComplete;
                    _downloadedSize = (int)(_progress * _fullSize * Mb);
                    downloadLabelData.SetProgress(_downloadedSize, _fullSize, _progress);
                    //Debug.Log($"Addressable {label} downloading {_progress * 100}% size {_downloadedSize}");
                    yield return(new WaitForSeconds(0.01f));
                }
                downloadLabelData.SetDone();
            }
            else
            {
                Debug.Log($"Addressable already to downloaded {downloadLabelData.Label}");
                downloadLabelData.SetDone();
            }
        }
    public IEnumerator DownAssetImpl()
    {
        var downloadsize = Addressables.GetDownloadSizeAsync(_updateKeys);

        yield return(downloadsize);

        Debug.Log("start download size :" + downloadsize.Result);
        if (downloadsize.Result > 0)
        {
            var download = Addressables.DownloadDependenciesAsync(_updateKeys, Addressables.MergeMode.Intersection);
            yield return(download);

            //await download.Task;
            Debug.Log("download result type " + download.Result.GetType());
            foreach (var item in download.Result as List <UnityEngine.ResourceManagement.ResourceProviders.IAssetBundleResource> )
            {
                var ab = item.GetAssetBundle();
                Debug.Log("ab name " + ab.name);
                foreach (var name in ab.GetAllAssetNames())
                {
                    Debug.Log("asset name " + name);
                }
            }
            Addressables.Release(download);
        }
        Addressables.Release(downloadsize);
    }
 void Start()
 {
     // ADDRESSABLES UPDATES
     loadingText.text = string.Format("Loading: {0}%", 0);
     preloadOp        = Addressables.DownloadDependenciesAsync("preload");
     LoadHazards();
 }
Example #9
0
        /// <summary>
        /// 下载指定资源
        /// </summary>
        public static void DownloadAssets(IEnumerable keys)
        {
            var handle = Addressables.DownloadDependenciesAsync(keys, Addressables.MergeMode.Union);

            handle.WaitForCompletion();

            if (handle.Status == AsyncOperationStatus.Succeeded)
            {
                Debug.Log("Download result type: " + handle.Result.GetType());

                foreach (var item in handle.Result as List <IAssetBundleResource> )
                {
                    var ab = item.GetAssetBundle();
                    Debug.Log("AssetBundle name: " + ab.name);

                    foreach (var assetName in ab.GetAllAssetNames())
                    {
                        Debug.Log("Asset name: " + assetName);
                    }
                }
            }
            else
            {
                Debug.Log("Download assets failed");
            }

            Addressables.Release(handle);
        }
Example #10
0
 public static async Task DownloadAllAssets(List <AssetReference> assetList)
 {
     foreach (var asset in assetList)
     {
         await Addressables.DownloadDependenciesAsync(asset).Task;
     }
 }
    private IEnumerator DownloadAsync()
    {
        long downloadedSize = 0;

        for (int i = 0; i < updateKeys.Count; i++)
        {
            var downloadSizeHandle = Addressables.GetDownloadSizeAsync(updateKeys[i]);
            yield return(downloadSizeHandle);

            long size = downloadSizeHandle.Result;
            Addressables.Release(downloadSizeHandle);
            if (size <= 0)
            {
                continue;
            }

            var downloadHandle = Addressables.DownloadDependenciesAsync(updateKeys[i]);
            while (downloadHandle.PercentComplete < 1 && !downloadHandle.IsDone)
            {
                OnDownload?.Invoke(downloadedSize + (long)(downloadHandle.PercentComplete * size), downloadSize);
#if UNITY_EDITOR
                Debug.Log(string.Format("Download Size: {0}/{1}", downloadedSize + (long)(downloadHandle.PercentComplete * size), downloadSize));
#endif
                yield return(null);
            }
            downloadedSize += size;
            Addressables.Release(downloadHandle);
            if (downloadedSize >= downloadSize)
            {
                break;
            }
        }
    }
        public IEnumerator StartDownLoadBundle()
        {
            var   size = Addressables.DownloadDependenciesAsync("default");
            float time = 0;

            while (!size.IsDone)
            {
                time += Time.deltaTime;
                float progress = float.Parse((size.PercentComplete * 100).ToString("f2"));
                Progress.text = $"正在更新资源... {progress}%";

                if (time > 1)
                {
                    float currentsize = TotalSize * size.PercentComplete;
                    speed             = currentsize - lastSize;
                    DownLoadSize.text = $" {FileHelper.ConventToSize(currentsize)}  速度: {FileHelper.ConventToSize(speed)}";
                    lastSize          = currentsize;
                    time = 0;
                }
                yield return(null);
            }

            DownLoadSize.text = "下载完成!";

            InitScript.StartAsync();
            gameObject.SetActive(false);
        }
        /// <summary>
        /// <para>指定されたアドレスもしくはラベルに紐づくアセットバンドルを事前にダウンロードします</para>
        /// <para>autoReleaseHandle を true にすると、ダウンロードしたアセットバンドルをキャッシュに保存してメモリからは解放します</para>
        /// <para>autoReleaseHandle を false にすると、ダウンロードしたアセットバンドルはメモリに残り続けます</para>
        /// <para>ダウンロードしたアセットバンドルに含まれるアセットをすぐに使う場合は false を、</para>
        /// <para>すぐに使わない場合は true を指定すると効率的です</para>
        /// </summary>
        public AddressablesControllerHandle DownloadDependenciesAsync
        (
            object addressOrLabel,
            bool autoReleaseHandle
        )
        {
            var source = new TaskCompletionSource <AddressablesControllerResultCode>();

            if (!m_isInitialized)
            {
                source.TrySetResult(AddressablesControllerResultCode.FAILURE_NOT_INITIALIZED);
                return(new AddressablesControllerHandle(source.Task));
            }

            var isFailure     = false;
            var isNotExistKey = false;

            void OnComplete(AsyncOperationHandle handle)
            {
                m_exceptionHandler -= ExceptionHandler;

                if (isFailure)
                {
                    var resultCode = isNotExistKey
                                                        ? AddressablesControllerResultCode.FAILURE_KEY_NOT_EXIST
                                                        : AddressablesControllerResultCode.FAILURE_CANNOT_CONNECTION
                    ;

                    source.TrySetResult(resultCode);
                    return;
                }

                if (handle.Status != AsyncOperationStatus.Succeeded)
                {
                    source.TrySetResult(AddressablesControllerResultCode.FAILURE_UNKNOWN);
                    return;
                }

                source.TrySetResult(AddressablesControllerResultCode.SUCCESS);
            }

            void ExceptionHandler(Exception exception)
            {
                isFailure     = true;
                isNotExistKey = exception.Message.Contains(nameof(InvalidKeyException));

                m_exceptionHandler -= ExceptionHandler;
            }

            m_exceptionHandler += ExceptionHandler;

            var result = Addressables.DownloadDependenciesAsync(addressOrLabel, autoReleaseHandle);

            result.Completed += handle => OnComplete(handle);

            var controllerHandle = new AddressablesControllerHandle(result, source.Task);

            return(controllerHandle);
        }
Example #14
0
        public static IProgressResult <float> DownloadNewAssets()
        {
            ProgressResult <float> progressResult = new ProgressResult <float>();
            var operation = Addressables.DownloadDependenciesAsync(DYNAMIC_TAG);

            Executors.RunOnCoroutineNoReturn(Download(progressResult, operation));
            return(progressResult);
        }
Example #15
0
        async UniTask IAssetDownloader.Download(IList <object> keys)
        {
            var operation = Addressables.DownloadDependenciesAsync(keys);

            if (!operation.IsDone)
            {
                await operation.Task;
            }
        }
 public void DownloadDependencies(List <IResourceLocation> Content, AddressableCatalogueManager.LoadCounter loadCounter = null)
 {
     foreach (var Assets in Content)
     {
         var newbar = Instantiate(DownloadBar, gameObject.transform);
         var Handle = Addressables.DownloadDependenciesAsync(Assets.InternalId);
         newbar.Setup(Handle, Assets.InternalId, loadCounter);
     }
 }
Example #17
0
#pragma warning disable 1998
        public override async Task <IProgressResult <DownloadProgress> > DownloadAssets(string key)
#pragma warning restore 1998
        {
            ProgressResult <DownloadProgress> progressResult = new ProgressResult <DownloadProgress>();
            var operation = Addressables.DownloadDependenciesAsync(key);

            Executors.RunOnCoroutineNoReturn(Download(progressResult, operation));
            return(progressResult);
        }
 // Update is called once per frame
 void Update()
 {
     if (Input.touchCount != 0 || Input.GetMouseButtonUp(0))
     {
         Debug.Log("touched");
         var handle = Addressables.DownloadDependenciesAsync("Assets/TestBackgroundImage.prefab", true);
         handle.Completed += _ => StartCoroutine(Login());
     }
 }
Example #19
0
        /// <summary>
        /// 以资源的“地址”或者标签为参数
        /// 进行依赖项资源的加载
        /// 一般情况下这些资源都是AssetBundle
        /// </summary>
        /// <param name="addressNames"></param>
        /// <param name="percent"></param>
        public static AsyncOperationHandle DownloadDependenciesAsync(string addressNames, Action <float> percent = null)
        {
            var download = Addressables.DownloadDependenciesAsync(addressNames);

            if (percent != null)
            {
                percent(download.PercentComplete);
            }
            return(download);
        }
Example #20
0
    public void Init()
    {
        _downloadedCount = 0;
        for (int i = 0; i < atlasNameList.Count; i++)
        {
            AsyncOperationHandle handle = Addressables.DownloadDependenciesAsync(atlasNameList[i]);

            handle.Completed += DownloadCompleted;
        }
    }
Example #21
0
    //</Invoked from buttons>

    private IEnumerator DownloadProgressTracker(AssetReference asset)
    {
        downloads[asset] = 0f;
        var op = Addressables.DownloadDependenciesAsync(asset);

        while (!op.IsDone)
        {
            downloads[asset] = op.PercentComplete;
            yield return(null);
        }
    }
Example #22
0
    // Start is called before the first frame update
    void Start()
    {
#if UMA_ADDRESSABLES
        op            = Addressables.DownloadDependenciesAsync(Labels, Addressables.MergeMode.Union, false);
        op.Completed += Op_Completed;
        //await op.Task;
#else
        Debug.Log("Addressables is not defined.");
        Text t = LoadingSlider.gameObject.GetComponentInChildren <Text>();
        t.text = "Sample requires addressables to run.";
#endif
    }
Example #23
0
    // Start download the file and display the progress
    private IEnumerator DownloadFile(string key, Text displayText, Action <AsyncOperationHandle> handle)
    {
        var handler = Addressables.DownloadDependenciesAsync(key);

        while (!handler.IsDone)
        {
            displayText.text = "Downloading: " + (handler.GetDownloadStatus().Percent * 100).ToString("00") + "%";

            yield return(null);
        }

        handle(handler);
    }
Example #24
0
    public void Init()
    {
        _downloadedCount = 0;
        // Clear();
        // MessageDispatcher.AddListener(GameEvent.DOWNLOAD_ASSETBUNDLES, DownloadAssetBundles, true);
        //MessageDispatcher.AddListener(GameEvent.DOWNLOAD_ASSETBUNDLE_SUCCESS, DownloadAssetBundleSuccess);
        for (int i = 0; i < bundleNameList.Count; i++)
        {
            AsyncOperationHandle handle = Addressables.DownloadDependenciesAsync(bundleNameList[i]);

            handle.Completed += DownloadCompleted;
        }
    }
Example #25
0
        public async void StartDownLoadBundle()
        {
            var size = Addressables.DownloadDependenciesAsync("default");

            while (!size.IsDone)
            {
                float currentsize = TotalSize * size.PercentComplete;
                speed             = currentsize - lastSize;
                DownLoadSize.text = $"({ConventToSize(currentsize)}  速度:{ConventToSize(speed)})";
                lastSize          = currentsize;
                await Task.Delay(100);
            }
            DownLoadSize.text = "下载完成!";
        }
Example #26
0
        private IEnumerator Update(List <object> keyList)
        {
            AsyncOperationHandle <long> downloadSizeHandle = Addressables.GetDownloadSizeAsync(keyList);

            yield return(downloadSizeHandle);

            if (downloadSizeHandle.Status == AsyncOperationStatus.Succeeded && downloadSizeHandle.Result > 0)
            {
                AsyncOperationHandle downloadDependenciesHandle = Addressables.DownloadDependenciesAsync(keyList, Addressables.MergeMode.Union);
                yield return(downloadDependenciesHandle);

                Addressables.Release(downloadDependenciesHandle);
            }
            Addressables.Release(downloadSizeHandle);
        }
        private IEnumerator PreloadAssets() {
            #region doc_Download
            string key = "assetKey";

            // Check the download size
            AsyncOperationHandle<long> getDownloadSize = Addressables.GetDownloadSizeAsync(key);
            yield return getDownloadSize;

            //If the download size is greater than 0, download all the dependencies.
            if (getDownloadSize.Result > 0) {
                AsyncOperationHandle downloadDependencies = Addressables.DownloadDependenciesAsync(key);
                yield return downloadDependencies;
            }
            #endregion
        }
Example #28
0
    IEnumerator DoDownload()
    {
        var dl = Addressables.DownloadDependenciesAsync(scene);

        dl.Completed += (AsyncOperationHandle) =>
        {
            DownloadComplete();
        };

        while (dl.PercentComplete < 1 && !dl.IsDone)
        {
            Debug.Log("Downloading Asset: " + dl.PercentComplete.ToString());
            yield return(null);
        }
    }
    public void Download(string label)
    {
        var index = GetLabelIndex(label);

        if (AsyncOpExists(listOps[index]))
        {
            Debug.Log("Download is allready in progress");
            return;
        }

        listOps[index]            = Addressables.DownloadDependenciesAsync(listLabels[index]);
        listOps[index].Completed += (x) => {
            OnDownloadComplete?.Invoke(GetLabel(index));
        };

        StartCoroutine(CRTDownload(index));
    }
    public static IEnumerator DownloadDependenciesFor(string key)
    {
        Debug.Log($"Downloading dependencies for {key}");

        var handle = Addressables.DownloadDependenciesAsync(key);

        yield return(handle);

        if (handle.Status == AsyncOperationStatus.Succeeded)
        {
            Debug.Log($"Successfully downloaded dependencies for {key}");
        }
        else
        {
            Debug.LogError($"Failed to download dependencies for {key}: {handle.OperationException}");
        }
    }