// Start is called before the first frame update void Start() { m_localJsonPath = Application.dataPath + "/Resources/ServerInfo.json"; Debug.Log("m_localJsonPath :" + m_localJsonPath); StreamReader sr = new StreamReader(m_localJsonPath); var content = sr.ReadToEnd(); m_localInfoDataModule = new ServerInfoDataModule(JsonMapper.ToObject(content)); sr.Close(); // 将重新排序的数组重新赋值给datamodule, 且排序时应该是对int类型就行排序,否则执行的是字符串的默认排序 m_localInfoDataModule.GameVersionInfos[0].Branches[0].Patches = m_localInfoDataModule.GameVersionInfos[0].Branches[0].Patches.OrderBy(i => int.Parse(i.Version)).ToList(); foreach (var item in m_localInfoDataModule.GameVersionInfos[0].Branches[0].Patches) { Debug.Log("Item :" + item.Version); } }
/// <summary> /// 从服务器端读取Server.json数据 /// </summary> /// <param name="jsonUrl"></param> /// <param name="callBack"></param> /// <returns></returns> private IEnumerator ReadServerInfoJson(string jsonUrl, Action callBack) { Debug.Log("ReadServerInfoJson :" + jsonUrl); UnityWebRequest webRequest = UnityWebRequest.Get(jsonUrl); yield return(webRequest.SendWebRequest()); if (webRequest.isNetworkError) { Debug.Log("Download Error :" + webRequest.error); } else { yield return(Utils.Core.FileUtil.Instance.CreateFile(m_serverJsonPath, webRequest.downloadHandler.data, null)); yield return(new WaitForEndOfFrame()); if (File.Exists(m_serverJsonPath)) { StreamReader sr = new StreamReader(m_serverJsonPath); var content = sr.ReadToEnd(); m_serverInfoDataModule = new ServerInfoDataModule(JsonMapper.ToObject(content)); sr.Close(); } else { Debug.LogError("热更配置读取错误!"); } } yield return(WaitProgressAdd(0.02f)); if (null != callBack) { callBack.Invoke(); } }