示例#1
0
 /// <summary>
 /// 同步方式;
 /// </summary>
 public IEnumerator LoadConfigSync(string strOutFilePath, string strInFilePath, string strNetFilePath, string strName)
 {
     strOutFilePath = strOutFilePath + strName + ".txt";
     strInFilePath  = strInFilePath + strName + ".txt";
     strName        = strName + ".txt";
     if (WWWDownLoaderConfig.CheckResNeedUpdate(strName))
     {
         DownLoadPack downloadPack = WWWDownLoader.InsertDownLoad(strName, strNetFilePath + strName, DownLoadAssetType.Text, null, null, DownLoadOrderType.AfterRunning);
         if (downloadPack != null)
         {
             while (!downloadPack.AssetReady)
             {
                 yield return(null);
             }
             using (StreamReader sr = new StreamReader(new MemoryStream(downloadPack.DataBytes), CommonFunc.GetCharsetEncoding()))
             {
                 ParseConfig(sr);
                 sr.Close();
             }
         }
         WWWDownLoader.RemoveDownLoad(strName, null);
     }
     else
     {
         IEnumerator itor = LoadConfigFromLocal(strOutFilePath, strInFilePath);
         while (itor.MoveNext())
         {
             yield return(null);
         }
     }
     Messenger.Broadcast(MessangerEventDef.LOAD_ONEASSET_FINISH, MessengerMode.DONT_REQUIRE_LISTENER);
 }
示例#2
0
        static public void RemoveDownLoad(string strName, Callback <object> callBack, bool isKeepDownLoading)
        {
            if (m_AssetPackMap.ContainsKey(strName))
            {
                DownLoadPack pack = m_AssetPackMap[strName];
                if (pack != null)
                {
                    pack.m_AssetRefer--;
                    pack.AssetInfo.m_callBack -= callBack;

                    if (pack.m_AssetRefer <= 0)                    //可能会出现小于0的情况,下载到一半停止,资源没有被引用,计数为0可以被删.
                    {
                        pack.AssetInfo.m_callBack = null;          //卸载完成callback一定会为null.之前的 CallBack -= 并不一定能确保CallBack被清空了.

                        if (!isKeepDownLoading)
                        {
                            //不保持下载,正常卸载流程;
                            if (pack.State != AssetState.Finish)                            //为下载完,被卸载,本地没有保存,已下载size不需要增加;
                            {
                                m_nDownLoadSize -= pack.AssetInfo.m_nSize;
                            }

                            DownLoadCoroutine freeCoroutine = pack.ReleaseDownLoadCoroutine();
                            RecycleDownLoadCoroutine(freeCoroutine);
                            m_AssetPackMap.Remove(strName);

                            if (m_AssetPackNameList.Contains(strName))
                            {
                                m_AssetPackNameList.Remove(strName);
                            }
                        }
                    }
                }
            }
        }
示例#3
0
        public static IEnumerator LoadAllShader(string assetDir, string assetWWWDir, string inAssetDir, string inAssetWWWDir, string assetNetDir)
        {
            string strName = "all.shd";

            if (WWWDownLoaderConfig.CheckResNeedUpdate(strName))
            {
                DownLoadPack downloadPack = WWWDownLoader.InsertDownLoad(strName, assetNetDir + strName, DownLoadAssetType.AssetBundle, null, null, DownLoadOrderType.AfterRunning);
                if (downloadPack != null)
                {
                    while (!downloadPack.AssetReady)
                    {
                        yield return(null);
                    }
                    m_ShaderAsset = downloadPack.Bundle;
                }
                WWWDownLoader.RemoveDownLoad(strName, null);
            }
            else
            {
                IEnumerator itor = LoadAllShader(assetDir, assetWWWDir, inAssetDir, inAssetWWWDir);
                while (itor.MoveNext())
                {
                    yield return(null);
                }
            }

            if (m_ShaderAsset != null)
            {
                m_AllShader = m_ShaderAsset.LoadAll();
            }
            Shader.WarmupAllShaders();
            Messenger.Broadcast(MessangerEventDef.LOAD_ONEASSET_FINISH, MessengerMode.DONT_REQUIRE_LISTENER);
        }
示例#4
0
 /// <summary>
 /// 停止某个链接下载;
 /// </summary>
 static public void StopLoad(string strName)
 {
     if (m_AssetPackMap.ContainsKey(strName))
     {
         DownLoadPack pack = m_AssetPackMap[strName];
         if (pack != null)
         {
             DownLoadCoroutine freeCoroutine = pack.ReleaseDownLoadCoroutine();
             RecycleDownLoadCoroutine(freeCoroutine);
             pack.Stop();
         }
     }
 }
示例#5
0
        public static IEnumerator LoaddefaultSkins()
        {
            string strName = "default.skn";

            if (WWWDownLoaderConfig.CheckResNeedUpdate(strName))
            {
                DownLoadPack downloadPack = WWWDownLoader.InsertDownLoad(strName, GetSkinResPath() + strName, DownLoadAssetType.AssetBundle, null, null, DownLoadOrderType.AfterRunning);
                if (downloadPack != null)
                {
                    while (!downloadPack.AssetReady)
                    {
                        yield return(null);
                    }
                    s_DefaultSkins = downloadPack.Bundle;
                }

                WWWDownLoader.RemoveDownLoad(strName, null);
            }
            else
            {
                string strSkins  = mAssetWWWDir + "Skin/default.skn";
                string assetPath = mAssetDir + "Skin/default.skn";
                if (!File.Exists(assetPath))
                {
                    strSkins = mInAssetWWWDir + "Skin/default.skn";
                }

                WWW www = null;
                using (www = new WWW(strSkins))
                {
                    while (!www.isDone)
                    {
                        yield return(null);
                    }
                    if (www.error != null)
                    {
                        Debug.LogError("Skin Load Error!");
                        Debug.LogError(www.error);
                    }
                    else
                    {
                        s_DefaultSkins = www.assetBundle;
                    }

                    www.Dispose();
                    www = null;
                }
            }
            Messenger.Broadcast(MessangerEventDef.LOAD_ONEASSET_FINISH, MessengerMode.DONT_REQUIRE_LISTENER);
        }
示例#6
0
        /// <summary>
        /// 开始未下载的任务;
        /// </summary>
        static private void StartAll()
        {
            int  nRunCount = 0;
            long nRunSize  = 0;

            for (int i = 0; i < m_AssetPackNameList.Count; i++)
            {
                string assetName = m_AssetPackNameList[i];
                if (m_AssetPackMap.ContainsKey(assetName))
                {
                    DownLoadPack gtPack = m_AssetPackMap[assetName];
                    if (gtPack == null)
                    {
                        Debug.LogWarning("WWWDownLoader StartAll, gtPack can not be null.");
                    }
                    else
                    {
                        nRunCount++;
                        nRunSize += gtPack.AssetInfo.m_nSize;

                        if (nRunCount > CommonDef.DOWNLOAD_MAX_LINK)                        //正常的链接限制控制;
                        {
                            StopLoad(assetName);
                            //Debug.LogError("WWWDownLoader StartAll, Max Link: " + gtPack.AssetInfo.m_strName + ",nRunCount:" + nRunCount);
                        }
                        else if (gtPack.AssetInfo.m_nSize + nRunSize >= CommonDef.DOWNLOAD_MAX_SIZE)                        //正常的链接限制控制;
                        {
                            StopLoad(assetName);
                            //Debug.LogError("WWWDownLoader InsertDownLoad, Max Running Size: " + gtPack.AssetInfo.m_strName + ",AssetSize:" + gtPack.AssetInfo.m_nSize + ",RunSize:" + nRunSize);
                        }
                        else if (gtPack.AssetInfo.m_nSize + m_nDownLoadSize >= m_MomorySize)                        //本机硬盘空间不足,属于异常;
                        {
                            StopLoad(assetName);
                            Debug.LogError("WWWDownLoader InsertDownLoad, No More SDCard Memory: " + gtPack.AssetInfo.m_strName + ",AssetSize:" + gtPack.AssetInfo.m_nSize + ",DownLoadSize:" + m_nDownLoadSize);
                        }
                        else
                        {
                            if (gtPack.State == AssetState.Waitting || gtPack.State == AssetState.HasRelease)                            //取停止状态下的任务,重新下载;
                            {
                                gtPack.LoadAsset(GetDownLoadCoroutine());
                            }
                        }
                    }
                }
            }
        }
示例#7
0
        static private DownLoadPack AddDownLoadAssetPack(string strName, string strURL, DownLoadAssetType assetType, Callback <object> callBack, object exData, bool debugError)
        {
            DownLoadPack gtAssetPack = null;

            if (m_AssetPackMap.ContainsKey(strName))            //如果存在上一个if的情况,此步等同于下载不销毁,重置回调 or 正常流程重复请求;
            {
                gtAssetPack = m_AssetPackMap[strName];
                if (gtAssetPack != null)
                {
                    gtAssetPack.AssetInfo.m_callBack += callBack;
                    gtAssetPack.m_AssetRefer++;
                }
            }
            else
            {
                DownLoadAssetInfo gtInfo = null;
                if (assetType == DownLoadAssetType.ConfigVersion)                //配置文件 特殊处理;
                {
                    gtInfo           = new DownLoadAssetInfo();
                    gtInfo.m_strName = strName;
                }
                else
                {
                    gtInfo = WWWDownLoaderConfig.GetAssetDownLoadInfo(strName);
                }

                if (gtInfo == null)
                {
                    Debug.LogError("WWWLoader LoadAsset, DownLoadInfo can not be null. \n" + strName);
                }
                else
                {
                    gtInfo.m_callBack   = callBack;
                    gtInfo.m_strFileUrl = strURL;                    //for组装下载路径 and 保存路径;

                    //gtAssetPack = new DownLoadPack(m_strWWWDownLoadUrl, gtInfo, assetType, DownLoadFinish, exData, debugError);
                    gtAssetPack = new DownLoadPack(m_strWWWDownLoadUrl, gtInfo, assetType, null, exData, debugError);

                    m_AssetPackMap.Add(strName, gtAssetPack);
                }
            }

            return(gtAssetPack);
        }
示例#8
0
        /// <summary>
        /// 检查是否可以开始下载当前任务;
        /// </summary>
        static private bool CheckCanBeginDownLoad(DownLoadPack dlPack)
        {
            int  nRunCount = 0;
            long nRunSize  = 0;

            foreach (KeyValuePair <string, DownLoadPack> kv in m_AssetPackMap)
            {
                if (kv.Value.State == AssetState.DownLoading)
                {
                    nRunCount++;
                    nRunSize += kv.Value.AssetInfo.m_nSize;
                }
            }

            if (nRunCount < CommonDef.DOWNLOAD_MAX_LINK)
            {
                if (dlPack.AssetInfo.m_nSize + m_nDownLoadSize < m_MomorySize)                //本机硬盘空间不足;
                {
                    if (dlPack.AssetInfo.m_nSize + nRunSize < CommonDef.DOWNLOAD_MAX_SIZE)
                    {
                        return(true);
                    }
                    else
                    {
                        Debug.LogError("WWWDownLoader InsertDownLoad, Max Running Size: " + dlPack.AssetInfo.m_strName + ",AssetSize:" + dlPack.AssetInfo.m_nSize + ",RunSize:" + nRunSize);
                    }
                }
                else
                {
                    Debug.LogError("WWWDownLoader InsertDownLoad, No More SDCard Memory: " + dlPack.AssetInfo.m_strName + ",AssetSize:" + dlPack.AssetInfo.m_nSize + ",DownLoadSize:" + m_nDownLoadSize);
                }
            }
            else
            {
                //在等待中的队列;
                //Debug.Log("WWWDownLoader InsertDownLoad, Max Running Link: " + dlPack.downLoadInfo.m_strName);
            }
            return(false);
        }
示例#9
0
 static public void StopAll()
 {
     //任务加入停止队列;
     for (int i = 0; i < m_AssetPackNameList.Count; i++)
     {
         string assetName = m_AssetPackNameList[i];
         if (m_AssetPackMap.ContainsKey(assetName))
         {
             DownLoadPack gtPack = m_AssetPackMap[assetName];
             if (gtPack != null)
             {
                 if (gtPack.State == AssetState.Waitting || gtPack.State == AssetState.HasRelease)                        //取停止状态下的任务;
                 {
                     m_StopingAssetPackList.Add(assetName);
                 }
             }
         }
     }
     //移除等待队列;
     for (int i = 0; i < m_StopingAssetPackList.Count; i++)
     {
         m_AssetPackNameList.Remove(m_StopingAssetPackList[i]);
     }
 }
示例#10
0
        private IEnumerator LoadingAsset(string assetName, bool isOnlyDownLoad, DownLoadOrderType downLoadOrderType)
        {
            if (m_AllAssets.ContainsKey(assetName))
            {
                AssetPack assetPack = m_AllAssets[assetName];

                string strNetLoadName = assetName + m_strAssetExtension;
                if (WWWDownLoaderConfig.CheckResNeedUpdate(strNetLoadName))                //检查版本,区分是加载or下载;
                {
                    DownLoadPack downloadPack = WWWDownLoader.InsertDownLoad(strNetLoadName, m_strAssetNetDir + strNetLoadName, DownLoadAssetType.AssetBundle, null, null, downLoadOrderType);
                    if (downloadPack != null)
                    {
                        while (!downloadPack.AssetReady)
                        {
                            assetPack.State = downloadPack.State;
                            yield return(null);
                        }

                        //资源交给AssetLoader;结束后删除wwwdownloader的任务;
                        assetPack.m_AssetBundle = downloadPack.Bundle;
                        assetPack.State         = downloadPack.State;
                    }
                    else
                    {
                        assetPack.State = AssetState.Finish;                            //临时处理,若不下载直接标记该资源已经被释放
                    }

                    WWWDownLoader.RemoveDownLoad(strNetLoadName, null);

                    if (isOnlyDownLoad)                    //如果预下载流程;
                    {
                        assetPack.UnloadAssetBundle(true); //only下载,下载完卸载资源,结束后删除wwwdownloader的任务;
                    }
                }
                else
                {
                    if (!isOnlyDownLoad)
                    {
                        IEnumerator itor = assetPack.LoadAsset(m_strAssetWWWDir, m_strAssetDir, m_strInAssetWWWDir, m_strAssetExtension);
                        while (itor.MoveNext())
                        {
                            yield return(null);
                        }
                    }
                    else
                    {
                        assetPack.State = AssetState.Finish;
                    }
                }

                if (assetPack.m_CallBack != null)
                {
                    assetPack.m_CallBack(assetName);
                }

                //下载完后判断是不是需要自主卸载,keepLoading的情况;
                assetPack.m_nKeepLoadingRefer = 0;
                if (!assetPack.m_IsResident && assetPack.m_AssetRefer <= 0 && assetPack.m_nKeepLoadingRefer <= 0)                //非常驻资源,没有外部使用,并且下载完成的情况下;
                {
                    ReleaseAsset(assetName, null, false);
                }
                else
                {
                    ReleaseDownLoadCoroutine(assetName);
                }
            }
            else
            {
                Debug.LogError("AssetLoader LoadingAsset, m_AllAssets dont has key : " + assetName);
            }
        }
示例#11
0
        /// <summary>
        /// 下载任务;
        /// </summary>
        /// <param name="strName">资源唯一key;</param>
        /// <param name="strURL">资源下载完整URL(包含资源名,由外部组合. 不包含服务器IP地址)</param>
        /// <param name="assetType">资源类型;</param>
        /// <param name="callBack">外部的回调;</param>
        /// <param name="exData">附加信息(音效提取有附加参数);</param>
        static public DownLoadPack InsertDownLoad(string strName, string strURL, DownLoadAssetType assetType, Callback <object> callBack, object exData, DownLoadOrderType downLoadOrderType, bool debugError)
        {
            DownLoadPack pack = null;

            if (!m_IgnoreDownLoad)
            {
                pack = AddDownLoadAssetPack(strName, strURL, assetType, callBack, exData, debugError);

                switch (downLoadOrderType)
                {
                case DownLoadOrderType.Head:
                {
                    if (m_AssetPackNameList.Contains(strName))                                    //重复情况,重新插入队首;
                    {
                        m_AssetPackNameList.Remove(strName);
                    }
                    m_AssetPackNameList.Insert(0, strName);
                }
                break;

                case DownLoadOrderType.AfterRunning:
                {
                    int          nIndex     = 0;                        //第一个等待下载的资源索引;
                    DownLoadPack curResPack = null;

                    for (nIndex = 0; nIndex < m_AssetPackNameList.Count; nIndex++)
                    {
                        if (m_AssetPackMap.ContainsKey(strName))
                        {
                            DownLoadPack gtPack = m_AssetPackMap[m_AssetPackNameList[nIndex]];
                            if (gtPack == null)
                            {
                                Debug.LogWarning("WWWDownLoader InsertDownLoadToWaittingBegin, gtPack can not be null.");
                                continue;
                            }
                            else
                            {
                                //获取第一个等待下载的资源的索引;
                                if (gtPack.State == AssetState.Waitting || gtPack.State == AssetState.HasRelease)
                                {
                                    break;
                                }

                                //从下载队列里面获取目标资源;
                                if (gtPack.AssetInfo.m_strName.Equals(strName))
                                {
                                    curResPack = gtPack;
                                }
                            }
                        }
                    }

                    if (curResPack == null || curResPack.State != AssetState.DownLoading)
                    {
                        if (m_AssetPackNameList.Contains(strName))
                        {
                            m_AssetPackNameList.Remove(strName);
                        }
                        m_AssetPackNameList.Insert(nIndex, strName);
                    }
                }
                break;

                default:
                    Debug.LogError("WWWDownLoader InsertDownLoad, error name : " + strName + " ,downLoadOrderType: " + downLoadOrderType);
                    break;
                }

                if (m_IsShowTipsBox)
                {
                    m_WaittingAssetPackList.Add(strName);
                    Messenger <Callback, Callback> .Broadcast(MessangerEventDef.DOWNLOAD_MOBILE_TIPSBOX, TipBoxCallBackYes, TipBoxCallBackNo);
                }
                else
                {
                    StartAll();
                }
            }

            return(pack);
        }
示例#12
0
        private IEnumerator Load()
        {
            if (mResName.StartsWith("wing_") || mResName.StartsWith("hip_") ||
                mResName.StartsWith("lefthand_") || mResName.StartsWith("righthand_") ||
                mResName.StartsWith("shoulders_") ||
                mResName.StartsWith("leftear_") || mResName.StartsWith("rightear_"))
            {
                if (WWWDownLoaderConfig.CheckResNeedUpdate(mAssetName))
                {
                    DownLoadPack downloadPack = WWWDownLoader.InsertDownLoad(mAssetName, m_assetNetDir + mChildPath + mAssetName, DownLoadAssetType.AssetBundle, null, null, DownLoadOrderType.AfterRunning);
                    if (downloadPack != null)
                    {
                        while (!downloadPack.AssetReady)
                        {
                            yield return(null);
                        }
                        bundle = downloadPack.Bundle;
                    }
                    WWWDownLoader.RemoveDownLoad(mAssetName, null);
                }
                else
                {
                    string assetWWWPath = mAssetWWWDir + mChildPath + mAssetName;
                    string assetPath    = mAssetDir + mChildPath + mAssetName;
                    if (!File.Exists(assetPath))
                    {
                        assetWWWPath = mInAssetWWWDir + mChildPath + mAssetName;
                    }

                    using (m_www = new WWW(assetWWWPath))
                    {
                        while (m_www != null && !m_www.isDone)
                        {
                            yield return(null);
                        }

                        if (m_www != null)
                        {
                            if (m_www.error != null)
                            {
                                Debug.LogError(m_www.error);
                                Debug.LogError("Model Load Error! AssetName : " + mAssetName);
                            }
                            if (m_www != null)
                            {
                                bundle = m_www.assetBundle;
                            }

                            m_www.Dispose();
                            m_www = null;
                        }
                    }
                }
                if (bundle != null)
                {
                    request = bundle.LoadAsync(mAssetName.Replace(".clh", ""), typeof(GameObject));
                    while (request != null && !request.isDone)
                    {
                        yield return(null);
                    }
                    if (request != null)
                    {
                        modelPrefab = request.asset as GameObject;
                    }

                    if (CommonValue.PhoneOS == Phone_OS.Ios)
                    {
                        bundle.Unload(false);
                    }
                }
            }
            Messenger.Broadcast(MessangerEventDef.LOAD_ONEASSET_FINISH, MessengerMode.DONT_REQUIRE_LISTENER);
        }
示例#13
0
        private IEnumerator LoadRenderer()
        {
            if (!ResuceName.StartsWith("wing_") && !ResuceName.StartsWith("hip_") &&
                !ResuceName.StartsWith("lefthand_") && !ResuceName.StartsWith("righthand_") &&
                !ResuceName.StartsWith("skin_") &&
                !ResuceName.StartsWith("shoulders_") &&
                !ResuceName.StartsWith("leftear_") && !ResuceName.StartsWith("rightear_"))
            {
                if (WWWDownLoaderConfig.CheckResNeedUpdate(ResuceName))
                {
                    DownLoadPack downloadPack = WWWDownLoader.InsertDownLoad(ResuceName, m_assetNetDir + m_ChildPath + ResuceName, DownLoadAssetType.AssetBundle, null, null, DownLoadOrderType.AfterRunning);
                    if (downloadPack != null)
                    {
                        while (!downloadPack.AssetReady)
                        {
                            yield return(null);
                        }
                        m_AssetBundle = downloadPack.Bundle;
                    }
                    WWWDownLoader.RemoveDownLoad(ResuceName, null);
                }
                else
                {
                    string assetWWWPath = mAssetWWWDir + m_ChildPath + ResuceName;
                    string assetPath    = mAssetDir + m_ChildPath + ResuceName;
                    if (!File.Exists(assetPath))
                    {
                        assetWWWPath = mInAssetWWWDir + m_ChildPath + ResuceName;
                    }

                    WWW www = null;
                    using (www = new WWW(assetWWWPath))
                    {
                        while (!www.isDone)
                        {
                            yield return(null);
                        }

                        if (string.IsNullOrEmpty(www.error))
                        {
                            m_AssetBundle = www.assetBundle;
                        }
                        else
                        {
                            Debug.LogError(www.error + "." + ResuceName);
                        }

                        www.Dispose();
                        www = null;
                    }
                }

                if (m_AssetBundle != null)
                {
                    AssetBundleRequest gameObjectRequest = null;
                    AssetBundleRequest boneNameRequest   = null;

                    gameObjectRequest = m_AssetBundle.LoadAsync(ResuceName.Replace(".clh", ""), typeof(GameObject));
                    while (!gameObjectRequest.isDone)
                    {
                        yield return(null);
                    }

                    if (m_AssetBundle != null)
                    {
                        List <AssetBundleRequest> las = new List <AssetBundleRequest>();
                        m_Prefb = (GameObject)gameObjectRequest.asset;

                        if (m_Prefb != null)
                        {
                            foreach (SkinnedMeshRenderer smr in m_Prefb.GetComponentsInChildren <SkinnedMeshRenderer>(true))
                            {
                                boneNameRequest = m_AssetBundle.LoadAsync(smr.name.Replace("(Clone)", "") + "bonenames", typeof(object));
                                if (boneNameRequest != null)
                                {
                                    las.Insert(0, boneNameRequest);
                                }
                            }

                            while (las.Count != 0)
                            {
                                AssetBundleRequest gtABR = las[las.Count - 1];
                                if (gtABR == null)
                                {
                                    break;
                                }
                                if (gtABR.isDone)
                                {
                                    m_BoneNames.Add((object)gtABR.asset);
                                    las.RemoveAt(las.Count - 1);
                                }
                                yield return(null);
                            }
                        }

                        if (CommonValue.PhoneOS == Phone_OS.Ios)
                        {
                            m_AssetBundle.Unload(false);
                        }
                    }
                }
            }
            Messenger.Broadcast(MessangerEventDef.LOAD_ONEASSET_FINISH, MessengerMode.DONT_REQUIRE_LISTENER);
        }