diff --git a/Assets/TcgEngine/Resources/Packs/elite.asset b/Assets/TcgEngine/Resources/Packs/elite.asset
index 6d9bf74..f208b98 100644
--- a/Assets/TcgEngine/Resources/Packs/elite.asset
+++ b/Assets/TcgEngine/Resources/Packs/elite.asset
@@ -34,10 +34,12 @@ MonoBehaviour:
probability: 90
- variant: {fileID: 11400000, guid: 3a827aeeaca139641a4b8ad0c3c74f52, type: 2}
probability: 10
- title: 黄金卡包
+ title: "\u9EC4\u91D1\u5361\u5305"
pack_img: {fileID: 21300000, guid: e400c282187e5f54dab6aacfd8adae20, type: 3}
cardback_img: {fileID: 21300000, guid: 96d8dad709a2729419f19d1d4633a0ef, type: 3}
- desc: 精英卡包,内含5张卡牌。更有机会获得稀有卡牌和神话卡牌。.
+ pack_img_path: Cardbacks/pack_gold.png
+ cardback_img_path: Cardbacks/cardback_gold.png
+ desc: "\u7CBE\u82F1\u5361\u5305\uFF0C\u5185\u542B5\u5F20\u5361\u724C\u3002\u66F4\u6709\u673A\u4F1A\u83B7\u5F97\u7A00\u6709\u5361\u724C\u548C\u795E\u8BDD\u5361\u724C\u3002."
sort_order: 1
available: 1
cost: 250
diff --git a/Assets/TcgEngine/Resources/Packs/standard.asset b/Assets/TcgEngine/Resources/Packs/standard.asset
index 089ba91..dc1bbc3 100644
--- a/Assets/TcgEngine/Resources/Packs/standard.asset
+++ b/Assets/TcgEngine/Resources/Packs/standard.asset
@@ -36,10 +36,12 @@ MonoBehaviour:
probability: 96
- variant: {fileID: 11400000, guid: 3a827aeeaca139641a4b8ad0c3c74f52, type: 2}
probability: 4
- title: 白银卡包
- pack_img: {fileID: 21300000, guid: b2c2a8efa1f7d7b4593a512e2c8cd61a, type: 3}
+ title: "\u767D\u94F6\u5361\u5305"
+ pack_img: {fileID: 0}
cardback_img: {fileID: 21300000, guid: 0e839bd6251bf9a4697b9cb18c1565a4, type: 3}
- desc: 白银卡包,内含5张卡牌.
+ pack_img_path: Cardbacks/pack_silver.png
+ cardback_img_path: Cardbacks/cardback_silver.png
+ desc: "\u767D\u94F6\u5361\u5305\uFF0C\u5185\u542B5\u5F20\u5361\u724C."
sort_order: 0
available: 1
cost: 100
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/Data/PackData.cs b/Assets/TcgEngine/Scripts/Data/PackData.cs
index 6c25b5a..dcb2287 100644
--- a/Assets/TcgEngine/Scripts/Data/PackData.cs
+++ b/Assets/TcgEngine/Scripts/Data/PackData.cs
@@ -24,6 +24,11 @@ namespace TcgEngine
public string title;
public Sprite pack_img;
public Sprite cardback_img;
+
+ [Header("Dynamic Art Paths")]
+ public string pack_img_path;
+ public string cardback_img_path;
+
[TextArea(5, 10)]
public string desc;
public int sort_order;
@@ -56,6 +61,54 @@ namespace TcgEngine
{
return desc;
}
+
+ ///
+ /// 获取Pack图片,优先使用动态路径
+ ///
+ public Sprite GetPackImage()
+ {
+ if (!string.IsNullOrEmpty(pack_img_path))
+ {
+ Sprite dynamicSprite = SpriteLoader.Get()?.LoadSprite(pack_img_path);
+ if (dynamicSprite != null)
+ {
+ return dynamicSprite;
+ }
+ else
+ {
+ Debug.LogWarning($"Pack {id} 图片加载失败: {pack_img_path}");
+ }
+ }
+ else
+ {
+ Debug.LogWarning($"Pack {id} pack_img_path为空");
+ }
+ return pack_img;
+ }
+
+ ///
+ /// 获取卡背图片,优先使用动态路径
+ ///
+ public Sprite GetCardbackImage()
+ {
+ if (!string.IsNullOrEmpty(cardback_img_path))
+ {
+ Sprite dynamicSprite = SpriteLoader.Get()?.LoadSprite(cardback_img_path);
+ if (dynamicSprite != null)
+ {
+ return dynamicSprite;
+ }
+ else
+ {
+ Debug.LogWarning($"Pack {id} 卡背图片加载失败: {cardback_img_path}");
+ }
+ }
+ else
+ {
+ Debug.LogWarning($"Pack {id} cardback_img_path为空");
+ }
+ return cardback_img;
+ }
public static PackData Get(string id)
{
diff --git a/Assets/TcgEngine/Scripts/GameClient/HandPack.cs b/Assets/TcgEngine/Scripts/GameClient/HandPack.cs
index 209bb01..00d5af9 100644
--- a/Assets/TcgEngine/Scripts/GameClient/HandPack.cs
+++ b/Assets/TcgEngine/Scripts/GameClient/HandPack.cs
@@ -127,7 +127,7 @@ namespace TcgEngine.Client
PackData ipack = PackData.Get(pack.tid);
if (ipack)
{
- pack_sprite.sprite = ipack.pack_img;
+ pack_sprite.sprite = ipack.GetPackImage();
}
}
diff --git a/Assets/TcgEngine/Scripts/GameClient/PackCard.cs b/Assets/TcgEngine/Scripts/GameClient/PackCard.cs
index 02dd020..fce77c7 100644
--- a/Assets/TcgEngine/Scripts/GameClient/PackCard.cs
+++ b/Assets/TcgEngine/Scripts/GameClient/PackCard.cs
@@ -70,7 +70,7 @@ namespace TcgEngine.Client
this.variant = variant;
if (cardback != null)
- cardback.sprite = pack.cardback_img;
+ cardback.sprite = pack.GetCardbackImage();
card_ui.SetCard(card, variant);
new_card?.SetActive(false);
diff --git a/Assets/TcgEngine/Scripts/Menu/ResourceInitializer.cs b/Assets/TcgEngine/Scripts/Menu/ResourceInitializer.cs
index 65eba3d..c5c0d30 100644
--- a/Assets/TcgEngine/Scripts/Menu/ResourceInitializer.cs
+++ b/Assets/TcgEngine/Scripts/Menu/ResourceInitializer.cs
@@ -181,19 +181,6 @@ namespace TcgEngine
downloadCompleted = true;
UpdateProgress(1f);
UpdateStatus("资源解压完成!");
-
- // 打印解压后的文件夹位置
- if (ResourceDownloader.Get() != null)
- {
- ResourceDownloader.Get().LogResourcePaths();
-
- // 另外也可以直接打印路径
- string spritesPath = ResourceDownloader.Get().GetSpritesDirectoryPath();
- Debug.Log($"[ResourceInitializer] 资源解压到: {spritesPath}");
-
- // 在macOS上,可以直接用这个命令在终端中打开文件夹
- Debug.Log($"[ResourceInitializer] 打开文件夹命令: open \"{spritesPath}\"");
- }
}
///
diff --git a/Assets/TcgEngine/Scripts/Network/ResourceDownloader.cs b/Assets/TcgEngine/Scripts/Network/ResourceDownloader.cs
index f4a65b2..5dca260 100644
--- a/Assets/TcgEngine/Scripts/Network/ResourceDownloader.cs
+++ b/Assets/TcgEngine/Scripts/Network/ResourceDownloader.cs
@@ -14,22 +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 = "/api/version";
-
- [Header("URL Pattern Options")]
- [Tooltip("支持的占位符: {version} - 版本号")]
- public bool useVersionInFilename = true;
- [Tooltip("如果启用,会先检查版本化文件是否存在")]
- public bool validateVersionedUrl = false;
- [Tooltip("调试模式:当版本接口失败时,使用固定版本号")]
- public bool debugMode = true;
- [Tooltip("调试模式下使用的固定版本号")]
- public string debugVersion = "0.0.1";
- [Tooltip("调试模式下使用的固定MD5值")]
- public string debugMd5 = "ceb24758054d6dcf1e23ddb41811a525";
+ [Header("Configuration")]
+ [Tooltip("资源下载器配置文件")]
+ public ResourceDownloaderConfig config;
private string currentVersion = "0.0.0";
private string currentMd5 = "";
private string targetVersion = "0.0.1";
@@ -86,19 +73,7 @@ namespace TcgEngine
Debug.Log($"Starting update check. Current version: {currentVersion}, Current MD5: {currentMd5}");
var serverVersionData = await GetServerVersionData();
if (serverVersionData == null || string.IsNullOrEmpty(serverVersionData.version))
- {
- Debug.LogWarning("Failed to get server version");
-
- // 调试模式:版本接口失败时使用固定版本号
- if (debugMode)
- {
- Debug.Log($"Debug mode enabled: using fixed version {debugVersion} and MD5 {debugMd5}");
- targetVersion = debugVersion;
- targetMd5 = debugMd5;
-
- return await CheckVersionAndMd5();
- }
-
+ {
return false;
}
@@ -112,16 +87,6 @@ namespace TcgEngine
{
Debug.LogError($"Error checking for updates: {e.Message}");
- // 调试模式:出现异常时也尝试使用固定版本
- if (debugMode)
- {
- Debug.Log($"Debug mode: attempting to use version {debugVersion} despite error");
- targetVersion = debugVersion;
- targetMd5 = debugMd5;
-
- return await CheckVersionAndMd5();
- }
-
return false;
}
}
@@ -152,20 +117,13 @@ namespace TcgEngine
return false;
}
- Debug.Log($"版本匹配,开始检查MD5校验...");
- Debug.Log($"当前版本: {currentVersion}");
- Debug.Log($"目标版本: {targetVersion}");
- Debug.Log($"保存的MD5: {currentMd5}");
- Debug.Log($"目标MD5: {targetMd5}");
+ Debug.Log($"版本匹配,开始检查MD5校验... 当前版本: {currentVersion} 目标版本: {targetVersion} 当前MD5: {currentMd5} 目标MD5: {targetMd5}");
string localMd5 = await CalculateDirectoryMd5(spritesPath);
if (localMd5 != targetMd5)
{
- Debug.LogWarning($"🚨 MD5校验失败!");
- Debug.LogWarning($"本地计算MD5: {localMd5}");
- Debug.LogWarning($"期望的MD5: {targetMd5}");
- Debug.Log("正在删除损坏的文件并重新下载...");
+ Debug.Log("MD5校验失败,正在删除损坏的文件并重新下载...");
// 删除损坏的文件
if (Directory.Exists(spritesPath))
@@ -176,8 +134,7 @@ namespace TcgEngine
return true; // 需要重新下载
}
- Debug.Log($"✅ MD5校验通过: {localMd5}");
- Debug.Log("文件完整性验证成功,无需下载");
+ Debug.Log($"✅ MD5校验通过");
return false; // 无需下载
}
@@ -195,25 +152,9 @@ namespace TcgEngine
if (files.Length == 0)
return "";
- Debug.Log($"=== 开始计算目录MD5 ===");
- Debug.Log($"目录路径: {directoryPath}");
- Debug.Log($"文件数量: {files.Length}");
-
// 按路径排序确保一致性
Array.Sort(files);
- // 打印前几个文件作为示例
- Debug.Log("文件列表示例:");
- for (int i = 0; i < Math.Min(5, files.Length); i++)
- {
- string relativePath = files[i].Substring(directoryPath.Length + 1).Replace('\\', '/');
- Debug.Log($" [{i+1}] {relativePath}");
- }
- if (files.Length > 5)
- {
- Debug.Log($" ... 还有 {files.Length - 5} 个文件");
- }
-
using (var md5 = System.Security.Cryptography.MD5.Create())
{
foreach (string file in files)
@@ -238,12 +179,6 @@ namespace TcgEngine
md5.TransformFinalBlock(new byte[0], 0, 0);
string result = BitConverter.ToString(md5.Hash).Replace("-", "").ToLowerInvariant();
- Debug.Log($"=== MD5计算完成 ===");
- Debug.Log($"本地计算的MD5: {result}");
- Debug.Log($"目标MD5: {targetMd5}");
- Debug.Log($"MD5匹配: {(result == targetMd5 ? "✅ 是" : "❌ 否")}");
- Debug.Log($"===================");
-
return result;
}
}
@@ -261,24 +196,23 @@ namespace TcgEngine
{
string targetFileName;
- if (!useVersionInFilename)
+ if (string.IsNullOrEmpty(version))
{
- // 不使用版本化文件名时,统一使用"sprites"
- targetFileName = "sprites";
- }
- else if (string.IsNullOrEmpty(version))
- {
- // 如果版本为空,使用调试版本
- targetFileName = debugVersion;
+ Debug.LogError("Version is null");
+ return "0.0.0";
}
else
{
- // 使用实际版本号
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;
@@ -289,7 +223,7 @@ namespace TcgEngine
///
private async Task ValidateVersionedUrl(string url)
{
- if (!validateVersionedUrl)
+ if (config == null || !config.validateVersionedUrl)
return true;
try
@@ -327,17 +261,13 @@ namespace TcgEngine
///
private async Task GetServerVersionData()
{
- // 从NetworkData获取游戏服务器地址
- string gameServerUrl = NetworkData.Get().api_url;
- if (string.IsNullOrEmpty(gameServerUrl))
+ if (config == null)
{
- Debug.LogError("Failed to get game server URL from NetworkData");
+ Debug.LogError("ResourceDownloaderConfig is not assigned!");
return null;
}
-
- // 构建完整的版本检查URL
- string protocol = NetworkData.Get().api_https ? "https://" : "http://";
- string url = protocol + gameServerUrl + versionEndpoint;
+
+ string url = config.GetVersionUrl();
Debug.Log($"Version check URL: {url}");
using (UnityWebRequest request = UnityWebRequest.Get(url))
{
@@ -382,7 +312,7 @@ namespace TcgEngine
string downloadUrl = BuildVersionedDownloadUrl(targetVersion);
// 验证URL是否存在(可选)
- if (validateVersionedUrl)
+ if (config != null && config.validateVersionedUrl)
{
bool urlExists = await ValidateVersionedUrl(downloadUrl);
if (!urlExists)
@@ -584,79 +514,6 @@ namespace TcgEngine
return currentVersion;
}
- ///
- /// 获取指定版本的下载URL(用于调试)
- ///
- public string GetDownloadUrlForVersion(string version)
- {
- return BuildVersionedDownloadUrl(version);
- }
-
- ///
- /// 获取当前目标版本的下载URL
- ///
- public string GetCurrentDownloadUrl()
- {
- return BuildVersionedDownloadUrl(targetVersion);
- }
-
- ///
- /// 获取本地Sprites目录的完整路径(用于调试)
- ///
- public string GetSpritesDirectoryPath()
- {
- return spritesPath;
- }
-
- ///
- /// 手动计算并打印当前Sprites目录的MD5
- ///
- public async void CalculateAndLogCurrentMd5()
- {
- Debug.Log("=== 手动计算当前Sprites目录MD5 ===");
- if (!Directory.Exists(spritesPath))
- {
- Debug.LogWarning("Sprites目录不存在!");
- return;
- }
-
- string calculatedMd5 = await CalculateDirectoryMd5(spritesPath);
- Debug.Log($"手动计算结果: {calculatedMd5}");
- Debug.Log($"当前保存的MD5: {currentMd5}");
- Debug.Log($"调试MD5: {debugMd5}");
- Debug.Log("================================");
- }
-
- ///
- /// 打印本地资源路径信息
- ///
- public void LogResourcePaths()
- {
- Debug.Log($"=== Resource Paths ===");
- Debug.Log($"persistentDataPath: {persistentDataPath}");
- Debug.Log($"Sprites Directory: {spritesPath}");
- Debug.Log($"Directory Exists: {Directory.Exists(spritesPath)}");
-
- if (Directory.Exists(spritesPath))
- {
- var files = Directory.GetFiles(spritesPath, "*", SearchOption.AllDirectories);
- Debug.Log($"Total files in Sprites: {files.Length}");
-
- // 显示前10个文件作为示例
- for (int i = 0; i < Math.Min(10, files.Length); i++)
- {
- string relativePath = files[i].Substring(spritesPath.Length + 1);
- Debug.Log($" {relativePath}");
- }
-
- if (files.Length > 10)
- {
- Debug.Log($" ... and {files.Length - 10} more files");
- }
- }
- Debug.Log($"======================");
- }
-
public static ResourceDownloader Get()
{
if (instance == null)
@@ -665,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:
diff --git a/Assets/TcgEngine/Scripts/UI/PackUI.cs b/Assets/TcgEngine/Scripts/UI/PackUI.cs
index 13f0fe2..1add572 100644
--- a/Assets/TcgEngine/Scripts/UI/PackUI.cs
+++ b/Assets/TcgEngine/Scripts/UI/PackUI.cs
@@ -41,7 +41,7 @@ namespace TcgEngine.UI
pack_title.text = pack.title;
}
pack_img.enabled = true;
- pack_img.sprite = pack.pack_img;
+ pack_img.sprite = pack.GetPackImage();
}
if (pack_quantity != null)