void Start() { var img = GetComponent <RawImage>(); var uri = Path.Combine(Application.streamingAssetsPath, path); var bytes = SDKAdapter.GetInstance().LoadAsset(uri); if (bytes != null) { var tex = new Texture2D(2, 2, TextureFormat.RGB24, false); tex.LoadImage(bytes); img.texture = tex; img.SetNativeSize(); } }
void Start() { if (GameUtil.mainGame != null) { return; } GameUtil.mainGame = s_Instance; Screen.sleepTimeout = SleepTimeout.NeverSleep; Application.targetFrameRate = AppConst.GameFrameRate; SDKAdapter.GetInstance().SetTDEvent("launch_game"); DOTween.Init(true, true).SetCapacity(200, 50); AddManager(); StartApp(); }
public IEnumerator LoadSettingFile() { string path = AppConst.SettingPath; LogUtil.StartLog("Load Setting File...\n" + path); string pContent; if (path.Contains("://")) { MutiLoader loader = new MutiLoader(3); yield return(loader.StartLoadText(path)); pContent = loader.text; } else { try { pContent = File.ReadAllText(path); } catch (Exception e) { LogUtil.LogExInfo("Failed To Load Setting Xml: " + path + "\n", e); yield break; } } if (string.IsNullOrEmpty(pContent)) { yield break; } LogUtil.StartLog("Read Setting File..." + pContent); ParseSetting(pContent); SDKAdapter.GetInstance().SetTDEvent("load_config"); Finish(); }
private IEnumerator CheckVersion() { UpdateTips("正在检查游戏版本", 1); string localVerPath = AppConst.CachePath + AppConst.VerionName; if (File.Exists(localVerPath)) { DecodeVersionFile(File.ReadAllText(localVerPath), localVersion, localSize); } else if (!Directory.Exists(AppConst.CachePath)) { Directory.CreateDirectory(AppConst.CachePath); } string assetVerPath = AppConst.AssetsPath + AppConst.VerionName; DecodeVersionFile(SDKAdapter.GetInstance().LoadAssetText(assetVerPath), assetsVersion, assetsSize); //load remote version file string remoteVerPath = AppConst.AssetBundleURI + AppConst.VerionName + "?r=" + Util.GetTime(); LogUtil.StartLog("Check Game Version: " + remoteVerPath); string remoteVerContent = null; UnityWebRequest request = UnityWebRequest.Get(remoteVerPath); yield return(request.SendWebRequest()); if (request.isNetworkError || request.isHttpError) { UpdateTips("检查游戏版本失败:" + request.error, 0); LogUtil.StartLog("Failed To Load Version File: " + remoteVerPath + "\n" + request.error); request.Dispose(); // 3秒后重新开始检查 yield return(new WaitForSeconds(3f)); ReLoad(); yield break; } remoteVerContent = request.downloadHandler.text; request.Dispose(); //read remote version file Dictionary <string, string> remoteVersion = new Dictionary <string, string>(); Dictionary <string, ulong> remoteSize = new Dictionary <string, ulong>(); DecodeVersionFile(remoteVerContent, remoteVersion, remoteSize); //compare version List <string> updatefiles = new List <string>(); CompareVersionFile(localVersion, assetsVersion, remoteVersion, updatefiles); //don't need to update if (updatefiles.Count == 0) { yield break; } //update the file ulong totalBytes = 0; for (int i = 0; i < updatefiles.Count; i++) { string abname = updatefiles[i]; totalBytes += remoteSize[abname]; } Util.Log("Total Download Bytes: " + totalBytes / 1024 + " KB..."); ulong downloadBytes = 0; for (int i = 0; i < updatefiles.Count; i++) { string fileURL = AppConst.AssetBundleURI + updatefiles[i] + "?r=" + Util.GetTime(); Util.Log("Update file: " + fileURL); UnityWebRequest www = UnityWebRequest.Get(fileURL); AsyncOperation op = www.SendWebRequest(); while (true) { ulong bytes = downloadBytes + www.downloadedBytes; float progress = (float)bytes / totalBytes; UpdateTips("正在更新文件", progress); if (op.isDone) { break; } yield return(null); } if (www.isNetworkError || www.isHttpError) { UpdateTips("更新文件失败: " + updatefiles[i], 0); Util.Log("Failed to load '" + fileURL + "', update stop.\n" + www.error); yield break; } downloadBytes += www.downloadedBytes; string filePath = AppConst.CachePath + updatefiles[i]; File.WriteAllBytes(filePath, www.downloadHandler.data); } //update local version file File.WriteAllText(localVerPath, remoteVerContent); }