Exemplo n.º 1
0
    IEnumerator Start()
    {
        //show log message
        BundleManager.LogMessages = true;

        //show some ongui elements for debugging
        BundleManager.ShowDebugGUI = true;

        //initialize bundle system & load local bundles
        yield return(BundleManager.Initialize());

        //get download size from latest bundle manifest
        var manifestReq = BundleManager.GetManifest();

        yield return(manifestReq);

        if (!manifestReq.Succeeded)
        {
            //handle error
            Debug.LogError(manifestReq.ErrorCode);
        }

        Debug.Log($"Need to download { BundleManager.GetDownloadSize(manifestReq.Result) * 0.000001f } mb");

        //start downloading
        var downloadReq = BundleManager.DownloadAssetBundles(manifestReq.Result);

        while (!downloadReq.IsDone)
        {
            if (downloadReq.CurrentCount >= 0)
            {
                Debug.Log($"Current File {downloadReq.CurrentCount}/{downloadReq.TotalCount}, " +
                          $"Progress : {downloadReq.Progress * 100}%, " +
                          $"FromCache {downloadReq.CurrentlyLoadingFromCache}");
            }

            //if user requests cancel
            if (m_DownloadCancelRequested)
            {
                downloadReq.Cancel();
            }

            yield return(null);
        }

        if (!downloadReq.Succeeded)
        {
            //handle error
            Debug.LogError(downloadReq.ErrorCode);
        }
        //start to game
    }
    IEnumerator CoDownloadAssetBundles()
    {
        var manifestReq = BundleManager.GetManifest();

        yield return(manifestReq);

        if (!manifestReq.Succeeded)
        {
            Debug.LogError(manifestReq.ErrorCode);
            yield break;
        }
        var downloadReq = BundleManager.DownloadAssetBundles(manifestReq.Result);

        yield return(downloadReq);

        if (!downloadReq.Succeeded)
        {
            Debug.LogError(downloadReq.ErrorCode);
            yield break;
        }
    }