Exemplo n.º 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);
 }
Exemplo n.º 2
0
        /// <summary>
        /// 卸载所有资源;
        /// </summary>
        public void ReleaseAllAsset()
        {
            List <string> delAsset = new List <string>();

            foreach (KeyValuePair <string, AssetPack> kvp in m_AllAssets)
            {
                if (!kvp.Value.m_IsResident)                //fufeng ni lao na yang?
                {
                    delAsset.Add(kvp.Key);
                }
            }

            foreach (string assetName in delAsset)
            {
                ReleaseDownLoadCoroutine(assetName);                                 //立即停止Coroutine;
                WWWDownLoader.StopLoad(assetName + m_strAssetExtension);
                WWWDownLoader.RemoveDownLoad(assetName + m_strAssetExtension, null); //AssetLoader内部的 www调用逻辑上来说没有回调.函数内部有非空判断;

                AssetPack assetPack = m_AllAssets[assetName];
                m_AllAssets.Remove(assetName);

                assetPack.m_AssetRefer--;
                assetPack.AssetRelease = true;

                if (assetPack.m_AssetRefer > 0)
                {
                    Debug.LogError("release asset still used: " + assetPack.m_AssetName);
                }

                assetPack = null;
            }

            delAsset.Clear();
        }
Exemplo n.º 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);
        }
Exemplo n.º 4
0
        public void Release()
        {
            m_RefNum -= 1;
            if (m_RefNum == 0)
            {
                m_mapRoleBodyLoader.Remove(ResuceName);

                WWWDownLoader.StopLoad(ResuceName);
                WWWDownLoader.RemoveDownLoad(ResuceName, null);

                _Release();
            }
        }
Exemplo n.º 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);
        }
Exemplo n.º 6
0
        public static void ReleaseAllModel()
        {
            foreach (ModelLoader loader in cacheLoaders.Values)
            {
                WWWDownLoader.StopLoad(loader.mResName);
                WWWDownLoader.RemoveDownLoad(loader.mResName, null);

                loader.modelPrefab = null;
                loader.request     = null;
                if (loader.bundle != null)
                {
                    loader.bundle.Unload(true);
                    loader.bundle = null;
                }
            }
            cacheLoaders.Clear();
        }
Exemplo n.º 7
0
        /// <summary>
        /// 卸载资源;
        /// </summary>
        public void ReleaseAsset(string assetName, Callback <string> callBack, bool isKeepLoading)
        {
            if (m_AllAssets.ContainsKey(assetName))
            {
                AssetPack assetPack = m_AllAssets[assetName];
                if (assetPack != null)
                {
                    if (assetPack.m_CallBack != null)
                    {
                        assetPack.m_CallBack -= callBack;
                    }
                    if (!assetPack.m_IsResident)
                    {
                        assetPack.m_AssetRefer--;

                        if (isKeepLoading)
                        {
                            if (assetPack.State != AssetState.DownLoading && assetPack.State != AssetState.LocalLoading)                            //KeepLoading的任务, 只有在加载完成后,才能进行卸载;
                            {
                                assetPack.m_nKeepLoadingRefer--;
                            }
                        }
                        if (assetPack.m_AssetRefer <= 0 && assetPack.m_nKeepLoadingRefer <= 0)                        //非常驻资源,没有外部使用,并且下载完成的情况下;
                        {
                            assetPack.m_CallBack = null;
                            WWWDownLoader.StopLoad(assetName + m_strAssetExtension);
                            WWWDownLoader.RemoveDownLoad(assetName + m_strAssetExtension, null); //AssetLoader内部的 www调用逻辑上来说没有回调.函数内部有非空判断;

                            ReleaseDownLoadCoroutine(assetName);                                 //立即停止Coroutine;
                            assetPack.AssetRelease = true;
                            m_AllAssets.Remove(assetName);
                        }
                    }
                }
                else
                {
                    Debug.LogError("AssetLoader ReleaseAsset,AssetPack can not be null. " + assetName);
                }
            }
        }
Exemplo n.º 8
0
        public void Release()
        {
            m_RefNum -= 1;

            if (m_RefNum == 0)
            {
                cacheLoaders.Remove(mResName);

                WWWDownLoader.StopLoad(mResName);
                WWWDownLoader.RemoveDownLoad(mResName, null);

                modelPrefab = null;
                request     = null;
                if (bundle != null)
                {
                    bundle.Unload(true);
                    bundle = null;
                }

                m_www = null;
            }
        }
Exemplo n.º 9
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);
            }
        }
Exemplo n.º 10
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);
        }
Exemplo n.º 11
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);
        }