public void Init() { if (loadType == LoadType.LocalResource) { var versionAsset = Resources.Load <TextAsset>("DataVersion"); var content = versionAsset.text; gameDataVersion = JsonMapper.ToObject <GameDataVersion>(content); LoadAllDataSet(); } else if (loadType == LoadType.URL) //URL 网络模式暂时只支持json { DownloadVersionFile(); } }
private IEnumerator DownloadVersionFileCoroutine() { var url = URLPath + "DataVersion.json"; var webRequest = UnityWebRequest.Get(url); yield return(webRequest.SendWebRequest()); //异常处理 if (webRequest.isHttpError || webRequest.isNetworkError) { Debug.Log(webRequest.error); } else { var content = webRequest.downloadHandler.text; gameDataVersion = JsonMapper.ToObject <GameDataVersion>(content); LoadAllDataSet(); Debug.Log(webRequest.downloadHandler.text); } }
/// <summary> /// 加载数据版本信息 /// </summary> /// <returns></returns> public static GameDataVersion Load() { var versionAsset = Resources.Load <TextAsset>("DataVersion"); if (versionAsset == null) { var version = new GameDataVersion(); var jsonStr = JsonMapper.ToJson(version); var fullPath = Path.Combine(Config.RESOURCE_FOLDER_PATH, "DataVersion.json"); File.WriteAllText(fullPath, jsonStr); return(version); } else { var content = versionAsset.text; var version = JsonMapper.ToObject <GameDataVersion>(content); Debug.Log("version:" + version.gameDataVersion); return(version); } }