public override void Reset()
 {
     state        = State.NextReq;
     cachedBundle = null;
     pendingData  = null;
     webReq       = null;
     bundleReq    = null;
     ao           = null;
 }
        public override TaskStatus Update()
        {
            switch (state)
            {
            case State.NextReq:
                if (queue.Count > 0)
                {
                    pendingData = queue.Dequeue();

                    cachedBundle = TaskAssetBundleCache.GetCachedBundle(pendingData.bundleName, pendingData.version);

                    if (cachedBundle == null)
                    {
                        webReq = UnityWebRequest.GetAssetBundle(pendingData.url, pendingData.version, pendingData.crc);
                        ao     = webReq.Send();
                        state  = State.LoadBundle;
                    }
                    else
                    {
                        state = State.LoadAsset;
                    }
                }
                else
                {
                    return(TaskStatus.Done);
                }
                break;

            case State.LoadBundle:
                // If loaded asset bundle
                if (ao.isDone)
                {
                    if (webReq.isHttpError || webReq.isNetworkError)
                    {
                        var data = pendingData;
                        progress += 1f;
                        Reset();
                        data.error = webReq.error;
                        if (data.onFail != null)
                        {
                            data.onFail(data);
                        }

                        if (data.abortIfFailed)
                        {
                            return(TaskStatus.Abort);
                        }
                    }
                    else
                    {
                        DownloadHandlerAssetBundle download = webReq.downloadHandler as DownloadHandlerAssetBundle;
                        cachedBundle = TaskAssetBundleCache.Cache(pendingData.bundleName, download.assetBundle, pendingData.version);
                        state        = State.LoadAsset;
                    }
                }
                break;

            case State.LoadAsset:
                if (bundleReq == null)
                {
                    bundleReq = cachedBundle.bundle.LoadAssetAsync(pendingData.assetName, pendingData.assetType);
                }

                if (bundleReq.isDone)
                {
                    var data = pendingData;
                    progress += 1f;
                    Reset();
                    data.loadedAsset = bundleReq.asset;
                    if (data.onSuccess != null)
                    {
                        data.onSuccess(data);
                    }
                }
                break;
            }

            return(TaskStatus.Pending);
        }
 public TaskAssetBundleLoad(TaskAssetBundleLoadData data)
 {
     queue = new Queue <TaskAssetBundleLoadData> ();
     queue.Enqueue(data);
     count = queue.Count;
 }