Exemple #1
0
 public void AddNode(string path, ResLoadNode node)
 {
     if (!_resLoadNodes.ContainsKey(path))
     {
         _resLoadNodes.Add(path, node);
     }
 }
Exemple #2
0
        //开始下载
        private void loadAll()
        {
            this.fileCount = this.pathArr.Length;

            for (int i = 0; i < pathArr.Length; i++)
            {
                ResLoadNode node     = null;
                bool        isCraete = ResLoadNode.CreateOrGetNode(pathArr[i], out node, key); //引用计数+1

                if (!isCraete && node.success)                                                 //已经加载完毕的了
                {
                    onNodeLoaded(node);
                }
                else if (!isCraete && !string.IsNullOrEmpty(node.path) && node.fn != null)//正在加载的
                {
                    node.fn += onNodeLoaded;
                }
                else//刚创建出来的
                {
                    //路径
                    node.path            = pathArr[i];
                    nodeDict[pathArr[i]] = node;//node.relaPath
                    node.relaPath        = pathArr[i];
                    //加载完毕回调函数
                    node.fn = onNodeLoaded;
                    DownLoadManager.instance.addNode(node);
                }
            }
        }
Exemple #3
0
        public ResLoadNode GetNode(string path)
        {
            ResLoadNode node = null;

            _resLoadNodes.TryGetValue(path, out node);
            return(node);
        }
Exemple #4
0
 //添加一个下载节点
 public void addNode(ResLoadNode node)
 {
     if (actArr.Count < maxThread)
     {
         actArr.Add(node);
         execOne(node);
     }
     else
     {
         nodeArr.Add(node);
     }
 }
Exemple #5
0
 //检查是否可以继续下载
 public void checkQueue()
 {
     if (nodeArr.Count > 0 && actArr.Count < maxThread)
     {
         ResLoadNode node = nodeArr[0];
         nodeArr.RemoveAt(0);
         actArr.Add(node);
         execOne(node);
     }
     if (showDebug && nodeArr.Count == 0 && actArr.Count == 0)
     {
         //Log.Info("*** All File Loaded ***", "DownloadManager");
     }
 }
Exemple #6
0
 //下载完成
 private void onFinish(ResLoadNode node)
 {
     if (node == null || this == null || actArr == null)
     {
         return;
     }
     //loadingOver = node.relaPath;
     actArr.Remove(node);
     this.checkQueue();
     if (node.fn != null)
     {
         node.fn(node);
     }
 }
Exemple #7
0
 public static bool CreateOrGetNode(string path, out ResLoadNode node, string key)
 {
     node = GetMgr().GetNode(path);
     if (node == null)
     {
         GetMgr().RemoveNode(path);
         node = new ResLoadNode();
         GetMgr().AddNode(path, node);
         //Debug.LogError(key + " create node retain " + path);
         return(true);
     }
     else
     {
         //Debug.LogError(key + " add node retain " + path);
         node.Retain();
     }
     return(false);
 }
Exemple #8
0
 private void onNodeLoaded(ResLoadNode node)
 {
     if (this == null || this.Equals(null))
     {
         //Log.Error("onNodeLoaded().this");
         return;
     }
     if (nodeDict == null)
     {
         //Log.Error("onNodeLoaded().nodeDict");
         return;
     }
     this.fileCount--;
     if (key == node.path)
     {
         content = node;
     }
     if (fileCount <= 0)
     {
         this.success = true;
         for (int i = 0; i < fns.Count; i++)
         {
             callback fn = fns[i];
             currentPrefabName = prefabNames[i];
             fn(this, fnParas[i]);
         }
         fns.Clear();
         fnParas.Clear();
         if (!isCache)
         {
             unload();
             DeviceFactory.Instance.RemoveDirResLoadInfoByKey(key);
             // Debug.Log("remove " + key + "      " + currentPrefabName);
         }
         else
         {
             // Debug.LogError("cache "+key+"      "+currentPrefabName+"PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP");
         }
     }
 }
Exemple #9
0
        //
        public IEnumerator downLoad(ResLoadNode node)
        {
            while (!Caching.ready)
            {
                yield return(null);
            }

            if (showDebug)
            {
                //Log.Info("load :  " + node.path, "DownloadManager");
            }
            //如果是ab,则使用cache模式

            //老的加载方式
//            if (node.isABFile && GlobalData.systemSet.isCacheResource)
//            {
//#if UNITY_EDITOR
//                node.wwwRes = new WWW(node.path);
//#else
//            node.wwwRes = WWW.LoadFromCacheOrDownload(node.path, BuildVer.fileVer);
//#endif
//            }
//            else
            // int verNum = GameApp.GetVersionManager().GetVersionNum(assetBundleName);
            // if (!Caching.IsVersionCached(node.path,0))
            {
                node.wwwRes = new WWW(node.path);
                while (!node.wwwRes.isDone)
                {
                    // Log.Info("progress " + node.path + " : " + node.wwwRes.progress);
                    yield return(null);
                }
                //报错
                if (!string.IsNullOrEmpty(node.wwwRes.error))
                {
                    //if (node.path.Contains("/PlatformAssets/"))
                    //    ErrorList.Add(node.path.Split(new string[] { "/PlatformAssets/" }, System.StringSplitOptions.None)[1]);
                    //else
                    //    if (node.path.Contains("/platformAssets/"))
                    //        ErrorList.Add(node.path.Split(new string[] { "/platformAssets/" }, System.StringSplitOptions.None)[1]);

                    // Log.Error("load error " + node.wwwRes.error);
                }
                else
                {
                    node.success = true;
                    //统一ab接口
                    if (node.isABFile)
                    {
                        node.ab = node.wwwRes.assetBundle;
                        // Log.Info("down ::::::" + node.relaPath+" :: "+node.path);
                    }
                }
                onFinish(node);
            }
            //else
            //{
            //    Log.Info("IsVersionCached ::::::" + node.path);
            //    onFinish(node);
            //}
        }
Exemple #10
0
 //开始下载一个
 private void execOne(ResLoadNode node)
 {
     StartCoroutine(downLoad(node));
 }