private IEnumerator HandleGameLoading() { // fire ge_loading_start event handled by ui module, display splash screen & change to loading state LogicSystem.BeginLoading(); yield return(new WaitForSeconds(.1f)); // if in shipping version, update resource from server if (GlobalVariables.Instance.IsPublish) { yield return(StartCoroutine(HandleGameLoadingPublish())); } #if UNITY_ANDROID || UNITY_WEBGL // if not play game in editor, extract config data to disk else if (!UnityEngine.Application.isEditor) { string destPath = UnityEngine.Application.persistentDataPath + "/Tables"; if (!Directory.Exists(destPath)) { yield return(StartCoroutine(HandleGameLoadingNonEditor())); } } #endif LogicSystem.UpdateLoadingProgress(0.45f); // init all game system and start game StartLogic(); // fire ge_loading_finish event handled by ui module, notify ui finished LogicSystem.EndLoading(); }
private IEnumerator HandleGameLoadingNonEditor() { LogicSystem.UpdateLoadingTip("加载配置数据"); string srcPath = UnityEngine.Application.streamingAssetsPath; string destPath = UnityEngine.Application.persistentDataPath + "/Tables"; Debug.Log(srcPath); Debug.Log(destPath); if (!srcPath.Contains("://")) { srcPath = "file://" + srcPath; } string listPath = srcPath + "/list.txt"; WWW listData = new WWW(listPath); yield return(listData); string listTxt = listData.text; if (null != listTxt) { using (StringReader sr = new StringReader(listTxt)) { string numStr = sr.ReadLine(); float totalNum = 50; if (null != numStr) { numStr = numStr.Trim(); if (numStr.StartsWith(BOMMarkUtf8)) { numStr = numStr.Remove(0, BOMMarkUtf8.Length); } totalNum = (float)int.Parse(numStr); if (totalNum <= 0) { totalNum = 50; } } for (float num = 1; ; num += 1) { string path = sr.ReadLine(); if (null != path) { path = path.Trim(); string url = srcPath + "/" + path; //Debug.Log("extract " + url); string filePath = Path.Combine(destPath, path); string dir = Path.GetDirectoryName(filePath); if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } WWW temp = new WWW(url); yield return(temp); if (null != temp.bytes) { try { #if LoadDataTableFromCache byte[] newAlloced = new byte[temp.bytes.Length]; temp.bytes.CopyTo(newAlloced, 0); CachedTables.Add(Path.GetFullPath(filePath).ToLower(), newAlloced); #else File.WriteAllBytes(filePath, temp.bytes); #endif } catch (System.Exception ex) { LogicSystem.LogErrorFromGfx("ExtractDataFileAndStartGame copy config failed. ex:{0} st:{1}", ex.Message, ex.StackTrace); } } else { //Debug.Log(path + " can't load"); } temp.Dispose(); temp = null; } else { break; } LogicSystem.UpdateLoadingProgress(0.8f + 0.2f * num / totalNum); } sr.Close(); } listData = null; } else { Debug.Log("Can't load list.txt"); } }