Exemplo n.º 1
0
        LoadReturnArgs LoadCommonAsset(ref CommonLoadArgs args, AssetBundleTaskType type = AssetBundleTaskType.Sync | AssetBundleTaskType.LoadAsset)
        {
            if (_assetBundleFeature != null)
            {
                AssetBundleContext context = _assetBundleFeature.StartRead();

                AssetBundleInfo info;
                GameAssetBundle gameAssetBundle;
                if (CanLoad(ref context, args.AssetPath, out info, out gameAssetBundle))
                {
                    AssetBundleTask task = new AssetBundleTask();
                    //
                    task.AssetInfo    = info;
                    task.TaskLoadType = type;
                    task.TaskId       = ++_taskid;
                    task.TaskResType  = TaskResType.Common;
                    task.Priority     = args.Priority;
                    task.CreateTime   = Time.realtimeSinceStartup;

                    //
                    Debug.LogFormat("Task ---- {0} Created", task);

                    context.AddTask(ref task);
                    _assetBundleFeature.EndRead(ref context);

                    LoadReturnArgs returnArgs = new LoadReturnArgs(this._assetBundleFeature, task.TaskId);
                    return(returnArgs);
                }
            }

            return(default(LoadReturnArgs));
        }
        protected virtual void PreLoadSubTask(ref AssetBundleContext context, ref AssetBundleTask task, ref bool retcode)
        {
            if (task.SubTasks != null && task.SubTasks.Count > 0)
            {
                for (int i = 0; i < task.SubTasks.Count; i++)
                {
                    var             subtask = task.SubTasks[i];
                    GameAssetBundle gameAssetBundle;
                    if (context.Cache.GetAssetBundle(subtask.AssetBundleName, out gameAssetBundle))
                    {
                        PreLoad(ref context, ref subtask, ref gameAssetBundle, ref retcode);

                        //Update
                        context.Cache.UpdateAssetBundle(subtask.AssetBundleName, ref gameAssetBundle);

                        PreLoadSubTask(ref context, ref subtask, ref retcode);
                    }
                    else
                    {
                        Debug.LogErrorFormat("not found assetbundle :{0}", subtask.AssetPath);
                        AddException(ref context, subtask.AssetPath);
                    }
                }
            }
        }
Exemplo n.º 3
0
        LoadReturnArgs LoadAssetScene(ref SceneLoadArgs args, AssetBundleTaskType type = AssetBundleTaskType.LoadAsset | AssetBundleTaskType.Sync)
        {
            if (_assetBundleFeature != null)
            {
                AssetBundleContext context = _assetBundleFeature.StartRead();

                AssetBundleInfo info;
                GameAssetBundle gameAssetBundle;
                if (CanLoad(ref context, args.AssetPath, out info, out gameAssetBundle))
                {
                    AssetBundleTask task = new AssetBundleTask();
                    task.AssetInfo     = info;
                    task.TaskLoadType  = type;
                    task.TaskId        = ++_taskid;
                    task.TaskResType   = TaskResType.Scene;
                    task.Priority      = args.Priority;
                    task.CreateTime    = Time.realtimeSinceStartup;
                    task.LoadSceneMode = args.SceneMode;

                    context.AddTask(ref task);
                    _assetBundleFeature.EndRead(ref context);

                    LoadReturnArgs returnArgs = new LoadReturnArgs(this._assetBundleFeature, task.TaskId);
                    return(returnArgs);
                }
            }
            return(default(LoadReturnArgs));
        }
        public void AddCopyTask(ref AssetBundleTask task)
        {
            if (Tasks == null)
            {
                Tasks = ListPool <AssetBundleTask> .Get();
            }

            Tasks.Add(task);
        }
Exemplo n.º 5
0
        protected override void LoadMainAsset(ref AssetBundleContext context, ref AssetBundleTask task, ref GameAssetBundle gameAssetBundle, ref bool retcode)
        {
            if (task.IsAsync())
            {
                if (gameAssetBundle.SceneRequest == null)//准备加载场景
                {
                    gameAssetBundle.SceneRequest = SceneManager.LoadSceneAsync(task.AssetPath, task.LoadSceneMode);
                    if (gameAssetBundle.SceneRequest != null)
                    {
                        gameAssetBundle.SceneRequest.allowSceneActivation = false;
                    }

                    if (task.Result.ProgresCallback != null)
                    {
                        ProgressArgs progressArgs = new ProgressArgs(0, 0, task.AssetPath, true);
                        task.Result.ProgresCallback(ref progressArgs);
                    }
                }
                else if (gameAssetBundle.SceneRequest != null)//检查加载场景的状态
                {
                    if (Mathf.Abs(gameAssetBundle.SceneRequest.progress - 0.9f) < 0.001f)
                    {
                        gameAssetBundle.AssetStatus |= AssetBundleStatus.InMemory;
                        //暂时不释放
                        AssetBundleFunction.AddRef(ref context, ref gameAssetBundle, task.AssetPath);

                        task.Result.scene = gameAssetBundle.SceneRequest;

                        gameAssetBundle.SceneRequest = null;

                        if (task.Result.ProgresCallback != null)
                        {
                            ProgressArgs progressArgs = new ProgressArgs(1, 0, task.AssetPath, true);
                            task.Result.ProgresCallback(ref progressArgs);
                        }
                        task.FinishTime = Time.realtimeSinceStartup;
                        retcode         = true;
                    }
                }
            }
            else
            {
                SceneManager.LoadScene(task.AssetPath, task.LoadSceneMode);
                gameAssetBundle.AssetStatus |= AssetBundleStatus.InMemory;
                AssetBundleFunction.AddRef(ref context, ref gameAssetBundle, task.AssetPath);

                if (task.Result.ProgresCallback != null)
                {
                    ProgressArgs progressArgs = new ProgressArgs(1, 0, task.AssetPath, true);
                    task.Result.ProgresCallback(ref progressArgs);
                }
                task.FinishTime = Time.realtimeSinceStartup;
                retcode         = true;
            }
        }
Exemplo n.º 6
0
        protected override void UnLoad(ref AssetBundleTask task, ref GameAssetBundle gameAssetBundle, ref bool retcode)
        {
            Scene scene = SceneManager.GetSceneByPath(task.AssetPath);

            if (scene.IsValid() && scene.isLoaded)
            {
                if (task.IsAsync())
                {
                    if (gameAssetBundle.UnloadSceneRequest == null)
                    {
                        gameAssetBundle.UnloadSceneRequest = SceneManager.UnloadSceneAsync(task.AssetPath);
                    }
                    else if (gameAssetBundle.UnloadSceneRequest != null)
                    {
                        if (gameAssetBundle.UnloadSceneRequest.progress.SimpleEqual(0.9f))
                        {
                            if (task.Result.ProgresCallback != null)
                            {
                                ProgressArgs progressArgs = new ProgressArgs(1, 0, task.AssetPath, true);
                                task.Result.ProgresCallback(ref progressArgs);
                            }
                            task.FinishTime = Time.realtimeSinceStartup;
                            retcode         = true;
                        }
                    }
                }
                else
                {
#pragma warning disable
                    if (SceneManager.UnloadScene(task.AssetPath))
                    {
                        Debug.LogFormat("UnLoadScene  :{0} Success", task.AssetPath);
                    }
#pragma warning restore
                    if (task.Result.ProgresCallback != null)
                    {
                        ProgressArgs progressArgs = new ProgressArgs(1, 0, task.AssetPath, true);
                        task.Result.ProgresCallback(ref progressArgs);
                    }
                    task.FinishTime = Time.realtimeSinceStartup;
                    retcode         = true;
                }
            }
            else
            {
                if (task.Result.ProgresCallback != null)
                {
                    ProgressArgs progressArgs = new ProgressArgs(1, 0, task.AssetPath, true);
                    task.Result.ProgresCallback(ref progressArgs);
                }
                task.FinishTime = Time.realtimeSinceStartup;
                retcode         = true;
            }
        }
        void DisposeTask(ref AssetBundleTask task)
        {
            if (task.SubTasks != null)
            {
                for (int i = 0; i < task.SubTasks.Count; i++)
                {
                    var subtask = task.SubTasks[i];
                    DisposeTask(ref subtask);
                }
            }

            task.Dispose();
        }
        bool DispatcherTask(ref AssetBundleContext context, ref AssetBundleTask task)
        {
            GameAssetBundle gameAssetBundle;

            if (task.IsDone(ref context, out gameAssetBundle))
            {
                //set or not ?
                //task.FinishTime = Time.realtimeSinceStartup;
                task.Result.Result      = !gameAssetBundle.IsException();
                task.Result.LoadObject  = gameAssetBundle.LoadAsset(task.AssetPath);
                task.Result.RuntimeInfo = task.AssetInfo;
                //因为这里只改边list 中的task存储内容,不涉及context 非reference的修改,所以没有关系
                task.Result.UpdateReferenceAction = AddRefrence;

                //notify
                if (task.Result.ResultCallback != null)
                {
                    task.Result.ResultCallback(ref task.Result);
                }
                else if (task.IsPreLoad())
                {
                    if (task.PinTime < 0)
                    {
                        AssetBundleFunction.AddRef(ref context, ref gameAssetBundle, task.AssetPath);
#if UNITY_EDITOR
                        context.Cache.UpdateAssetBundle(task.AssetBundleName, ref gameAssetBundle);
#endif
                    }
                }
                else if (task.TaskResType == TaskResType.GameObject)
                {
                    task.Result.Instantiate();
                }
                else if (task.TaskResType == TaskResType.Scene)
                {
                    if (!task.Result.Hide)
                    {
                        task.Result.LoadScene();
                    }
                }


                Debug.LogFormat("DisposeTask : {0} dispose", task);
                DisposeTask(ref task);
                return(true);
            }

            return(false);
        }
        protected virtual void LoadDependency(ref AssetBundleContext context, ref AssetBundleTask task, ref bool retcode)
        {
            var depinfo = task.AssetInfo.DependNames;

            if (depinfo != null && depinfo.Length > 0 && task.SubTasks == null)
            {
                for (int i = 0; i < depinfo.Length; i++)
                {
                    var             depname = depinfo[i];
                    AssetBundleInfo info;
                    GameAssetBundle gameAssetBundle;
                    if (AssetBundleLoadManager.mIns.CanLoad(ref context, depname, out info, out gameAssetBundle))
                    {
                        if (!gameAssetBundle.AssetStatus.HasEnum(AssetBundleStatus.InMemory))
                        {
                            AssetBundleTask subtask = new AssetBundleTask();
                            subtask.AssetInfo    = info;
                            subtask.Priority     = task.Priority;
                            subtask.TaskResType  = task.TaskResType;
                            subtask.TaskLoadType = task.TaskLoadType;
                            subtask.TaskId       = task.TaskId;
                            subtask.CreateTime   = Time.realtimeSinceStartup;

                            task.AddSubTask(ref subtask);
                            if (AssetBundleConfig.DebugMode.HasEnum(DebugMode.Detail))
                            {
                                Debug.LogFormat("subTask --- {0}  Created ", subtask);
                            }
                            LoadDependency(ref context, ref subtask, ref retcode);
                        }
                    }
                    else
                    {
                        Debug.LogErrorFormat("cant load Dependency :{0}", depname);
#pragma warning disable
                        if (AssetBundleConfig.SafeMode)
                        {
                            AddException(ref context, depname);
                        }
#pragma warning restore
                    }
                }

                retcode = true;
            }
        }
        void UnLoad(ref AssetBundleContext context, ref AssetBundleTask task)
        {
            if (task.AssetInfo.AssetResType == AssetBundleResType.Scene)
            {
                if (task.IsAsync())
                {
                    GameAssetBundle gameAssetBundle;
                    if (context.Cache.GetAssetBundle(task.AssetBundleName, out gameAssetBundle))
                    {
                        if (gameAssetBundle.UnloadSceneRequest == null)
                        {
                            gameAssetBundle.UnloadSceneRequest = SceneManager.UnloadSceneAsync(task.AssetPath);
                        }
                        else if (gameAssetBundle.UnloadSceneRequest.isDone)
                        {
                            if (Mathf.Abs(gameAssetBundle.UnloadSceneRequest.progress - 0.9f) < 0.001f)
                            {
                                if (task.Result.ProgresCallback != null)
                                {
                                    ProgressArgs progressArgs = new ProgressArgs(1, 0, task.AssetPath, true);
                                    task.Result.ProgresCallback(ref progressArgs);
                                }
                                task.FinishTime = Time.realtimeSinceStartup;
                            }
                        }
                    }
                }
                else
                {
#pragma warning disable
                    if (SceneManager.UnloadScene(task.AssetPath))
                    {
                        Debug.LogFormat("UnLoadScene  :{0} Success", task.AssetPath);
                    }
#pragma warning restore
                    if (task.Result.ProgresCallback != null)
                    {
                        ProgressArgs progressArgs = new ProgressArgs(1, 0, task.AssetPath, true);
                        task.Result.ProgresCallback(ref progressArgs);
                    }
                    task.FinishTime = Time.realtimeSinceStartup;
                }
            }
        }
 protected virtual void AfterLoadAssetBundle(ref AssetBundleContext context, ref AssetBundleTask task, ref GameAssetBundle gameAssetBundle, ref bool retcode, ref bool mainloadrequest)
 {
     if (gameAssetBundle.AssetBundle == null)
     {
         gameAssetBundle.AssetStatus |= AssetBundleStatus.NotInMemory;
     }
     else if (!mainloadrequest)//作为依赖
     {
         if (AssetBundleConfig.DebugMode.HasEnum(DebugMode.Detail))
         {
             Debug.LogFormat("dependency :{0} is Done", task);
         }
         gameAssetBundle.AssetStatus |= AssetBundleStatus.InMemory;
     }
     else
     {
         LoadMainAsset(ref context, ref task, ref gameAssetBundle, ref retcode);
     }
 }
Exemplo n.º 12
0
        bool InTask(ref GameAssetBundle gameAssetBundle, ref AssetBundleTask task)
        {
            if (task.AssetBundleName == gameAssetBundle.AssetBundleInfo.AssetBundleName)
            {
                return(true);
            }

            if (task.AssetInfo.DepAssetBundleNames != null)
            {
                for (int i = 0; i < task.AssetInfo.DepAssetBundleNames.Length; i++)
                {
                    var depname = task.AssetInfo.DepAssetBundleNames[i];
                    if (gameAssetBundle.AssetBundleInfo.AssetBundleName == depname)
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
Exemplo n.º 13
0
 public void AddTask(ref AssetBundleTask task)
 {
     if (Tasks != null)
     {
         if (task.Priority < 0)
         {
             Tasks.Add(task);
         }
         else
         {
             for (int i = 0; i < Tasks.Count; i++)
             {
                 var intask = Tasks[i];
                 if (intask.Priority < task.Priority)
                 {
                     Tasks.Insert(i, task);
                     break;
                 }
             }
         }
     }
 }
Exemplo n.º 14
0
        internal static bool InDowloading(ref AssetBundleContext context, ref AssetBundleTask task)
        {
            AssetDownloadInfo downloadInfo = new AssetDownloadInfo();

            downloadInfo.AssetBundleName = task.AssetBundleName;
            if (context.DownLoadQueue.Contains(downloadInfo))
            {
                return(true);
            }

            if (task.SubTasks != null)
            {
                for (int i = 0; i < task.SubTasks.Count; i++)
                {
                    var subtask = task.SubTasks[i];
                    if (InDowloading(ref context, ref subtask))
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
 protected virtual void UnLoad(ref AssetBundleTask task, ref GameAssetBundle gameAssetBundle, ref bool retcode)
 {
 }
Exemplo n.º 16
0
 public void RemoveTask(ref AssetBundleTask task)
 {
     RemoveTask(task.TaskId);
 }
Exemplo n.º 17
0
 protected override bool IsEnableLoadAssetBunlde(ref AssetBundleContext context, ref AssetBundleTask task, ref GameAssetBundle gameAssetBundle)
 {
     return(task.FreeSize || _size < Mathf.Max(1, AssetBundleConfig.TaskLoadAssetLimit));
 }
Exemplo n.º 18
0
 protected override void AfterLoadAssetBundle(ref AssetBundleContext context, ref AssetBundleTask task, ref GameAssetBundle gameAssetBundle, ref bool retcode, ref bool mainloadrequest)
 {
     _size += gameAssetBundle.AssetBundleInfo.AssetSize;
     base.AfterLoadAssetBundle(ref context, ref task, ref gameAssetBundle, ref retcode, ref mainloadrequest);
 }
        void Load(ref AssetBundleContext context, ref AssetBundleTask task)
        {
#if UNITY_EDITOR
            GameAssetBundle gameAssetBundle;
            if (context.Cache.GetAssetBundle(task.AssetBundleName, out gameAssetBundle))
            {
                if (task.AssetInfo.AssetResType == AssetBundleResType.Scene)
                {
                    if (task.IsAsync())
                    {
                        if (gameAssetBundle.SceneRequest == null)//准备加载场景
                        {
                            gameAssetBundle.SceneRequest = SceneManager.LoadSceneAsync(task.AssetPath, task.LoadSceneMode);
                            if (gameAssetBundle.SceneRequest != null)
                            {
                                gameAssetBundle.SceneRequest.allowSceneActivation = false;
                            }

                            if (task.Result.ProgresCallback != null)
                            {
                                ProgressArgs progressArgs = new ProgressArgs(0, 0, task.AssetPath, true);
                                task.Result.ProgresCallback(ref progressArgs);
                            }
                            context.Cache.UpdateAssetBundle(task.AssetBundleName, ref gameAssetBundle);
                        }
                        else if (gameAssetBundle.SceneRequest != null)//检查加载场景的状态
                        {
                            if (gameAssetBundle.SceneRequest.progress.SimpleEqual(0.9f))
                            {
                                task.Result.scene = gameAssetBundle.SceneRequest;

                                gameAssetBundle.SceneRequest = null;

                                if (task.Result.ProgresCallback != null)
                                {
                                    ProgressArgs progressArgs = new ProgressArgs(1, 0, task.AssetPath, true);
                                    task.Result.ProgresCallback(ref progressArgs);
                                }
                                task.FinishTime = Time.realtimeSinceStartup;
                                context.Cache.UpdateAssetBundle(task.AssetBundleName, ref gameAssetBundle);
                            }
                        }
                    }
                    else
                    {
                        SceneManager.LoadScene(task.AssetPath, task.LoadSceneMode);

                        if (task.Result.ProgresCallback != null)
                        {
                            ProgressArgs progressArgs = new ProgressArgs(1, 0, task.AssetPath, true);
                            task.Result.ProgresCallback(ref progressArgs);
                        }
                        task.FinishTime = Time.realtimeSinceStartup;
                    }
                }
                else
                {
                    if (!gameAssetBundle.ContainsAsset(task.AssetPath))
                    {
                        var unityasset = AssetDatabase.LoadAssetAtPath <Object>(task.AssetPath);
                        if (unityasset != null)
                        {
                            UpdateMaterial(unityasset);
                            //update
                            gameAssetBundle.AddAsset(task.AssetPath, unityasset);
                            context.Cache.UpdateAssetBundle(task.AssetBundleName, ref gameAssetBundle);
                        }
                        else
                        {
                            Debug.LogErrorFormat("not found asset :{0}", task.AssetPath);
                            AddException(ref context, task.AssetPath);
                        }
                    }

                    task.FinishTime = Time.realtimeSinceStartup;
                }
            }
            else
            {
                Debug.LogErrorFormat("not found gameassetbundle :{0}", task.AssetBundleName);
                AddException(ref context, task.AssetPath);
            }
#endif
        }
Exemplo n.º 20
0
 protected override bool IsEnableTask(ref AssetBundleContext context, ref AssetBundleTask task)
 {
     return(task.TaskResType <= TaskResType.GameObject && base.IsEnableTask(ref context, ref task));
 }
        bool LoadAssetBundle(ref AssetBundleContext context, ref AssetBundleTask task)
        {
            bool result = false;

            if (task.FinishTime > 0)
            {
                result = true;
            }
            else
            {
                if (task.IsLoad())
                {
                    LoadDependency(ref context, ref task, ref result);

                    LoadSubTask(ref context, ref task, ref result);

                    int finishcnt;
                    int totalcnt;
                    if (task.IsSubAllDone(ref context, out finishcnt, out totalcnt)) //
                    {
                        GameAssetBundle gameAssetBundle;
                        if (context.Cache.GetAssetBundle(task.AssetBundleName, out gameAssetBundle))
                        {
                            if (task.Result.ProgresCallback != null)
                            {
                                ProgressArgs progressArgs = new ProgressArgs((float)finishcnt / (totalcnt + 1), 0, task.AssetPath, false);
                                task.Result.ProgresCallback(ref progressArgs);
                            }

                            Load(ref context, ref task, ref gameAssetBundle, ref result, true);
                            context.Cache.UpdateAssetBundle(task.AssetBundleName, ref gameAssetBundle);
                        }
                        else
                        {
                            Debug.LogErrorFormat("not found gameassetbundle :{0}", task.AssetBundleName);
                            AddException(ref context, task.AssetPath);
                        }
                    }
                    else
                    {
                        if (task.Result.ProgresCallback != null)
                        {
                            ProgressArgs progressArgs = new ProgressArgs((float)finishcnt / (totalcnt + 1), 0, task.AssetPath, false);
                            task.Result.ProgresCallback(ref progressArgs);
                        }
                    }
                }
                else if (task.IsUnLoad())
                {
                    GameAssetBundle gameAssetBundle;
                    if (context.Cache.GetAssetBundle(task.AssetBundleName, out gameAssetBundle))
                    {
                        UnLoad(ref task, ref gameAssetBundle, ref result);
                    }
                    else
                    {
                        Debug.LogErrorFormat("not found gameassetbundle :{0}", task.AssetBundleName);
                        AddException(ref context, task.AssetPath);
                    }
                }
                else if (task.IsPreLoad())
                {
                    LoadDependency(ref context, ref task, ref result);
                    PreLoadSubTask(ref context, ref task, ref result);

                    int finishcnt;
                    int totalcnt;

                    if (task.IsSubAllDone(ref context, out finishcnt, out totalcnt)) //
                    {
                        GameAssetBundle gameAssetBundle;
                        if (context.Cache.GetAssetBundle(task.AssetBundleName, out gameAssetBundle))
                        {
                            if (task.Result.ProgresCallback != null)
                            {
                                ProgressArgs progressArgs = new ProgressArgs((float)finishcnt / (totalcnt + 1), 0, task.AssetPath, false);
                                task.Result.ProgresCallback(ref progressArgs);
                            }

                            PreLoad(ref context, ref task, ref gameAssetBundle, ref result, true);
                            context.Cache.UpdateAssetBundle(task.AssetBundleName, ref gameAssetBundle);
                        }
                        else
                        {
                            Debug.LogErrorFormat("not found gameassetbundle :{0}", task.AssetBundleName);
                            AddException(ref context, task.AssetPath);
                        }
                    }
                    else
                    {
                        if (task.Result.ProgresCallback != null)
                        {
                            ProgressArgs progressArgs = new ProgressArgs((float)finishcnt / (totalcnt + 1), 0, task.AssetPath, false);
                            task.Result.ProgresCallback(ref progressArgs);
                        }
                    }
                }
            }

            return(result);
        }
 protected virtual bool IsEnableTask(ref AssetBundleContext context, ref AssetBundleTask task)
 {
     return(!task.IsStatus(ref context, AssetBundleStatus.FileNotExist | AssetBundleStatus.LoadException | AssetBundleStatus.NotInMemory));
 }
 protected virtual bool IsEnableLoadAssetBunlde(ref AssetBundleContext context, ref AssetBundleTask task, ref GameAssetBundle gameAssetBundle)
 {
     return(true);
 }
 protected virtual void PreLoad(ref AssetBundleContext context, ref AssetBundleTask task, ref GameAssetBundle gameAssetBundle, ref bool retcode, bool mainloadrequest = false)
 {
     this.Load(ref context, ref task, ref gameAssetBundle, ref retcode, mainloadrequest);
 }
        protected virtual void Load(ref AssetBundleContext context, ref AssetBundleTask task,
                                    ref GameAssetBundle gameAssetBundle, ref bool retcode, bool mainloadrequest = false)
        {
            if (gameAssetBundle.IsException())
            {
                return;
            }

            if (AssetBundleConfig.DebugMode.HasEnum(DebugMode.Detail))
            {
                Debug.LogFormat("Load --- {0}", task);
            }

            gameAssetBundle.AssetStatus |= AssetBundleStatus.Loading;
            //not loaded
            if (gameAssetBundle.AssetBundle == null && gameAssetBundle.LoadRequest == null && gameAssetBundle.LoadAssetRequest == null)
            {
                if (IsEnableLoadAssetBunlde(ref context, ref task, ref gameAssetBundle))
                {
                    string assetfilename = AssetBundleConfig.Convert(task.AssetBundleName);
                    string path          = AssetBundleHelper.GetBundlePersistentPath(assetfilename);
                    bool   fileExist     = File.Exists(path);

                    string url;
                    bool   indownloadcache = context.Cache.TryGetDownloadUrl(new IgnoreCaseString(task.AssetBundleName), out url);
                    bool   canload         = false;
                    if (indownloadcache && !fileExist)
                    {
                        AssetDownloadInfo downloadInfo = new AssetDownloadInfo();
                        downloadInfo.AssetPath       = task.AssetPath;
                        downloadInfo.AssetBundleName = task.AssetBundleName;
                        if (!context.DownLoadQueue.Contains(downloadInfo))
                        {
                            downloadInfo.DstPath = path;
                            downloadInfo.Url     = url;
                            downloadInfo.TaskId  = task.TaskId;
                            context.DownLoadQueue.Add(downloadInfo);
                        }
                    }
                    else if (fileExist)
                    {
                        canload = true;
                    }
                    else if (!fileExist)
                    {
                        string streampath = AssetBundleHelper.GetBundleStreamPath(assetfilename);
                        if (File.Exists(streampath))
                        {
                            canload = true;
                            path    = streampath;
                        }
                    }

                    if (canload)
                    {
                        if (task.IsAsync())
                        {
                            gameAssetBundle.LoadRequest = AssetBundle.LoadFromFileAsync(path);
                            if (AssetBundleConfig.DebugMode.HasEnum(DebugMode.Detail))
                            {
                                Debug.LogFormat("LoadFromFileAsync AssetBundle :{0} ", task.AssetBundleName);
                            }
                        }
                        else
                        {
                            gameAssetBundle.AssetBundle = AssetBundle.LoadFromFile(path);
                            if (AssetBundleConfig.DebugMode.HasEnum(DebugMode.Detail))
                            {
                                Debug.LogFormat("LoadFromFile AssetBundle :{0} ", task.AssetBundleName);
                            }

                            AfterLoadAssetBundle(ref context, ref task, ref gameAssetBundle, ref retcode, ref mainloadrequest);
                        }
                    }
                    else if (!indownloadcache)
                    {
                        gameAssetBundle.AssetStatus |= AssetBundleStatus.FileNotExist;
                        AddException(ref context, task.AssetPath);
                        Debug.LogError(string.Format("cant load :{0}", task));
                    }
                }
            }
            else if (gameAssetBundle.LoadRequest != null)// in asyncing Load AssetBundle
            {
                if (gameAssetBundle.LoadRequest.isDone)
                {
                    if (AssetBundleConfig.DebugMode.HasEnum(DebugMode.Detail))
                    {
                        Debug.LogFormat("Async Task for Load AssetBundle is Done :{0} ", task);
                    }
                    gameAssetBundle.AssetBundle = gameAssetBundle.LoadRequest.assetBundle;

                    AfterLoadAssetBundle(ref context, ref task, ref gameAssetBundle, ref retcode, ref mainloadrequest);
                    gameAssetBundle.LoadRequest = null;
                }
            }
            else if (gameAssetBundle.LoadAssetRequest != null && mainloadrequest)// Load Asset
            {
                if (gameAssetBundle.LoadAssetRequest.isDone)
                {
                    var loadfinishasset = gameAssetBundle.LoadAssetRequest.asset;

                    if (loadfinishasset != null)
                    {
                        if (AssetBundleConfig.DebugMode.HasEnum(DebugMode.Detail))
                        {
                            Debug.LogFormat("Async Task Add Asset :{0} ", task);
                        }
                        gameAssetBundle.AddAsset(task.AssetPath, gameAssetBundle.LoadAssetRequest.asset);
                        gameAssetBundle.AssetStatus |= AssetBundleStatus.InMemory;
                        if (task.Result.ProgresCallback != null)
                        {
                            ProgressArgs progressArgs = new ProgressArgs(1, 0, task.AssetPath, true);
                            task.Result.ProgresCallback(ref progressArgs);
                        }
                        task.FinishTime = Time.realtimeSinceStartup;
                        retcode         = true;
                    }
                    else
                    {
                        Debug.LogErrorFormat("{0} has 0 Assets", gameAssetBundle.AssetBundle);
                        gameAssetBundle.AssetStatus |= AssetBundleStatus.NotInMemory;
                    }

                    gameAssetBundle.LoadAssetRequest = null;
                }
            }
            else
            {
                if (mainloadrequest)
                {
                    LoadMainAsset(ref context, ref task, ref gameAssetBundle, ref retcode);
                }
            }
        }
        //Load Main Asset
        protected virtual void LoadMainAsset(ref AssetBundleContext context, ref AssetBundleTask task, ref GameAssetBundle gameAssetBundle, ref bool retcode)
        {
            if (!gameAssetBundle.ContainsAsset(task.AssetPath))
            {
                if (task.IsAsync())
                {
                    //Load Async Asset

                    if (task.AssetInfo.AssetResType == AssetBundleResType.Image)
                    {
                        gameAssetBundle.LoadAssetRequest = gameAssetBundle.AssetBundle.LoadAssetAsync <Sprite>(task.AssetInfo.AssetName);
                        if (gameAssetBundle.LoadAssetRequest == null || gameAssetBundle.LoadAssetRequest.asset == null)
                        {
                            gameAssetBundle.LoadAssetRequest = gameAssetBundle.AssetBundle.LoadAssetAsync(task.AssetInfo.AssetName);
                        }
                    }
                    else
                    {
                        gameAssetBundle.LoadAssetRequest = gameAssetBundle.AssetBundle.LoadAssetAsync(task.AssetInfo.AssetName);
                    }

                    if (AssetBundleConfig.DebugMode.HasEnum(DebugMode.Detail))
                    {
                        Debug.LogFormat("Load Async Asset :{0}", task);
                    }
                }
                else
                {
                    //Load Asset
                    Object asset = null;
                    if (task.AssetInfo.AssetResType == AssetBundleResType.Image)
                    {
                        asset = gameAssetBundle.AssetBundle.LoadAsset <Sprite>(task.AssetInfo.AssetName);
                        if (asset == null)
                        {
                            asset = gameAssetBundle.AssetBundle.LoadAsset(task.AssetInfo.AssetName);
                        }
                    }
                    else
                    {
                        asset = gameAssetBundle.AssetBundle.LoadAsset(task.AssetInfo.AssetName);
                    }
                    // gameAssetBundle.AssetBundle.LoadAsset(task.AssetInfo.AssetName);

                    if (AssetBundleConfig.DebugMode.HasEnum(DebugMode.Detail))
                    {
                        Debug.LogFormat("Load Sync Asset :{0}", task);
                    }

                    if (asset != null)
                    {
                        gameAssetBundle.AddAsset(task.AssetPath, asset);
                        if (AssetBundleConfig.DebugMode.HasEnum(DebugMode.Detail))
                        {
                            Debug.LogFormat("Add Asset :{0} ", task);
                        }
                        gameAssetBundle.AssetStatus |= AssetBundleStatus.InMemory;

                        if (task.Result.ProgresCallback != null)
                        {
                            ProgressArgs progressArgs = new ProgressArgs(1, 0, task.AssetPath, true);
                            task.Result.ProgresCallback(ref progressArgs);
                        }
                        task.FinishTime = Time.realtimeSinceStartup;
                        retcode         = true;
                    }
                    else
                    {
                        Debug.LogErrorFormat("{0} cant load Asset", gameAssetBundle.AssetBundle);
                        gameAssetBundle.AssetStatus |= AssetBundleStatus.NotInMemory;
                    }
                }
            }
            else
            {
                if (task.Result.ProgresCallback != null)
                {
                    ProgressArgs progressArgs = new ProgressArgs(1, 0, task.AssetPath, true);
                    task.Result.ProgresCallback(ref progressArgs);
                }

                task.FinishTime = Time.realtimeSinceStartup;
                retcode         = true;
            }
        }