| using System.Collections; | 
| using System.Collections.Generic; | 
| using UnityEngine; | 
| using System.IO; | 
| using LitJson; | 
|   | 
| #if UNITY_EDITOR | 
| using UnityEditor; | 
| #endif | 
|   | 
| [CreateAssetMenu(menuName = "Config/VersionConfig")] | 
|   | 
| public class VersionConfig : ScriptableObject | 
| { | 
|     public const string VERSION_ALTERNATIVE = "1.0.0"; | 
|   | 
|     [SerializeField] public string m_AppId = string.Empty; | 
|     public string appId | 
|     { | 
|         get | 
|         { | 
|             if (!string.IsNullOrEmpty(SDKUtils.Yj_AppID)) | 
|             { | 
|                 return SDKUtils.Yj_AppID; | 
|             } | 
|             return m_AppId; | 
|         } | 
|     } | 
|   | 
|     [SerializeField] public string m_SpID = string.Empty; | 
|     public string SpID | 
|     { | 
|         get | 
|         { | 
|             if (!string.IsNullOrEmpty(SDKUtils.Yj_SpID)) | 
|             { | 
|                 return SDKUtils.Yj_SpID; | 
|             } | 
|             return m_SpID; | 
|         } | 
|     } | 
|   | 
|     [SerializeField] VersionAuthority m_VersionAuthority; | 
|     public VersionAuthority versionAuthority { get { return m_VersionAuthority; } } | 
|   | 
|     [SerializeField] public string m_Version; | 
|     public string version { get { return VersionCompare(m_Version, VERSION_ALTERNATIVE); } } | 
|   | 
|     [SerializeField] string m_ClientPackageFlag; | 
|     public string clientPackageFlag { get { return m_ClientPackageFlag; } } | 
|   | 
|     [SerializeField] int m_Branch = 0; | 
|     public int branch | 
|     { | 
|         get | 
|         { | 
|             if (DebugUtility.Instance.debugBranch >= 0) | 
|             { | 
|                 return DebugUtility.Instance.debugBranch; | 
|             } | 
|             else | 
|             { | 
|                 return m_Branch; | 
|             } | 
|         } | 
|     } | 
|   | 
|     string m_GameId = string.Empty; | 
|     public string gameId | 
|     { | 
|         get | 
|         { | 
|             if (string.IsNullOrEmpty(m_GameId)) | 
|             { | 
|                 var gameText = Resources.Load<TextAsset>("Game"); | 
|                 if (gameText != null) | 
|                 { | 
|                     m_GameId = gameText.text; | 
|                 } | 
|                 else | 
|                 { | 
|                     m_GameId = "xbqy"; | 
|                 } | 
|             } | 
|   | 
|             return m_GameId; | 
|         } | 
|     } | 
|   | 
|     [SerializeField] InstalledAsset m_AssetAccess = InstalledAsset.IngoreDownLoad; | 
|     public InstalledAsset assetAccess { get { return m_AssetAccess; } set { m_AssetAccess = value; } } | 
|   | 
|     [SerializeField] bool m_PartAssetPackage = false; | 
|     public bool partAssetPackage { get { return m_PartAssetPackage; } set { m_PartAssetPackage = value; } } | 
|   | 
|     [SerializeField] string m_ProductName = string.Empty; | 
|     public string productName { get { return m_ProductName; } } | 
|   | 
|     [SerializeField] string m_BundleIdentifier = string.Empty; | 
|     public string bundleIdentifier { get { return m_BundleIdentifier; } } | 
|   | 
|     [SerializeField] string m_KeystoreFileName; | 
|     public string keystoreFileName { get { return m_KeystoreFileName; } } | 
|   | 
|     [SerializeField] string m_KeystorePassword; | 
|     public string keystorePassword { get { return m_KeystorePassword; } } | 
|   | 
|     [SerializeField] string m_KeystoreAlias; | 
|     public string keystoreAlias { get { return m_KeystoreAlias; } } | 
|   | 
|     [SerializeField] string m_KeystoreAliasPassword; | 
|     public string keystoreAliasPassword { get { return m_KeystoreAliasPassword; } } | 
|   | 
|     [SerializeField] string m_AppleDeveloperTeamID; | 
|     public string appleDeveloperTeamID { get { return m_AppleDeveloperTeamID; } } | 
|   | 
|     [SerializeField] bool m_DebugVersion = false; | 
|     public bool debugVersion | 
|     { | 
|         get { return m_DebugVersion; } | 
|         set { m_DebugVersion = value; } | 
|     } | 
|   | 
|     [SerializeField] bool m_IsBanShu = false; | 
|     public bool isBanShu | 
|     { | 
|         get { return m_IsBanShu; } | 
|         set { m_IsBanShu = value; } | 
|     } | 
|   | 
|     [SerializeField] string m_BuildTime; | 
|     public string buildTime | 
|     { | 
|         get { return m_BuildTime; } | 
|         set { m_BuildTime = value; } | 
|     } | 
|   | 
|     [SerializeField] int m_BuildIndex; | 
|     public int buildIndex | 
|     { | 
|         get { return m_BuildIndex; } | 
|         set { m_BuildIndex = value; } | 
|     } | 
|   | 
|     [SerializeField] Vector2 m_LogoPosition; | 
|     public Vector2 logoPosition { get { return m_LogoPosition; } } | 
|   | 
|     [SerializeField] string m_BanHao; | 
|     public string banHao | 
|     { | 
|         get | 
|         { | 
|             if (!string.IsNullOrEmpty(SDKUtils.Yj_BanHao)) | 
|             { | 
|                 return SDKUtils.Yj_BanHao; | 
|             } | 
|             return m_BanHao; | 
|         } | 
|     } | 
|   | 
|     // 打包时sdk文件名,有配置取这个名字,没配置用appid,用于同一个appid版本sdk不同的情况 | 
|     // 打包读取的logo目录不同,安卓有两个sdk | 
|     [SerializeField] string m_SdkFileName; | 
|     public string sdkFileName | 
|     { | 
|         get { return m_SdkFileName; } | 
|         set { m_SdkFileName = value; } | 
|     } | 
|   | 
|     public void Read(string _data) | 
|     { | 
|         var dataStrings = _data.Split('\t'); | 
|         try | 
|         { | 
|             m_AppId = dataStrings[2]; | 
|             m_VersionAuthority = (VersionAuthority)int.Parse(dataStrings[3]); | 
|             m_Version = dataStrings[4]; | 
|             m_ClientPackageFlag = dataStrings[5]; | 
|             m_Branch = int.Parse(dataStrings[6]); | 
|             m_AssetAccess = (InstalledAsset)int.Parse(dataStrings[8]); | 
|             m_PartAssetPackage = int.Parse(dataStrings[9]) == 1; | 
|             m_ProductName = dataStrings[10]; | 
|             m_BundleIdentifier = dataStrings[11]; | 
|             m_KeystoreFileName = dataStrings[12]; | 
|             m_KeystorePassword = dataStrings[13]; | 
|             m_KeystoreAlias = dataStrings[14]; | 
|             m_KeystoreAliasPassword = dataStrings[15]; | 
|             m_AppleDeveloperTeamID = dataStrings[16]; | 
|             m_DebugVersion = int.Parse(dataStrings[17]) == 1; | 
|             m_IsBanShu = int.Parse(dataStrings[18]) == 1; | 
|             m_LogoPosition = dataStrings[19].Vector3Parse(); | 
|             m_BanHao = dataStrings[20]; | 
|             m_SpID = dataStrings[21]; | 
|             m_SdkFileName = dataStrings[24]; | 
|         } | 
|         catch (System.Exception ex) | 
|         { | 
|             Debug.Log(ex); | 
|         } | 
|     } | 
|   | 
|     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 | 
|         { | 
|             config.m_AppId = _data["m_AppId"].ToString(); | 
|             config.m_VersionAuthority = (VersionAuthority)int.Parse(_data["m_VersionAuthority"].ToString()); | 
|             config.m_Version = _data["m_Version"].ToString(); | 
|             config.m_ClientPackageFlag = _data["m_ClientPackageFlag"].ToString(); | 
|             config.m_Branch = int.Parse(_data["m_Branch"].ToString()); | 
|             config.m_AssetAccess = (InstalledAsset)int.Parse(_data["m_AssetAccess"].ToString()); | 
|             config.m_PartAssetPackage = (bool)_data["m_PartAssetPackage"]; | 
|             config.m_ProductName = _data["m_ProductName"].ToString(); | 
|             config.m_BundleIdentifier = _data["m_BundleIdentifier"].ToString(); | 
|             config.m_KeystoreFileName = _data["m_KeystoreFileName"].ToString(); | 
|             config.m_KeystorePassword = _data["m_KeystorePassword"].ToString(); | 
|             config.m_KeystoreAlias = _data["m_KeystoreAlias"].ToString(); | 
|             config.m_KeystoreAliasPassword = _data["m_KeystoreAliasPassword"].ToString(); | 
|             config.m_AppleDeveloperTeamID = _data["m_AppleDeveloperTeamID"].ToString(); | 
|             config.m_DebugVersion = (bool)_data["m_DebugVersion"]; | 
|             config.m_IsBanShu = (bool)_data["m_IsBanShu"]; | 
|             config.m_LogoPosition = JsonMapper.ToObject<Vector2>(_data["m_LogoPosition"].ToJson()); | 
|             config.m_BanHao = _data["m_BanHao"].ToString(); | 
|             config.m_SpID = _data["m_SpID"].ToString(); | 
|             config.m_BuildIndex = int.Parse(_data["m_BuildIndex"].ToString()); | 
|             config.m_BuildTime = _data["m_BuildTime"].ToString(); | 
|             config.m_SdkFileName = _data["m_SdkFileName"].ToString(); | 
|   | 
|             Debug.Log("VersionConfig ReadJson Success"); | 
|         } | 
|         catch (System.Exception ex) | 
|         { | 
|             Debug.Log(ex); | 
|         } | 
|     } | 
|   | 
|     public static void Copy(VersionConfig _from, VersionConfig _to) | 
|     { | 
|         _to.m_VersionAuthority = _from.m_VersionAuthority; | 
|         _to.m_Version = _from.m_Version; | 
|         _to.m_AppId = _from.m_AppId; | 
|         _to.m_Branch = _from.m_Branch; | 
|         _to.m_AssetAccess = _from.m_AssetAccess; | 
|         _to.m_PartAssetPackage = _from.m_PartAssetPackage; | 
|         _to.m_BuildTime = _from.m_BuildTime; | 
|         _to.m_DebugVersion = _from.m_DebugVersion; | 
|         _to.m_ProductName = _from.m_ProductName; | 
|         _to.m_BundleIdentifier = _from.m_BundleIdentifier; | 
|         _to.m_KeystoreFileName = _from.m_KeystoreFileName; | 
|         _to.m_KeystoreAlias = _from.m_KeystoreAlias; | 
|         _to.m_KeystorePassword = _from.m_KeystorePassword; | 
|         _to.m_KeystoreAliasPassword = _from.m_KeystoreAliasPassword; | 
|         _to.m_AppleDeveloperTeamID = _from.m_AppleDeveloperTeamID; | 
|         _to.m_IsBanShu = _from.m_IsBanShu; | 
|         _to.m_ClientPackageFlag = _from.m_ClientPackageFlag; | 
|         _to.m_LogoPosition = _from.m_LogoPosition; | 
|         _to.m_BanHao = _from.m_BanHao; | 
|         _to.m_SpID = _from.m_SpID; | 
|         _to.m_SdkFileName = _from.m_SdkFileName; | 
|     } | 
|   | 
|     /// <summary> | 
|     /// 比较两个版本,返回更大的那个 | 
|     /// </summary> | 
|     /// <param name="_lhs"></param> | 
|     /// <param name="_rhs"></param> | 
|     /// <returns></returns> | 
|     static string VersionCompare(string _lhs, string _rhs) | 
|     { | 
|         var lhsStrings = _lhs.Split('.'); | 
|         var rhsStrings = _rhs.Split('.'); | 
|   | 
|         if (lhsStrings.Length > rhsStrings.Length) | 
|         { | 
|             return _lhs; | 
|         } | 
|         else if (lhsStrings.Length < rhsStrings.Length) | 
|         { | 
|             return _rhs; | 
|         } | 
|         else | 
|         { | 
|             var version1 = 0; | 
|             for (int i = 0; i < lhsStrings.Length; i++) | 
|             { | 
|                 var input = lhsStrings[i]; | 
|                 var intTemp = 0; | 
|                 int.TryParse(input, out intTemp); | 
|                 version1 += intTemp * MathUtility.Power(1000, lhsStrings.Length - 1 - i); | 
|             } | 
|   | 
|             var version2 = 0; | 
|             for (int i = 0; i < rhsStrings.Length; i++) | 
|             { | 
|                 var input = rhsStrings[i]; | 
|                 var intTemp = 0; | 
|                 int.TryParse(input, out intTemp); | 
|                 version2 += intTemp * MathUtility.Power(1000, rhsStrings.Length - 1 - i); | 
|             } | 
|   | 
|             return version1 > version2 ? _lhs : _rhs; | 
|         } | 
|     } | 
|   | 
|     public static int GetVersionNumber(string version) | 
|     { | 
|         var numberStrings = version.Split('.'); | 
|         var number = 0; | 
|   | 
|         for (var i = 0; i < Mathf.Min(numberStrings.Length, 3); i++) | 
|         { | 
|             var temp = 0; | 
|             int.TryParse(numberStrings[i], out temp); | 
|             number += temp * MathUtility.Power(1000, 2 - i); | 
|         } | 
|   | 
|         return number; | 
|     } | 
|   | 
| } |