Esempio n. 1
0
        void UnloadAssetBundleInternal(string abName, bool isThorough)
        {
            AssetBundleInfo bundle = GetLoadedAssetBundle(abName);

            if (bundle == null)
            {
                return;
            }

            if (--bundle.m_ReferencedCount <= 0)
            {
                if (m_LoadRequests.ContainsKey(abName))
                {
                    return;     //如果当前AB处于Async Loading过程中,卸载会崩溃,只减去引用计数即可
                }
                bundle.m_AssetBundle.Unload(isThorough);
                m_LoadedAssetBundles.Remove(abName);
                LogManager.Debug(abName + " has been unloaded successfully");
            }
        }
Esempio n. 2
0
        IEnumerator OnExtractResource()
        {
            string dataPath = Util.DataPath;         //数据目录
            string resPath  = Util.AppContentPath(); //游戏包资源目录

            if (Directory.Exists(dataPath))
            {
                Directory.Delete(dataPath, true);
            }
            Directory.CreateDirectory(dataPath);

            string infile  = resPath + "files.txt";
            string outfile = dataPath + "files.txt";

            if (File.Exists(outfile))
            {
                File.Delete(outfile);
            }

            string message = "正在解包文件:>files.txt";

            LogManager.Debug(infile);
            LogManager.Debug(outfile);
            if (Application.platform == RuntimePlatform.Android)
            {
                WWW www = new WWW(infile);
                yield return(www);

                if (www.isDone)
                {
                    File.WriteAllBytes(outfile, www.bytes);
                }
                yield return(0);
            }
            else
            {
                File.Copy(infile, outfile, true);
            }
            yield return(new WaitForEndOfFrame());

            //需要解压的文件名字
            List <string> willExtractFileName = new List <string>();

            //释放所有文件到数据目录
            string[] files = File.ReadAllLines(outfile);

            foreach (var file in files)
            {
                string[] fs = file.Split('|');
                infile  = resPath + fs[0];
                outfile = dataPath + fs[0];
                willExtractFileName.Add(fs[0]);
            }
            if (willExtractFileName.Count > 0)
            {
                facade.SendMessageCommand(NotiConst.EXTRACT_ALL_COUNT, willExtractFileName.Count);
            }

            for (int i = 0, length = willExtractFileName.Count; i < length; i++)
            {
                message = "正在解包文件:>" + willExtractFileName[i];
                LogManager.Debug("正在解包文件:>" + willExtractFileName[i]);
                string from = resPath + willExtractFileName[i];
                string to   = dataPath + willExtractFileName[i];
                facade.SendMessageCommand(NotiConst.EXTRACT_FILE_NAME, willExtractFileName[i]);
                string dir = Path.GetDirectoryName(to);
                if (!Directory.Exists(dir))
                {
                    Directory.CreateDirectory(dir);
                }
                if (Application.platform == RuntimePlatform.Android)
                {
                    //if (!firstExtractResource) facade.SendMessageCommand(NotiConst.EXTRACT_FILE_NAME, willExtractFileName[i]);
                    WWW www = new WWW(from);
                    yield return(www);

                    if (www.isDone)
                    {
                        File.WriteAllBytes(to, www.bytes);
                        facade.SendMessageCommand(NotiConst.EXTRACT_FINISH_ONE, 0);
                    }
                    yield return(0);
                }
                else
                {
                    if (File.Exists(to))
                    {
                        File.Delete(to);
                    }
                    File.Copy(from, to, true);
                    facade.SendMessageCommand(NotiConst.EXTRACT_FINISH_ONE, 0);
                }
                yield return(new WaitForEndOfFrame());
            }

            /*
             * foreach (var file in files) {
             *  string[] fs = file.Split('|');
             *  infile = resPath + fs[0];  //
             *  outfile = dataPath + fs[0];
             *  message = "正在解包文件:>"+ fs[0];
             *  LogManager.Debug("正在解包文件:>"+ infile);
             *  facade.SendMessageCommand(NotiConst.UPDATE_MESSAGE, message);
             *  text.text = message;
             *  string dir = Path.GetDirectoryName(outfile);
             *  if (!Directory.Exists(dir)) Directory.CreateDirectory(dir);
             *
             *  if (Application.platform == RuntimePlatform.Android) {
             *      WWW www = new WWW(infile);
             *      yield return www;
             *
             *      if (www.isDone) {
             *          File.WriteAllBytes(outfile, www.bytes);
             *      }
             *      yield return 0;
             *  } else {
             *      if (File.Exists(outfile)) {
             *          File.Delete(outfile);
             *      }
             *      File.Copy(infile, outfile, true);
             *  }
             *  yield return new WaitForEndOfFrame();
             *  index++;
             *  loadProgress.value = (float)index / files.Length;
             *  progressText.text = Mathf.Round(loadProgress.value * 100).ToString() + "/100";
             * }*/
            message = "解包完成!!!";
            facade.SendMessageCommand(NotiConst.UPDATE_MESSAGE, message);
            yield return(new WaitForSeconds(0.1f));

            message = string.Empty;
            //释放完成,开始启动更新资源
            StartCoroutine(OnUpdateResource());
        }
Esempio n. 3
0
 /// <summary>
 /// 当放回池子里面时
 /// </summary>
 /// <param name="obj"></param>
 void OnPoolPushElement(TestObjectClass obj)
 {
     LogManager.Debug("OnPoolPushElement--->>>" + obj);
 }
Esempio n. 4
0
        /// <summary>
        /// 启动更新下载,这里只是个思路演示,此处可启动线程下载更新
        /// </summary>
        IEnumerator OnUpdateResource()
        {
            if (!AppConst.UpdateMode)
            {
                OnResourceInited();
                yield break;
            }
            string dataPath = Util.DataPath;  //数据目录
            string url      = AppConst.WebUrl;
            string message  = string.Empty;
            string random   = DateTime.Now.ToString("yyyymmddhhmmss");
            string listUrl  = url + "files.txt?v=" + random;

            //string listUrl = url + "files.txt";
            LogManager.Warning("正在检测更新---->>>" + listUrl);
            message = "正在检测更新---->>>" + listUrl;
            facade.SendMessageCommand(NotiConst.CHECK_UPDATE, message);
            WWW www = new WWW(listUrl); yield return(www);

            if (www.error != null)
            {
                OnUpdateFailed(string.Empty);
                yield break;
            }
            if (!Directory.Exists(dataPath))
            {
                Directory.CreateDirectory(dataPath);
            }
            File.WriteAllBytes(dataPath + "files.txt", www.bytes);
            string filesText = www.text;

            string[] files = filesText.Split('\n');

            List <string> willDownLoadUrl         = new List <string>(); //from
            List <string> willDownLoadFileName    = new List <string>();
            List <string> willDownLoadDestination = new List <string>(); //to


            float countLength = 0;

            System.Net.HttpWebRequest request = null;
            System.Net.ServicePointManager.ServerCertificateValidationCallback +=
                delegate(object sender, System.Security.Cryptography.X509Certificates.X509Certificate certificate,
                         System.Security.Cryptography.X509Certificates.X509Chain chain,
                         System.Net.Security.SslPolicyErrors sslPolicyErrors)
            {
                return(true);        // **** Always accept
            };
            for (int i = 0; i < files.Length; i++)
            {
                if (string.IsNullOrEmpty(files[i]))
                {
                    continue;
                }
                string[] keyValue  = files[i].Split('|');
                string   f         = keyValue[0];
                string   localfile = (dataPath + f).Trim();
                string   path      = Path.GetDirectoryName(localfile);
                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }
                string fileUrl = url + f + "?v=" + random;
                //string fileUrl = url + f ;
                bool canUpdate = !File.Exists(localfile);

                if (!canUpdate)
                {
                    string remoteMd5 = keyValue[1].Trim();
                    string localMd5  = Util.md5file(localfile);
                    canUpdate = !remoteMd5.Equals(localMd5);

                    if (canUpdate)
                    {
                        File.Delete(localfile);
                    }
                }
                if (canUpdate)     //本地缺少文件

                //message = "正在检查更新>>" + fileUrl;
                //facade.SendMessageCommand(NotiConst.CHECK_UPDATE, message);

                /*
                 * www = new WWW(fileUrl);
                 * loadProgress.value = www.progress;
                 * progressText.text = Mathf.Round(loadProgress.value * 100).ToString() + "/100";
                 * yield return www;
                 * if (www.error != null) {
                 *  OnUpdateFailed(path);   //
                 *  yield break;
                 * }
                 * File.WriteAllBytes(localfile, www.bytes);
                 */
                //这里都是资源文件,用线程下载
                //BeginDownload(fileUrl, localfile);
                //while (!(IsDownOK(localfile))) { yield return new WaitForEndOfFrame(); }

                {
                    willDownLoadUrl.Add(fileUrl);           //下载地址
                    willDownLoadFileName.Add(keyValue[0]);
                    willDownLoadDestination.Add(localfile); //目标文件路径

                    //计算文件大小
                    request = (System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create(fileUrl);
                    request.UseDefaultCredentials = true;
                    request.Method = "HEAD";
                    countLength   += request.GetResponse().ContentLength;
                }
            }

            //System.Net.HttpWebRequest request=null;
            ////计算文件大小
            //for (int i = 0; i < willDownLoadUrl.Count; i++)
            //{
            //    request = (System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create(willDownLoadUrl[i]);
            //    request.UseDefaultCredentials = true;
            //    request.Method = "HEAD";
            //    countLength += request.GetResponse().ContentLength;
            //    //UnityWebRequest uwr = UnityWebRequest.Head(willDownLoadUrl[i]);
            //    //yield return uwr.Send();
            //    //string size = uwr.GetResponseHeader("Content-Length");
            //    //if (!string.IsNullOrEmpty(size)) //{ OnUpdateFailed(null); yield break; }
            //    //    countLength += float.Parse(size);
            //}

            string value = string.Format("{0}", Math.Round(countLength / 1024, 2));

            facade.SendMessageCommand(NotiConst.UPDATE_ALL_COUNTLENGTH, value);
            if (willDownLoadUrl.Count > 0)
            {
                facade.SendMessageCommand(NotiConst.UPDATE_ALL_COUNT, willDownLoadUrl.Count);
            }
            for (int i = 0; i < willDownLoadUrl.Count; i++)
            {
                LogManager.Debug("要下载的文件:" + willDownLoadUrl[i]);
                //这里都是资源文件,用线程下载
                facade.SendMessageCommand(NotiConst.UPDATE_FILE_NAME, willDownLoadFileName[i]);
                BeginDownload(willDownLoadUrl[i], willDownLoadDestination[i]);
                while (!(IsDownOK(willDownLoadDestination[i])))
                {
                    yield return(new WaitForEndOfFrame());
                }
            }

            yield return(new WaitForEndOfFrame());

            //yield return new WaitForSeconds(0.1f);
            message = "更新完成!";
            facade.SendMessageCommand(NotiConst.CHECK_UPDATE, message);
            OnResourceInited();
        }
Esempio n. 5
0
 /// <summary>
 /// 析构函数
 /// </summary>
 new void OnDestroy()
 {
     SocketClient.OnRemove();
     LogManager.Debug("~NetworkManager was destroy");
 }
Esempio n. 6
0
 public static void Log(string str)
 {
     LogManager.Debug(str);
 }