예제 #1
0
        //提交一个 同步加载请求
        public void LoadRequest(LoadRequest req)
        {
            if (req == null)
            {
                return;
            }

            foreach (var task in req)
            {
                LoadTask(task);
            }

            OnRequestLoaded(req);
        }
예제 #2
0
 //请求执行完后的回调
 private void OnRequestLoaded(LoadRequest req)
 {
     foreach (var task in req)
     {
         AssetReference assetRef;
         if (TryGetAssetReference(task.LoadedAsset, out assetRef))
         {
             assetRef.UnReference(); //释放Request带来的引用
         }
     }
     if (!req.IsCancel)
     {
         req.CallAllLoaded();
     }
 }
예제 #3
0
        //提交一个 异步加载请求
        public void LoadRequestAsync(LoadRequest req, LoadRequest.OnAllLoaded onLoaded = null)
        {
            if (req == null)
            {
                return;
            }
            //辅助写法,防止回调设置晚了
            if (req.onAllLoaded == null && onLoaded != null)
            {
                req.onAllLoaded = onLoaded;
            }

            //Debug.Log("New Request");
            _loadingQueue.AddLoadRequest(req);
        }
예제 #4
0
        //将引用计数托管给GameObject
        public void ReferenceAssetsWithGo(GameObject go, LoadRequest request)
        {
            if (request == null || go == null)
            {
                return;
            }
            AssetReferenceComponent comp = TryGetAssetReferenceComponent(go);

            foreach (var task in request)
            {
                if (task.LoadedAsset != null)
                {
                    ReferenceAssetWithGo(comp, task.LoadedAsset);
                }
            }
        }
예제 #5
0
 public override IEnumerator Load()
 {
     while (_loadingQueue.Count > 0)
     {
         LoadRequest req = _loadingQueue.Dequeue();
         if (req.IsDone || req.IsCancel)
         {
             continue;
         }
         //全部提交
         foreach (LoadTask task in req)
         {
             LoadTask(task);
         }
         OnRequestLoaded(req);
         yield return(null);
     }
 }
예제 #6
0
        public override IEnumerator Load()
        {
            while (_loadingQueue.Count > 0)
            {
                LoadRequest req = _loadingQueue.Dequeue();
                if (req.IsDone || req.IsCancel)
                {
                    continue;
                }
                //一次提交一个,加载完再次提交
                foreach (LoadTask task in req)
                {
                    LoadTaskAsync(task);
                    yield return(new LoadTaskAsync(task));

                    //加载完一个任务后发现整个请求取消了
                    if (req.IsCancel)
                    {
                        break;
                    }
                }
                OnRequestLoaded(req);
            }
        }
예제 #7
0
 public LoadReqAsync(LoadRequest req)
 {
     Req = req;
 }
예제 #8
0
 public void OnRequestLoaded(LoadRequest req)
 {
     this._onLoaded(req);
 }
예제 #9
0
 public void AddLoadRequest(LoadRequest req)
 {
     _loadingQueue.Enqueue(req);
 }