少年修仙传客户端代码仓库
lcy
2024-12-16 a39c35fc6449430cd02bccb681c4a0a880e46cd9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
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(ynmbxxjUtil.Yj_AppID))
            {
                return ynmbxxjUtil.Yj_AppID;
            }
            return m_AppId;
        }
    }
 
    [SerializeField] public string m_SpID = string.Empty;
    public string SpID
    {
        get
        {
            if (!string.IsNullOrEmpty(ynmbxxjUtil.Yj_SpID))
            {
                return ynmbxxjUtil.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(ynmbxxjUtil.Yj_BanHao))
            {
                return ynmbxxjUtil.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)
        {
            DebugEx.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)
        {
            DebugEx.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;
    }
 
}