| | |
| | | using UnityEngine; |
| | | using System.IO; |
| | | using LitJson; |
| | | using Cysharp.Threading.Tasks; |
| | | |
| | | |
| | | #if UNITY_EDITOR |
| | | using UnityEditor; |
| | |
| | | |
| | | public class VersionConfig : ScriptableObject |
| | | { |
| | | |
| | | public const string VERSION_ALTERNATIVE = "1.0.0"; |
| | | |
| | | [SerializeField] public string m_AppId = string.Empty; |
| | |
| | | { |
| | | if (string.IsNullOrEmpty(m_GameId)) |
| | | { |
| | | var gameText = Resources.Load<TextAsset>("Game"); |
| | | if (gameText != null) |
| | | { |
| | | m_GameId = gameText.text; |
| | | } |
| | | else |
| | | { |
| | | m_GameId = "xssg"; |
| | | } |
| | | Debug.LogError("VersionConfig gameId is empty, do getasync first"); |
| | | } |
| | | |
| | | return m_GameId; |
| | |
| | | } |
| | | } |
| | | |
| | | static VersionConfig config = null; |
| | | public static VersionConfig Get() |
| | | public static async UniTask<VersionConfig> GetAsync() |
| | | { |
| | | if (config == null) |
| | | { |
| | | if (Application.isEditor) |
| | | { |
| | | config = Resources.Load<VersionConfig>("VersionConfig"); |
| | | config = await Resources.LoadAsync<VersionConfig>("VersionConfig") as VersionConfig; |
| | | //debug登录后第二次启动默认恢复test |
| | | if (LocalSave.GetBool("RestoreTest")) |
| | | { |
| | |
| | | LocalSave.SetBool("RestoreTest", false); |
| | | Debug.Log("appid 恢复test"); |
| | | } |
| | | |
| | | } |
| | | else |
| | | { |
| | | var text = Resources.Load<TextAsset>("VersionConfigEx"); |
| | | if (text != null) |
| | | var textAsset = await Resources.LoadAsync<TextAsset>("VersionConfigEx") as TextAsset; |
| | | if (textAsset != null) |
| | | { |
| | | config = ScriptableObject.CreateInstance<VersionConfig>(); |
| | | var json = JsonMapper.ToObject(text.text); |
| | | var json = JsonMapper.ToObject(textAsset.text); |
| | | ReadJson(json); //逐一解析,不用VersionConfig类结构读取,因为变量定义是按asset的结构定义的 |
| | | } |
| | | else |
| | | { |
| | | Debug.LogError("[VersionConfig] VersionConfigEx not found, falling back to VersionConfig asset"); |
| | | config = await Resources.LoadAsync<VersionConfig>("VersionConfig") as VersionConfig; |
| | | } |
| | | } |
| | | } |
| | | |
| | | if (string.IsNullOrEmpty(config.m_GameId)) |
| | | { |
| | | var gameText = await Resources.LoadAsync<TextAsset>("Game") as TextAsset; |
| | | if (gameText != null) |
| | | { |
| | | config.m_GameId = gameText.text; |
| | | } |
| | | else |
| | | { |
| | | config.m_GameId = "xssg"; |
| | | } |
| | | } |
| | | |
| | | return config; |
| | | } |
| | | |
| | | public static VersionConfig config = null; |
| | | // public static VersionConfig Get() |
| | | // { |
| | | // if (config == null) |
| | | // { |
| | | // if (Application.isEditor) |
| | | // { |
| | | // config = Resources.Load<VersionConfig>("VersionConfig"); |
| | | // //debug登录后第二次启动默认恢复test |
| | | // if (LocalSave.GetBool("RestoreTest")) |
| | | // { |
| | | // config.m_AppId = "test"; |
| | | // LocalSave.SetBool("RestoreTest", false); |
| | | // Debug.Log("appid 恢复test"); |
| | | // } |
| | | |
| | | // } |
| | | // else |
| | | // { |
| | | // var text = Resources.Load<TextAsset>("VersionConfigEx"); |
| | | // if (text != null) |
| | | // { |
| | | // config = ScriptableObject.CreateInstance<VersionConfig>(); |
| | | // var json = JsonMapper.ToObject(text.text); |
| | | // ReadJson(json); //逐一解析,不用VersionConfig类结构读取,因为变量定义是按asset的结构定义的 |
| | | // } |
| | | // } |
| | | // } |
| | | |
| | | // return config; |
| | | // } |
| | | |
| | | public static void ReadJson(JsonData _data) |
| | | { |
| | | try |