Esempio n. 1
0
        public void Load(AssetLoadRequest req)
        {
            string url = req.url;

            if (loaded.TryGetValue(url, out var info))
            {
                //已经加载完了
                info.unusedFrame = 0;
                req.assetHandle  = new AssetHandle(info.asset, refMgr.GetOrCreateRef(info.asset));
                req.Complete();
                return;
            }

            var webReq = req.GetData <UnityWebRequest>("__webRequest");

            if (webReq == null)
            {
                webReq = UnityWebRequest.Get(url);
            }
            var opt = webReq.SendWebRequest();

            opt.completed += OnRequestCompelted;

            if (loadingReqs.TryGetValue(url, out var reqs))
            {
                reqs.Add(req);
            }
            else
            {
                reqs = new List <AssetLoadRequest>();
                reqs.Add(req);
                loadingReqs[url] = reqs;
            }
        }
Esempio n. 2
0
        bool DoLoadSync(AssetLoadRequest req)
        {
            var handle = GetLoadHandle(req.path);

            req.assetHandle = handle.Load(req.type);
            req.Complete();
            return(req.assetHandle.isValid);
        }
 private void OnRequestComplted(AssetLoadRequest req)
 {
     --loadingCount;
     if (!isDone)
     {
         return;
     }
     OnCompleted();
 }
        public void AddRequest(string path, Type type = null, GameObject autoRefGameObject = null)
        {
            var req = AssetLoadRequest.Get();

            req.path = path;
            req.type = type;
            req.autoRefGameObject = autoRefGameObject;
            AddRequest(req);
        }
Esempio n. 5
0
 private void OnLoadCompleted(Object asset, AssetLoadRequest req)
 {
     loaded[req.path] = new WebAssetInfo()
     {
         asset       = asset,
         unusedFrame = 0,
     };
     req.assetHandle = new AssetHandle(asset, refMgr.GetOrCreateRef(asset));
     req.Complete();
 }
 //添加提前创建的任务
 //注意任务回调会被覆盖掉
 public void AddRequest(AssetLoadRequest req)
 {
     reqs.Add(req);
     req.onCompleted = OnRequestComplted;
     if (req.autoFree)
     {
         req.autoFree = false;
         autoFreeReqs.Add(req);
     }
 }
 protected virtual void OnCompleted()
 {
     //全部加载结束
     if (onBatchCompleted != null)
     {
         onBatchCompleted(this);
     }
     //回收
     foreach (var autoFreeReq in autoFreeReqs)
     {
         AssetLoadRequest.Free(autoFreeReq);
     }
     autoFreeReqs.Clear();
     reqs.Clear();
 }
Esempio n. 8
0
 bool DoLoadAsync(AssetLoadRequest req)
 {
     if (!req.isUrl)
     {
         var handle = GetLoadHandle(req.path);
         return(handle.LoadAsync(req));
     }
     else
     {
         var group = req.GetData <string>("__webGroup");
         if (webLoaders.TryGetValue(group, out var loader))
         {
             loader.Load(req);
             return(true);
         }
         return(false);
     }
 }
Esempio n. 9
0
 public void StartLoad(AssetLoadRequest req)
 {
     if (req == null)
     {
         return;
     }
     if (req.priority <= AssetLoadRequest.Priority_Sync)
     {
         DoLoadSync(req);
         return;
     }
     if (loadProcessCoroutine == null)
     {
         loadProcessCoroutine = StartCoroutine(AssetLoadProcess());
         StartCoroutine(AutoClearInvalidAssetRef());
     }
     requestQueue.Enqueue(req.priority, req);
 }
Esempio n. 10
0
        public AssetLoadRequest LoadAsync(string path
                                          , GameObject autoRefGameObject
                                          , AssetLoadRequest.OnCompleted cb = null
                                          , Type type    = null
                                          , int priority = AssetLoadRequest.Priority_Common
                                          )
        {
            var req = AssetLoadRequest.Get();

            req.path              = path;
            req.type              = type;
            req.onCompleted       = cb;
            req.autoRefGameObject = autoRefGameObject;
            req.priority          = priority;
            req.autoFree          = true;
            StartLoad(req);
            return(req);
        }
Esempio n. 11
0
        public AssetLoadRequest LoadWebTexture(string group, string url
                                               , GameObject autoRefGameObject    = null
                                               , AssetLoadRequest.OnCompleted cb = null
                                               , int priority = AssetLoadRequest.Priority_Common)
        {
            if (priority <= AssetLoadRequest.Priority_Fast)
            {
                throw new Exception("Load From web not support sync mode." + url);
            }
            AssetLoadRequest req = AssetLoadRequest.Get();

            req.url = url;
            req.autoRefGameObject = autoRefGameObject;
            req.priority          = priority;
            req.type        = typeof(Texture2D);
            req.onCompleted = cb;
            req.AttachData("__webGroup", group);
            StartLoad(req);
            return(req);
        }
Esempio n. 12
0
        public AssetLoadRequest LoadFromWeb(string group, UnityEngine.Networking.UnityWebRequest webReq
                                            , GameObject autoRefGameObject    = null
                                            , AssetLoadRequest.OnCompleted cb = null
                                            , int priority = AssetLoadRequest.Priority_Common
                                            )
        {
            if (priority <= AssetLoadRequest.Priority_Fast)
            {
                throw new Exception("Load From web not support sync mode." + webReq.url);
            }
            AssetLoadRequest req = AssetLoadRequest.Get();

            req.url = webReq.url;
            req.autoRefGameObject = autoRefGameObject;
            req.priority          = priority;
            req.onCompleted       = cb;
            req.AttachData("__webReq", webReq);
            req.AttachData("__webGroup", group);
            StartLoad(req);
            return(req);
        }
Esempio n. 13
0
 public bool LoadAsync(AssetLoadRequest req)
 {
     return(abLoader.LoadFromAbAsync(abPath, assetName, req));
 }
Esempio n. 14
0
 public bool LoadAsync(AssetLoadRequest req)
 {
     req.Complete();
     return(false);
 }
Esempio n. 15
0
 public bool LoadAsync(AssetLoadRequest req)
 {
     req.assetHandle = Load(req.type);
     req.Complete();
     return(req.assetHandle.isValid);
 }
 //回收任务,减少gc
 public static void Free(AssetLoadRequest req)
 {
     gcPool.Free(req);
 }