From 565e2ddf463c748afee71d3fe638e0f3e020015d Mon Sep 17 00:00:00 2001 From: xianyi Date: Thu, 28 Aug 2025 17:44:28 +0800 Subject: [PATCH] =?UTF-8?q?=E7=89=88=E6=9C=AC=E9=AA=8C=E8=AF=81=E9=85=8D?= =?UTF-8?q?=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Resources/ResourceDownloaderConfig.asset | 19 +++++++ .../ResourceDownloaderConfig.asset.meta | 8 +++ Assets/TcgEngine/Scenes/Menu/Splash.unity | 2 +- .../Scripts/Network/ResourceDownloader.cs | 53 ++++++++++++++----- .../Network/ResourceDownloaderConfig.cs | 49 +++++++++++++++++ .../Network/ResourceDownloaderConfig.cs.meta | 11 ++++ 6 files changed, 128 insertions(+), 14 deletions(-) create mode 100644 Assets/TcgEngine/Resources/ResourceDownloaderConfig.asset create mode 100644 Assets/TcgEngine/Resources/ResourceDownloaderConfig.asset.meta create mode 100644 Assets/TcgEngine/Scripts/Network/ResourceDownloaderConfig.cs create mode 100644 Assets/TcgEngine/Scripts/Network/ResourceDownloaderConfig.cs.meta diff --git a/Assets/TcgEngine/Resources/ResourceDownloaderConfig.asset b/Assets/TcgEngine/Resources/ResourceDownloaderConfig.asset new file mode 100644 index 0000000..8a46604 --- /dev/null +++ b/Assets/TcgEngine/Resources/ResourceDownloaderConfig.asset @@ -0,0 +1,19 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!114 &11400000 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: cdc2f7b92625e448fb76f26558cd0779, type: 3} + m_Name: ResourceDownloaderConfig + m_EditorClassIdentifier: + cdnUrl: https://cardcdn.ambigrat.com + serverUrl: http://192.168.1.99:8080 + resourcesEndpoint: /test/{version}.zip + versionEndpoint: /version + validateVersionedUrl: 1 diff --git a/Assets/TcgEngine/Resources/ResourceDownloaderConfig.asset.meta b/Assets/TcgEngine/Resources/ResourceDownloaderConfig.asset.meta new file mode 100644 index 0000000..48174bd --- /dev/null +++ b/Assets/TcgEngine/Resources/ResourceDownloaderConfig.asset.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 5852c171f99424772952bce4e3303421 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 11400000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/TcgEngine/Scenes/Menu/Splash.unity b/Assets/TcgEngine/Scenes/Menu/Splash.unity index 94228c2..dc497e9 100644 --- a/Assets/TcgEngine/Scenes/Menu/Splash.unity +++ b/Assets/TcgEngine/Scenes/Menu/Splash.unity @@ -467,7 +467,7 @@ MonoBehaviour: nextSceneName: LoginMenu fadeInDuration: 1 fadeOutDuration: 1 - minimumDisplayTime: 3 + minimumDisplayTime: 0 splashMusic: {fileID: 0} --- !u!114 &507621921 MonoBehaviour: diff --git a/Assets/TcgEngine/Scripts/Network/ResourceDownloader.cs b/Assets/TcgEngine/Scripts/Network/ResourceDownloader.cs index c0c33ba..5dca260 100644 --- a/Assets/TcgEngine/Scripts/Network/ResourceDownloader.cs +++ b/Assets/TcgEngine/Scripts/Network/ResourceDownloader.cs @@ -14,14 +14,9 @@ namespace TcgEngine /// public class ResourceDownloader : MonoBehaviour { - [Header("Download Settings")] - public string serverUrl = "https://cardcdn.ambigrat.com"; - public string resourcesEndpoint = "/test/{version}.zip"; - public string versionEndpoint = "/version"; - - [Header("URL Pattern Options")] - [Tooltip("检查版本化文件是否存在")] - public bool validateVersionedUrl = true; + [Header("Configuration")] + [Tooltip("资源下载器配置文件")] + public ResourceDownloaderConfig config; private string currentVersion = "0.0.0"; private string currentMd5 = ""; private string targetVersion = "0.0.1"; @@ -211,8 +206,13 @@ namespace TcgEngine targetFileName = version; } - string endpoint = resourcesEndpoint.Replace("{version}", targetFileName); - string url = serverUrl + endpoint; + if (config == null) + { + Debug.LogError("ResourceDownloaderConfig is not assigned!"); + return "0.0.0"; + } + + string url = config.GetResourceUrl(targetFileName); Debug.Log($"Built download URL: {url} (version: {version}, filename: {targetFileName})"); return url; @@ -223,7 +223,7 @@ namespace TcgEngine /// private async Task ValidateVersionedUrl(string url) { - if (!validateVersionedUrl) + if (config == null || !config.validateVersionedUrl) return true; try @@ -261,8 +261,13 @@ namespace TcgEngine /// private async Task GetServerVersionData() { + if (config == null) + { + Debug.LogError("ResourceDownloaderConfig is not assigned!"); + return null; + } - string url = "http://192.168.1.99:8080" + versionEndpoint; + string url = config.GetVersionUrl(); Debug.Log($"Version check URL: {url}"); using (UnityWebRequest request = UnityWebRequest.Get(url)) { @@ -307,7 +312,7 @@ namespace TcgEngine string downloadUrl = BuildVersionedDownloadUrl(targetVersion); // 验证URL是否存在(可选) - if (validateVersionedUrl) + if (config != null && config.validateVersionedUrl) { bool urlExists = await ValidateVersionedUrl(downloadUrl); if (!urlExists) @@ -517,10 +522,32 @@ namespace TcgEngine GameObject go = new GameObject("ResourceDownloader"); instance = go.AddComponent(); DontDestroyOnLoad(go); + + // 加载配置文件 + instance.LoadConfig(); + Debug.Log("Created new ResourceDownloader instance"); } return instance; } + + /// + /// 加载配置文件 + /// + private void LoadConfig() + { + // 从Resources文件夹加载配置文件 + config = Resources.Load("ResourceDownloaderConfig"); + + if (config == null) + { + Debug.LogError("ResourceDownloaderConfig not found in Resources folder! Please create a ResourceDownloaderConfig asset in the Resources folder."); + } + else + { + Debug.Log("ResourceDownloaderConfig loaded successfully"); + } + } } /// diff --git a/Assets/TcgEngine/Scripts/Network/ResourceDownloaderConfig.cs b/Assets/TcgEngine/Scripts/Network/ResourceDownloaderConfig.cs new file mode 100644 index 0000000..0d9e1ba --- /dev/null +++ b/Assets/TcgEngine/Scripts/Network/ResourceDownloaderConfig.cs @@ -0,0 +1,49 @@ +using UnityEngine; + +namespace TcgEngine +{ + /// + /// 资源下载器配置文件 + /// 用于存储服务器URL、资源端点等配置信息 + /// + [CreateAssetMenu(fileName = "ResourceDownloaderConfig", menuName = "TcgEngine/ResourceDownloaderConfig", order = 0)] + public class ResourceDownloaderConfig : ScriptableObject + { + [Header("CDN Configuration")] + [Tooltip("资源服务器的基础URL")] + public string cdnUrl = ""; + + [Tooltip("游戏服务器URL")] + public string serverUrl = ""; + + [Tooltip("资源文件下载路径,{version}会被替换为实际版本号")] + public string resourcesEndpoint = ""; + + [Tooltip("版本检查接口")] + public string versionEndpoint = ""; + + [Header("Download Settings")] + [Tooltip("检查版本化文件是否存在")] + public bool validateVersionedUrl = true; + + /// + /// 获取完整的资源下载URL + /// + /// 版本号 + /// 完整的下载URL + public string GetResourceUrl(string version) + { + string endpoint = resourcesEndpoint.Replace("{version}", version); + return cdnUrl + endpoint; + } + + /// + /// 获取版本检查URL + /// + /// 版本检查URL + public string GetVersionUrl() + { + return serverUrl + versionEndpoint; + } + } +} diff --git a/Assets/TcgEngine/Scripts/Network/ResourceDownloaderConfig.cs.meta b/Assets/TcgEngine/Scripts/Network/ResourceDownloaderConfig.cs.meta new file mode 100644 index 0000000..1854321 --- /dev/null +++ b/Assets/TcgEngine/Scripts/Network/ResourceDownloaderConfig.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: cdc2f7b92625e448fb76f26558cd0779 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: