From 2769f4c6422de2d85436b38ee7f5ad92236ed0cf Mon Sep 17 00:00:00 2001
From: yyl <yyl>
Date: 星期一, 19 五月 2025 17:42:07 +0800
Subject: [PATCH] 18 子 2D卡牌客户端搭建 / 2D卡牌客户端搭建

---
 Assets/Launch/Manager/LocalResManager.cs | 1028 +++++++++++++++++++++++++++------------------------------
 1 files changed, 487 insertions(+), 541 deletions(-)

diff --git a/Assets/Launch/Manager/ResManager.cs b/Assets/Launch/Manager/LocalResManager.cs
similarity index 88%
rename from Assets/Launch/Manager/ResManager.cs
rename to Assets/Launch/Manager/LocalResManager.cs
index ae51d2c..5fa4bc7 100644
--- a/Assets/Launch/Manager/ResManager.cs
+++ b/Assets/Launch/Manager/LocalResManager.cs
@@ -1,542 +1,488 @@
-using UnityEngine;
-using System.Collections;
-using System.Collections.Generic;
-using Cysharp.Threading.Tasks;
-using System;
-using UnityEngine.U2D;
-using LitJson;
-using System.IO;
-using UnityEngine.Networking;
-
-#if UNITY_EDITOR
-using UnityEditor;
-#endif
-
-using LaunchCommon;
-
-public class ResManager : Singleton<ResManager>
-{
-    
-
-    //涓嶄笅杞芥椂鏈湴瀹夊崜娴嬭瘯璺緞
-    public string assetBundlesPath = Application.dataPath + "/../AssetBundles/Android/";
-    public static string bytesFolderName = "logicbytes/";
-    public string StreamingAssetPath
-    {
-        get
-        {
-            return ResourcesPath.Instance.StreamingAssetPath;
-        }
-    }
-    public string ExternalStorePath 
-    {
-        get
-        {
-            return ResourcesPath.Instance.ExternalStorePath;
-        }
-    }
-
-    //鐢ㄤ簬editor 涓嬬殑璧勬簮璺緞
-    public string ResourcesOutPath 
-    {
-        get
-        {
-            return ResourcesPath.ResourcesOutPath;
-        }
-    }
-
-    public string CONFIG_FODLER
-    {
-        get
-        {
-            return ResourcesPath.CONFIG_FODLER;
-        }
-    }
-
-    public string ResourcesOutAssetPath
-    {
-        get
-        {
-            return ResourcesPath.ResourcesOutAssetPath;
-        }
-    }
-
-    public bool isPCTestDownLoad = false;
-
-    public static readonly string[] VERSION_URL = new string[] {
-        "http://gamecenter.secondworld.net.cn:11000/center/appversion_new.php/?"};
-
-    public int debugBranch { get; private set; }
-
-    private int urlIndex = 0;
-
-    private string versionUrl;
-
-    public VersionInfo versionInfo { get; private set; }
-
-    private static LoadDllStep m_step;
-
-    public static LoadDllStep step
-    {
-        get { return m_step; }
-        set
-        {
-            m_step = value;
-            Debug.Log("LoadDllStep:" + m_step);
-        }
-    }
-
-    string assetBytesUrl;
-
-    //浠庣綉缁滆幏鍙栫殑璧勬簮鐗堟湰淇℃伅
-    public Dictionary<string, AssetVersion> assetVersions = new Dictionary<string, AssetVersion>();
-
-    //鏈湴LogicBytes鏂囦欢鍜� assetVersions 姣旇緝鏄惁闇�瑕佷笅杞�
-    public Dictionary<string, AssetVersion> localAssetVersions = new Dictionary<string, AssetVersion>();
-
-    public static string versionUrlResult { get; private set; }
-
-    /// <summary>
-    /// 璇█鐨処D锛岀敤浜庡尯鍒嗕笅杞借祫婧�
-    /// </summary>
-    /// <value></value>
-    public static string Id
-    {
-        get
-        {
-            var config = InitialFunctionConfig.Get("Language").Numerical1;
-            if (string.IsNullOrEmpty(config))
-                return "";
-            return LocalSave.GetString("LANGUAGE_ID1");
-        }
-        set
-        {
-            LocalSave.SetString("LANGUAGE_ID1", value);
-        }
-    }
-
-    //榛樿璺緞涓嶉檮鍔犲湴鍧�锛孖d涓嶄负绌烘椂闄勫姞Id
-    public static string fixPath
-    {
-        get
-        {
-            if (string.IsNullOrEmpty(Id))
-                return "";
-            return string.Format("/{0}", Id);
-        }
-    }
-
-    private AssetBundle spriteBundle = null;   //闇�瑕佸嵏杞�
-    private AssetBundle prefabBundle = null;   //闇�瑕佸嵏杞�
-    private SpriteAtlas spriteAtlas = null;
-
-    public void Init()
-    {
-        if (LocalSave.GetString("#@#BrancH") != string.Empty)
-        {
-            int tmpbranch;
-            int.TryParse(LocalSave.GetString("#@#BrancH").Substring(1), out tmpbranch);
-            if (tmpbranch != 0)
-                debugBranch = tmpbranch;
-        }
-
-        var parentDirectory = Directory.GetParent(Application.persistentDataPath);
-        if (File.Exists(parentDirectory + "/Debug"))
-        {
-            var content = File.ReadAllText(parentDirectory + "/Debug");
-            if (!string.IsNullOrEmpty(content))
-            {
-                var json = JsonMapper.ToObject<DebugBranch>(File.ReadAllText(parentDirectory + "/Debug"));
-                debugBranch = json.branch;
-            }
-        }
-
-        Clock.Init();
-        Debug.Log("ResManager.Init");
-    }
-
-    public void Release()
-    {
-        spriteBundle?.Unload(true);  //true瀹屽叏鍗歌浇锛屾洿鏂板悗閲嶆柊鍔犺浇
-        prefabBundle?.Unload(true);
-        assetVersions = null;
-        localAssetVersions = null;
-        spriteAtlas = null;
-        Debug.Log("鎻愬墠ResManager.Release璧勬簮");
-    }
-
-    public void RequestVersionCheck()
-    {
-        var versionConfig = VersionConfigEx.Get();
-        var tables = new Dictionary<string, string>();
-        tables["channel"] = versionConfig.appId;
-        tables["versioncode"] = versionConfig.version;
-        if (versionConfig.branch != 0)
-        {
-            tables["branch"] = versionConfig.branch.ToString();
-        }
-
-        tables["game"] = versionConfig.gameId;
-
-        var url = string.Concat(VERSION_URL[urlIndex % VERSION_URL.Length], HttpRequest.HashtablaToString(tables));
-
-        urlIndex++;
-        versionUrl = url;
-        Debug.Log("http鍦板潃:versionUrl  " + url);
-        HttpRequest.Instance.RequestHttpGet(url, HttpRequest.defaultHttpContentType, 1, OnVersionCheckResult);
-    }
-
-    private void OnVersionCheckResult(bool _ok, string _result)
-    {
-        if (_ok)
-        {
-            versionUrlResult = _result.Replace("{}", "null");
-            versionInfo = JsonMapper.ToObject<VersionInfo>(versionUrlResult);
-
-            if (VersionConfigEx.Get().assetAccess == VersionConfigEx.InstalledAsset.IngoreDownLoad)
-            {
-                assetVersions = localAssetVersions;
-                step = LoadDllStep.ReadBytes;
-                return;
-            }
-            step = LoadDllStep.PrepareDownLoad;
-        }
-        else
-        {
-            Debug.Log("http 鏁版嵁閫氳: VersionUtility:" + versionUrl + "  result:" + versionUrlResult);
-            Clock.AlarmAt(DateTime.Now + new TimeSpan(TimeSpan.TicksPerSecond), RequestVersionCheck);
-        }
-    }
-
-    public string GetAssetFilePath(string _assetKey)
-    {
-        var path = Path.Combine(ExternalStorePath, _assetKey);
-        if (!File.Exists(path))
-        {
-            path = Path.Combine(StreamingAssetPath, _assetKey);
-        }
-
-        return path;
-    }
-
-    public Sprite LoadSprite(string name)
-    {
-        Sprite sprite = null;
-#if UNITY_EDITOR
-        // if (excludePngs.Contains(StringUtility.Contact(name, ".png")))
-        // {
-        //     var path = StringUtility.Contact("Assets/ResourcesOut/BuiltIn/Sprites/", name, ".png");
-        //     sprite = UnityEditor.AssetDatabase.LoadAssetAtPath<Sprite>(path);
-        // }
-        // else
-        // {
-            var spriteAtlas = UnityEditor.AssetDatabase.LoadAssetAtPath<SpriteAtlas>("Assets/ResourcesOut/BuiltIn/Sprites/sprites.spriteatlasv2");
-            sprite = spriteAtlas.GetSprite(name);
-        // }
-
-#else
-        if (spriteBundle == null)
-        {
-            string _path = GetAssetFilePath("builtin/sprites");
-            spriteBundle = AssetBundle.LoadFromFile(_path);
-        }
-
-        sprite = spriteBundle.LoadAsset(name, typeof(Sprite)) as Sprite;
-#endif
-        if (sprite == null)
-        {
-            Debug.LogErrorFormat("LoadSprite() => 鍔犺浇涓嶅埌璧勬簮: {0}.", name);
-        }
-
-        return sprite;
-    }
-
-    public GameObject LoadBuiltInPrefab(string name)
-    {
-        GameObject prefab = null;
-#if UNITY_EDITOR
-        var path = string.Concat("Assets/ResourcesOut/BuiltIn/Prefabs/", name, ".prefab");
-        prefab = UnityEditor.AssetDatabase.LoadAssetAtPath<GameObject>(path);
-#else
-        if (prefabBundle == null)
-        {
-            string _path = GetAssetFilePath("builtin/prefabs");
-            prefabBundle = AssetBundle.LoadFromFile(_path);
-        }
-        prefab = prefabBundle.LoadAsset(name) as GameObject;
-#endif
-        if (prefab == null)
-        {
-            Debug.LogErrorFormat("LoadBuiltInPrefab() => 鍔犺浇涓嶅埌璧勬簮: {0}.", name);
-        }
-
-        return prefab;
-    }
-    
-    private string GetExtension(Type type)
-    {
-        if (type == typeof(GameObject))
-            return ".prefab";
-        else if (type == typeof(Sprite))
-            return ".png";
-        else if (type == typeof(Texture2D))
-            return ".png";
-        else if (type == typeof(Shader))
-            return ".shader";
-        else if (type == typeof(TextAsset))
-            return ".txt";
-        else if (type == typeof(AudioClip))
-            return ".wav";
-        else if (type == typeof(Font))
-            return ".ttf";
-        else if (type == typeof(Material))
-            return ".mat";
-        else
-        {
-            Debug.LogErrorFormat("GetExtension() => 涓嶆敮鎸佺殑璧勬簮绫诲瀷: {0}.", type.Name);
-            return "";
-        }
-    }
-
-    public T LoadAsset<T> (string directory, string name) where T : UnityEngine.Object
-    {
-        T asset = null;
-#if UNITY_EDITOR
-        var path = string.Concat($"Assets/ResourcesOut/{directory}/{name}", GetExtension(typeof(T)));
-        asset = UnityEditor.AssetDatabase.LoadAssetAtPath<T>(path);
-#else
-        if (prefabBundle == null)
-        {
-            // string _path = GetAssetFilePath("builtin/prefabs");
-            string _path = GetAssetFilePath($"builtin/{directory}");
-            prefabBundle = AssetBundle.LoadFromFile(_path);
-        }
-        asset = prefabBundle.LoadAsset(name) as t;
-#endif
-        if (asset == null)
-        {
-            Debug.LogErrorFormat("LoadBuiltInPrefab() => 鍔犺浇涓嶅埌璧勬簮: {0}.", name);
-        }
-
-        return asset;
-    }
-
-
-    public void InitDefaultLanguage()
-    {
-        var config = InitialFunctionConfig.Get("Language").Numerical1;
-        Debug.LogFormat("绯荤粺璇█锛歿0} {1}", Application.systemLanguage, config);
-        if (string.IsNullOrEmpty(config))
-            return;
-        var id = LocalSave.GetString("LANGUAGE_ID1");
-        if (!string.IsNullOrEmpty(id))
-            return;
-
-        switch (Application.systemLanguage)
-        {
-            case SystemLanguage.Chinese:
-            case SystemLanguage.ChineseSimplified:
-            case SystemLanguage.ChineseTraditional:
-                {
-                    id = "zh";
-                    break;
-                }
-        }
-        var json = JsonMapper.ToObject(config);
-        if (json.Keys.Contains(id))
-            Id = id;
-        else
-        {
-            //寮�鍚殑鎯呭喌涓嬪繀椤昏鏈変釜榛樿鍊�
-            Id = InitialFunctionConfig.Get("Language").Numerical2;
-        }
-    }
-    
-    //LogicBytes鏂囦欢鐨凪D5淇℃伅
-    public void RequestLogicBytes()
-    {
-        var remoteURL = string.Concat(versionInfo.GetResourcesURL(VersionConfigEx.Get().branch), fixPath, "/logicbytes.txt");
-        //var localURL = string.Concat(.ExternalStorePath, "/logicbytes.txt");
-        assetBytesUrl = remoteURL;
-        Debug.Log("http鍦板潃:logicbytesUrl  " + assetBytesUrl);
-        //HttpRequest.Instance.RequestHttpGet(assetBytesUrl, HttpRequest.defaultHttpContentType, 3, OnGetAssetVersionFile);
-        HttpRequest.Instance.UnityWebRequestGet(assetBytesUrl, 5, OnGetAssetVersionFile);
-    }
-
-    private void OnGetAssetVersionFile(bool _ok, string _result)
-    {
-        Debug.LogFormat("RequestLogicBytes鏂囦欢缁撴灉锛氭椂闂� {0}锛岀粨鏋� {1}, 鏂囦欢澶у皬 {2}", DateTime.Now, _ok, _result.Length);
-        if (_ok)
-        {
-            UpdateAssetVersions(_result);
-            step = LoadDllStep.DownLoad;
-        }
-        else
-        {
-            Debug.Log("http 鏁版嵁閫氳: RequestLogicBytes:" + assetBytesUrl + "  result:" + _result);
-            Clock.AlarmAt(DateTime.Now + new TimeSpan(TimeSpan.TicksPerSecond * 3), RequestLogicBytes);
-        }
-    }
-
-    public Dictionary<string, AssetVersion> UpdateAssetVersions(string _assetVersionFile)
-    {
-        var lines = _assetVersionFile.Split(new string[] { FileExtersion.lineSplit }, StringSplitOptions.RemoveEmptyEntries);
-        assetVersions.Clear();
-        for (int i = 0; i < lines.Length; i++)
-        {
-            var assetVersion = new AssetVersion(lines[i]);
-            assetVersions[assetVersion.relativePath] = assetVersion;
-        }
-        return assetVersions;
-    }
-
-    //璇昏〃 浣跨敤UnityWebRequest 鑰冭檻瀹夊崜鐜
-    private async UniTask ReadText(string table, Action<bool, string> OnComplete = null, string filePath = "")
-    {
-        var path = string.Empty;
-        string content = string.Empty;
-        bool result = false;
-        if (filePath != "")
-        {
-            path = Path.Combine(filePath + $"{table}.txt");
-        }
-        else
-        {
-#if UNITY_EDITOR
-            path = CONFIG_FODLER + $"/{table}.txt";
-#else
-        path = GetAssetFilePath($"config/{table}.txt");
-#endif
-        }
-        if (!path.Contains("file:"))
-        {
-            //ExternalStorePath 璺緞闇�瑕佹坊鍔�
-            path = "file://" + path;
-        }
-        Debug.LogFormat("ReadText() => path: {0}", path);
-        UnityWebRequest www = UnityWebRequest.Get(path);
-        await www.SendWebRequest();
-
-#if UNITY_2020_1_OR_NEWER
-    if (www.result != UnityWebRequest.Result.Success)
-    {
-        Debug.Log(www.error);
-        OnComplete(result, content);
-    }
-#else
-        if (www.isHttpError || www.isNetworkError)
-        {
-            Debug.Log(www.error);
-            OnComplete(result, content);
-        }
-#endif
-        else
-        {
-            content = www.downloadHandler.text;
-            Debug.Log($"table:{table}  size:{content.Length}");
-            result = true;
-            OnComplete(result, content);
-        }
-
-    }
-
-    public async void InitTable(Action OnComplete = null)
-    {
-        await ReadText("InitialFunction", (isOK, value) =>
-        {
-            if (isOK)
-            {
-                InitialFunctionConfig.Init(value);
-                OnComplete();
-            }
-            else
-            {
-                Debug.LogError("InitTable InitialFunctionConfig error");
-            }
-        });
-        if (isPCTestDownLoad || Application.isMobilePlatform)
-        {
-            //璇诲彇鐨勪竴瀹氭槸StreamingAssetPath璺緞
-            await ReadText("logicbytes", (isOK, value) =>
-            {
-                if (isOK)
-                    InitLocalLogicbytes(value);
-                else
-                    Debug.LogWarning("InitTable logicbytes error");
-            }, StreamingAssetPath);
-        }
-    }
-
-    //闅忓寘瀹夎鐨勮祫婧愪笉鍚屽钩鍙颁笉涓�瀹氬彲浠ヨ幏鍙朏ileInfo锛屾墍浠ラ渶瑕佷笅杞戒竴涓枃浠舵潵鑾峰彇璧勬簮鐨凪D5淇℃伅
-    //璇ユ枃浠跺湪鎵撳寘鏃剁敓鎴� 璁板綍闅忓寘鐨勬墍鏈夎祫婧愮殑淇℃伅
-    //璇ユ枃浠惰褰曠殑璧勬簮鍦ㄥ寘涓偗瀹氬瓨鍦紝鎵�浠ヤ笉鐢ㄥ幓鍙栨寚瀹氱殑璧勬簮鏂囦欢鑾峰緱FileInfo 璁$畻MD5
-    //闅忓寘LogicBytes鏂囦欢鐨凪D5淇℃伅 鐢ㄤ簬涓嬭浇瀵规瘮
-    void InitLocalLogicbytes(string content)
-    {
-        using (StringReader reader = new StringReader(content))
-        {
-            string line;
-            while ((line = reader.ReadLine()) != null)
-            {
-                try
-                {
-                    var assetVersion = new AssetVersion(line);
-                    assetVersion.localValid = true;
-                    localAssetVersions[assetVersion.relativePath] = assetVersion;
-                }
-                catch (System.Exception ex)
-                {
-                    Debug.LogError(ex);
-                }
-            }
-        }
-        
-    }
-
-    public void UnloadAsset(string assetBundleName)
-    {
-        
-    }
-
-    public class VersionInfo
-    {
-        public JsonData notice_flag;
-        public JsonData resource_url; //杩欓噷鍙敤鍒拌繖涓彇涓嬭浇鍦板潃
-        public string ResourceAward;
-        public int downAsset = 1;
-        public string downUrl;
-        public int VersionCount;
-
-
-        public string GetResourcesURL(int _branch)
-        {
-            if (resource_url != null)
-            {
-                return resource_url[_branch.ToString()].ToString();
-            }
-            else
-            {
-                return string.Empty;
-            }
-        }
-
-    }
-
-    public class DebugBranch
-    {
-        public int branch = -1;
-    }
-
-    public enum LoadDllStep
-    {
-        None,
-        Wait,   //姣忎釜闃舵鐨勭瓑寰呮椂闂� 姣斿鍦ㄤ笅杞戒腑灏卞浜庣瓑寰呯姸鎬侊紝瀹屾垚鍚庡啀杩涘叆涓嬩竴涓樁娈�
-        RequestVersion,
-        PrepareDownLoad,
-        DownLoad,
-        ReadBytes,
-        Completed,
-    }
-
-
+using UnityEngine;
+using System.Collections;
+using System.Collections.Generic;
+using Cysharp.Threading.Tasks;
+using System;
+using UnityEngine.U2D;
+using LitJson;
+using System.IO;
+using UnityEngine.Networking;
+
+#if UNITY_EDITOR
+using UnityEditor;
+#endif
+
+using LaunchCommon;
+
+
+//  鐑洿鏂板墠鐨勪唬鐮�
+
+public class LocalResManager : Singleton<LocalResManager>
+{
+	//涓嶄笅杞芥椂鏈湴瀹夊崜娴嬭瘯璺緞
+    public string assetBundlesPath = Application.dataPath + "/../AssetBundles/Android/";
+    public static string bytesFolderName = "logicbytes/";
+    public string StreamingAssetPath
+    {
+        get
+        {
+            return ResourcesPath.Instance.StreamingAssetPath;
+        }
+    }
+    public string ExternalStorePath 
+    {
+        get
+        {
+            return ResourcesPath.Instance.ExternalStorePath;
+        }
+    }
+
+    //鐢ㄤ簬editor 涓嬬殑璧勬簮璺緞
+    public string ResourcesOutPath 
+    {
+        get
+        {
+            return ResourcesPath.ResourcesOutPath;
+        }
+    }
+
+    public string CONFIG_FODLER
+    {
+        get
+        {
+            return ResourcesPath.CONFIG_FODLER;
+        }
+    }
+
+    public string ResourcesOutAssetPath
+    {
+        get
+        {
+            return ResourcesPath.ResourcesOutAssetPath;
+        }
+    }
+
+    public bool isPCTestDownLoad = false;
+
+    public static readonly string[] VERSION_URL = new string[] {
+        "http://gamecenter.secondworld.net.cn:11000/center/appversion_new.php/?"};
+
+	public int debugBranch { get; private set; }
+
+    private int urlIndex = 0;
+
+    private string versionUrl;
+
+    public VersionInfo versionInfo { get; private set; }
+
+    private static LoadDllStep m_step;
+
+    public static LoadDllStep step
+    {
+        get { return m_step; }
+        set
+        {
+            m_step = value;
+            Debug.Log("LoadDllStep:" + m_step);
+        }
+    }
+
+    string assetBytesUrl;
+
+    //浠庣綉缁滆幏鍙栫殑璧勬簮鐗堟湰淇℃伅
+    public Dictionary<string, AssetVersion> assetVersions = new Dictionary<string, AssetVersion>();
+
+    //鏈湴LogicBytes鏂囦欢鍜� assetVersions 姣旇緝鏄惁闇�瑕佷笅杞�
+    public Dictionary<string, AssetVersion> localAssetVersions = new Dictionary<string, AssetVersion>();
+
+    public static string versionUrlResult { get; private set; }
+
+        /// <summary>
+    /// 璇█鐨処D锛岀敤浜庡尯鍒嗕笅杞借祫婧�
+    /// </summary>
+    /// <value></value>
+    public static string Id
+    {
+        get
+        {
+            var config = InitialFunctionConfig.Get("Language").Numerical1;
+            if (string.IsNullOrEmpty(config))
+                return "";
+            return LocalSave.GetString("LANGUAGE_ID1");
+        }
+        set
+        {
+            LocalSave.SetString("LANGUAGE_ID1", value);
+        }
+    }
+
+    //榛樿璺緞涓嶉檮鍔犲湴鍧�锛孖d涓嶄负绌烘椂闄勫姞Id
+    public static string fixPath
+    {
+        get
+        {
+            if (string.IsNullOrEmpty(Id))
+                return "";
+            return string.Format("/{0}", Id);
+        }
+    }
+
+    private AssetBundle spriteBundle = null;   //闇�瑕佸嵏杞�
+    private AssetBundle prefabBundle = null;   //闇�瑕佸嵏杞�
+    private SpriteAtlas spriteAtlas = null;
+
+    public void Init()
+    {
+        if (LocalSave.GetString("#@#BrancH") != string.Empty)
+        {
+            int tmpbranch;
+            int.TryParse(LocalSave.GetString("#@#BrancH").Substring(1), out tmpbranch);
+            if (tmpbranch != 0)
+                debugBranch = tmpbranch;
+        }
+
+        var parentDirectory = Directory.GetParent(Application.persistentDataPath);
+        if (File.Exists(parentDirectory + "/Debug"))
+        {
+            var content = File.ReadAllText(parentDirectory + "/Debug");
+            if (!string.IsNullOrEmpty(content))
+            {
+                var json = JsonMapper.ToObject<DebugBranch>(File.ReadAllText(parentDirectory + "/Debug"));
+                debugBranch = json.branch;
+            }
+        }
+
+        Clock.Init();
+        Debug.Log("LocalResManager.Init");
+    }
+
+    public void Release()
+    {
+        spriteBundle?.Unload(true);  //true瀹屽叏鍗歌浇锛屾洿鏂板悗閲嶆柊鍔犺浇
+        prefabBundle?.Unload(true);
+        assetVersions = null;
+        localAssetVersions = null;
+        spriteAtlas = null;
+        Debug.Log("鎻愬墠ResManager.Release璧勬簮");
+    }
+
+	public void RequestVersionCheck()
+    {
+        var versionConfig = VersionConfigEx.Get();
+        var tables = new Dictionary<string, string>();
+        tables["channel"] = versionConfig.appId;
+        tables["versioncode"] = versionConfig.version;
+        if (versionConfig.branch != 0)
+        {
+            tables["branch"] = versionConfig.branch.ToString();
+        }
+
+        tables["game"] = versionConfig.gameId;
+
+        var url = string.Concat(VERSION_URL[urlIndex % VERSION_URL.Length], HttpRequest.HashtablaToString(tables));
+
+        urlIndex++;
+        versionUrl = url;
+        Debug.Log("http鍦板潃:versionUrl  " + url);
+        HttpRequest.Instance.RequestHttpGet(url, HttpRequest.defaultHttpContentType, 1, OnVersionCheckResult);
+    }
+
+    private void OnVersionCheckResult(bool _ok, string _result)
+    {
+        if (_ok)
+        {
+            versionUrlResult = _result.Replace("{}", "null");
+            versionInfo = JsonMapper.ToObject<VersionInfo>(versionUrlResult);
+
+            if (VersionConfigEx.Get().assetAccess == VersionConfigEx.InstalledAsset.IngoreDownLoad)
+            {
+                assetVersions = localAssetVersions;
+                step = LoadDllStep.ReadBytes;
+                return;
+            }
+            step = LoadDllStep.PrepareDownLoad;
+        }
+        else
+        {
+            Debug.Log("http 鏁版嵁閫氳: VersionUtility:" + versionUrl + "  result:" + versionUrlResult);
+            Clock.AlarmAt(DateTime.Now + new TimeSpan(TimeSpan.TicksPerSecond), RequestVersionCheck);
+        }
+    }
+
+    public string GetAssetFilePath(string _assetKey)
+    {
+        var path = Path.Combine(ExternalStorePath, _assetKey);
+        if (!File.Exists(path))
+        {
+            path = Path.Combine(StreamingAssetPath, _assetKey);
+        }
+
+        return path;
+    }
+
+    public Sprite LoadSprite(string name)
+    {
+        Sprite sprite = null;
+#if UNITY_EDITOR
+        // if (excludePngs.Contains(StringUtility.Contact(name, ".png")))
+        // {
+        //     var path = StringUtility.Contact("Assets/ResourcesOut/BuiltIn/Sprites/", name, ".png");
+        //     sprite = UnityEditor.AssetDatabase.LoadAssetAtPath<Sprite>(path);
+        // }
+        // else
+        // {
+            var spriteAtlas = UnityEditor.AssetDatabase.LoadAssetAtPath<SpriteAtlas>("Assets/ResourcesOut/BuiltIn/Sprites/sprites.spriteatlasv2");
+            sprite = spriteAtlas.GetSprite(name);
+        // }
+
+#else
+        if (spriteBundle == null)
+        {
+            string _path = GetAssetFilePath("builtin/sprites");
+            spriteBundle = AssetBundle.LoadFromFile(_path);
+        }
+
+        sprite = spriteBundle.LoadAsset(name, typeof(Sprite)) as Sprite;
+#endif
+        if (sprite == null)
+        {
+            Debug.LogErrorFormat("LoadSprite() => 鍔犺浇涓嶅埌璧勬簮: {0}.", name);
+        }
+
+        return sprite;
+    }
+
+    public GameObject LoadBuiltInPrefab(string name)
+    {
+        GameObject prefab = null;
+#if UNITY_EDITOR
+        var path = string.Concat("Assets/ResourcesOut/BuiltIn/Prefabs/", name, ".prefab");
+        prefab = UnityEditor.AssetDatabase.LoadAssetAtPath<GameObject>(path);
+#else
+        if (prefabBundle == null)
+        {
+            string _path = GetAssetFilePath("builtin/prefabs");
+            prefabBundle = AssetBundle.LoadFromFile(_path);
+        }
+        prefab = prefabBundle.LoadAsset(name) as GameObject;
+#endif
+        if (prefab == null)
+        {
+            Debug.LogErrorFormat("LoadBuiltInPrefab() => 鍔犺浇涓嶅埌璧勬簮: {0}.", name);
+        }
+
+        return prefab;
+    }
+
+
+    public void InitDefaultLanguage()
+    {
+        var config = InitialFunctionConfig.Get("Language").Numerical1;
+        Debug.LogFormat("绯荤粺璇█锛歿0} {1}", Application.systemLanguage, config);
+        if (string.IsNullOrEmpty(config))
+            return;
+        var id = LocalSave.GetString("LANGUAGE_ID1");
+        if (!string.IsNullOrEmpty(id))
+            return;
+
+        switch (Application.systemLanguage)
+        {
+            case SystemLanguage.Chinese:
+            case SystemLanguage.ChineseSimplified:
+            case SystemLanguage.ChineseTraditional:
+                {
+                    id = "zh";
+                    break;
+                }
+        }
+        var json = JsonMapper.ToObject(config);
+        if (json.Keys.Contains(id))
+            Id = id;
+        else
+        {
+            //寮�鍚殑鎯呭喌涓嬪繀椤昏鏈変釜榛樿鍊�
+            Id = InitialFunctionConfig.Get("Language").Numerical2;
+        }
+    }
+    
+    //LogicBytes鏂囦欢鐨凪D5淇℃伅
+    public void RequestLogicBytes()
+    {
+        var remoteURL = string.Concat(versionInfo.GetResourcesURL(VersionConfigEx.Get().branch), fixPath, "/logicbytes.txt");
+        //var localURL = string.Concat(.ExternalStorePath, "/logicbytes.txt");
+        assetBytesUrl = remoteURL;
+        Debug.Log("http鍦板潃:logicbytesUrl  " + assetBytesUrl);
+        //HttpRequest.Instance.RequestHttpGet(assetBytesUrl, HttpRequest.defaultHttpContentType, 3, OnGetAssetVersionFile);
+        HttpRequest.Instance.UnityWebRequestGet(assetBytesUrl, 5, OnGetAssetVersionFile);
+    }
+
+    private void OnGetAssetVersionFile(bool _ok, string _result)
+    {
+        Debug.LogFormat("RequestLogicBytes鏂囦欢缁撴灉锛氭椂闂� {0}锛岀粨鏋� {1}, 鏂囦欢澶у皬 {2}", DateTime.Now, _ok, _result.Length);
+        if (_ok)
+        {
+            UpdateAssetVersions(_result);
+            step = LoadDllStep.DownLoad;
+        }
+        else
+        {
+            Debug.Log("http 鏁版嵁閫氳: RequestLogicBytes:" + assetBytesUrl + "  result:" + _result);
+            Clock.AlarmAt(DateTime.Now + new TimeSpan(TimeSpan.TicksPerSecond * 3), RequestLogicBytes);
+        }
+    }
+
+    public Dictionary<string, AssetVersion> UpdateAssetVersions(string _assetVersionFile)
+    {
+        var lines = _assetVersionFile.Split(new string[] { FileExtersion.lineSplit }, StringSplitOptions.RemoveEmptyEntries);
+        assetVersions.Clear();
+        for (int i = 0; i < lines.Length; i++)
+        {
+            var assetVersion = new AssetVersion(lines[i]);
+            assetVersions[assetVersion.relativePath] = assetVersion;
+        }
+        return assetVersions;
+    }
+
+    //璇昏〃 浣跨敤UnityWebRequest 鑰冭檻瀹夊崜鐜
+    private async UniTask ReadText(string table, Action<bool, string> OnComplete = null, string filePath = "")
+    {
+        var path = string.Empty;
+        string content = string.Empty;
+        bool result = false;
+        if (filePath != "")
+        {
+            path = Path.Combine(filePath + $"{table}.txt");
+        }
+        else
+        {
+#if UNITY_EDITOR
+            path = CONFIG_FODLER + $"/{table}.txt";
+#else
+        path = GetAssetFilePath($"config/{table}.txt");
+#endif
+        }
+        if (!path.Contains("file:"))
+        {
+            //ExternalStorePath 璺緞闇�瑕佹坊鍔�
+            path = "file://" + path;
+        }
+        Debug.LogFormat("ReadText() => path: {0}", path);
+        UnityWebRequest www = UnityWebRequest.Get(path);
+        await www.SendWebRequest();
+
+#if UNITY_2020_1_OR_NEWER
+    if (www.result != UnityWebRequest.Result.Success)
+    {
+        Debug.Log(www.error);
+        OnComplete(result, content);
+    }
+#else
+        if (www.isHttpError || www.isNetworkError)
+        {
+            Debug.Log(www.error);
+            OnComplete(result, content);
+        }
+#endif
+        else
+        {
+            content = www.downloadHandler.text;
+            Debug.Log($"table:{table}  size:{content.Length}");
+            result = true;
+            OnComplete(result, content);
+        }
+
+    }
+
+    public async void InitTable(Action OnComplete = null)
+    {
+        await ReadText("InitialFunction", (isOK, value) =>
+        {
+            if (isOK)
+            {
+                InitialFunctionConfig.Init(value);
+                OnComplete();
+            }
+            else
+            {
+                Debug.LogError("InitTable InitialFunctionConfig error");
+            }
+        });
+        if (isPCTestDownLoad || Application.isMobilePlatform)
+        {
+            //璇诲彇鐨勪竴瀹氭槸StreamingAssetPath璺緞
+            await ReadText("logicbytes", (isOK, value) =>
+            {
+                if (isOK)
+                    InitLocalLogicbytes(value);
+                else
+                    Debug.LogWarning("InitTable logicbytes error");
+            }, StreamingAssetPath);
+        }
+    }
+
+    //闅忓寘瀹夎鐨勮祫婧愪笉鍚屽钩鍙颁笉涓�瀹氬彲浠ヨ幏鍙朏ileInfo锛屾墍浠ラ渶瑕佷笅杞戒竴涓枃浠舵潵鑾峰彇璧勬簮鐨凪D5淇℃伅
+    //璇ユ枃浠跺湪鎵撳寘鏃剁敓鎴� 璁板綍闅忓寘鐨勬墍鏈夎祫婧愮殑淇℃伅
+    //璇ユ枃浠惰褰曠殑璧勬簮鍦ㄥ寘涓偗瀹氬瓨鍦紝鎵�浠ヤ笉鐢ㄥ幓鍙栨寚瀹氱殑璧勬簮鏂囦欢鑾峰緱FileInfo 璁$畻MD5
+    //闅忓寘LogicBytes鏂囦欢鐨凪D5淇℃伅 鐢ㄤ簬涓嬭浇瀵规瘮
+    void InitLocalLogicbytes(string content)
+    {
+        using (StringReader reader = new StringReader(content))
+        {
+            string line;
+            while ((line = reader.ReadLine()) != null)
+            {
+                try
+                {
+                    var assetVersion = new AssetVersion(line);
+                    assetVersion.localValid = true;
+                    localAssetVersions[assetVersion.relativePath] = assetVersion;
+                }
+                catch (System.Exception ex)
+                {
+                    Debug.LogError(ex);
+                }
+            }
+        }
+        
+    }
+
+    public class VersionInfo
+    {
+        public JsonData notice_flag;
+        public JsonData resource_url; //杩欓噷鍙敤鍒拌繖涓彇涓嬭浇鍦板潃
+        public string ResourceAward;
+        public int downAsset = 1;
+        public string downUrl;
+        public int VersionCount;
+
+
+        public string GetResourcesURL(int _branch)
+        {
+            if (resource_url != null)
+            {
+                return resource_url[_branch.ToString()].ToString();
+            }
+            else
+            {
+                return string.Empty;
+            }
+        }
+
+    }
+
+    public class DebugBranch
+    {
+        public int branch = -1;
+    }
+
+    public enum LoadDllStep
+    {
+        None,
+        Wait,   //姣忎釜闃舵鐨勭瓑寰呮椂闂� 姣斿鍦ㄤ笅杞戒腑灏卞浜庣瓑寰呯姸鎬侊紝瀹屾垚鍚庡啀杩涘叆涓嬩竴涓樁娈�
+        RequestVersion,
+        PrepareDownLoad,
+        DownLoad,
+        ReadBytes,
+        Completed,
+    }
 }
\ No newline at end of file

--
Gitblit v1.8.0