From b3a5232867db4e9aaf05aa56d52244f0abed0dbb Mon Sep 17 00:00:00 2001 From: xianyi Date: Fri, 29 Aug 2025 10:48:03 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=BB=98=E8=AE=A4=E5=8D=A1?= =?UTF-8?q?=E7=BB=84&=E5=8D=A1=E8=83=8C=E5=9B=BE=E7=89=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../TcgEngine/Resources/Decks/fire_deck.asset | 6 +- .../Resources/Decks/forest_deck.asset | 6 +- .../Resources/Decks/water_deck.asset | 10 ++- Assets/TcgEngine/Scenes/Game/Game.unity | 10 +++ .../Scripts/GameClient/HandCardBack.cs | 65 ++++++++++++++++++- .../Scripts/GameClient/OpponentHand.cs | 22 ++++++- 6 files changed, 111 insertions(+), 8 deletions(-) diff --git a/Assets/TcgEngine/Resources/Decks/fire_deck.asset b/Assets/TcgEngine/Resources/Decks/fire_deck.asset index 0b7bdf7..ed3afdc 100644 --- a/Assets/TcgEngine/Resources/Decks/fire_deck.asset +++ b/Assets/TcgEngine/Resources/Decks/fire_deck.asset @@ -13,7 +13,7 @@ MonoBehaviour: m_Name: fire_deck m_EditorClassIdentifier: id: fire_deck - title: 火焰 + title: "\u706B\u7130" hero: {fileID: 11400000, guid: cf170aea7ffb041428f37608f1561058, type: 2} cards: - {fileID: 11400000, guid: 99081d84b6aa6264aa1c68c6defbe31d, type: 2} @@ -24,3 +24,7 @@ MonoBehaviour: - {fileID: 11400000, guid: 90322744d448d6a46b8c2361a222d9a6, type: 2} - {fileID: 11400000, guid: 90322744d448d6a46b8c2361a222d9a6, type: 2} - {fileID: 11400000, guid: faacda797c4448a4bbbcbca76c6fefc0, type: 2} + - {fileID: 11400000, guid: 83692bb780503404b92feed04c7d222b, type: 2} + - {fileID: 11400000, guid: d3e866161f45f03498b4098dbd8d968d, type: 2} + - {fileID: 11400000, guid: 979b326ecf73d0a4791dc37a6f13c24a, type: 2} + - {fileID: 11400000, guid: 900d0aa6de59c1349ab5c08a481c2a38, type: 2} diff --git a/Assets/TcgEngine/Resources/Decks/forest_deck.asset b/Assets/TcgEngine/Resources/Decks/forest_deck.asset index 4a3b09d..9b4c0cb 100644 --- a/Assets/TcgEngine/Resources/Decks/forest_deck.asset +++ b/Assets/TcgEngine/Resources/Decks/forest_deck.asset @@ -13,7 +13,7 @@ MonoBehaviour: m_Name: forest_deck m_EditorClassIdentifier: id: forest_deck - title: 森林 + title: "\u68EE\u6797" hero: {fileID: 11400000, guid: 04fd0777e8f567b48ad05e6bdaf97c1d, type: 2} cards: - {fileID: 11400000, guid: 1e22d4647e903814d96f63a729e1f820, type: 2} @@ -24,3 +24,7 @@ MonoBehaviour: - {fileID: 11400000, guid: 4a0f93237a2ae53468e29927c1b7c1ec, type: 2} - {fileID: 11400000, guid: 2302f11d23015254dbb067255d70e738, type: 2} - {fileID: 11400000, guid: 4fc52d01f2883134ea1e6ea0d9ba82f2, type: 2} + - {fileID: 11400000, guid: 4fc52d01f2883134ea1e6ea0d9ba82f2, type: 2} + - {fileID: 11400000, guid: fa7053162e690c948a100b6cbcde7266, type: 2} + - {fileID: 11400000, guid: fa7053162e690c948a100b6cbcde7266, type: 2} + - {fileID: 11400000, guid: 9f363479388a0c347b8a455c4f32a659, type: 2} diff --git a/Assets/TcgEngine/Resources/Decks/water_deck.asset b/Assets/TcgEngine/Resources/Decks/water_deck.asset index d8de949..b2196ed 100644 --- a/Assets/TcgEngine/Resources/Decks/water_deck.asset +++ b/Assets/TcgEngine/Resources/Decks/water_deck.asset @@ -13,7 +13,7 @@ MonoBehaviour: m_Name: water_deck m_EditorClassIdentifier: id: water_deck - title: 臻冰 + title: "\u81FB\u51B0" hero: {fileID: 11400000, guid: 111d60b13ae137f4597da2789d94ecce, type: 2} cards: - {fileID: 11400000, guid: 89f3d73097f233148896600d94d482c0, type: 2} @@ -22,5 +22,9 @@ MonoBehaviour: - {fileID: 11400000, guid: 3eb5d82b098a31640981aa400ef099f0, type: 2} - {fileID: 11400000, guid: 3eb5d82b098a31640981aa400ef099f0, type: 2} - {fileID: 11400000, guid: 7522cb2b475fdca45aae97664d79e53c, type: 2} - - {fileID: 11400000, guid: fced434c254f6a94e8377864595757c8, type: 2} - - {fileID: 11400000, guid: fced434c254f6a94e8377864595757c8, type: 2} + - {fileID: 11400000, guid: 89f3d73097f233148896600d94d482c0, type: 2} + - {fileID: 11400000, guid: 6d25f87d5e8912e4aae6b2e8cdb51378, type: 2} + - {fileID: 11400000, guid: e777946125cd2eb49a3b2ac17bea169a, type: 2} + - {fileID: 11400000, guid: 3eb5d82b098a31640981aa400ef099f0, type: 2} + - {fileID: 11400000, guid: 74ffbe8087a7ec64696352b9013d5d21, type: 2} + - {fileID: 11400000, guid: ee0eb5f42cd646d4c92cc5bae97f8512, type: 2} diff --git a/Assets/TcgEngine/Scenes/Game/Game.unity b/Assets/TcgEngine/Scenes/Game/Game.unity index 6c165c7..9e83c86 100644 --- a/Assets/TcgEngine/Scenes/Game/Game.unity +++ b/Assets/TcgEngine/Scenes/Game/Game.unity @@ -2393,6 +2393,16 @@ PrefabInstance: propertyPath: m_Name value: HandsArea objectReference: {fileID: 0} + - target: {fileID: 5110355759202193847, guid: 4f5d06d57a8cd5f42b526a96b940dca7, + type: 3} + propertyPath: usePathMode + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 5110355759202193847, guid: 4f5d06d57a8cd5f42b526a96b940dca7, + type: 3} + propertyPath: cardback_path + value: Cardbacks/cardback_gold.png + objectReference: {fileID: 0} m_RemovedComponents: [] m_SourcePrefab: {fileID: 100100000, guid: 4f5d06d57a8cd5f42b526a96b940dca7, type: 3} --- !u!1001 &5509868164999168658 diff --git a/Assets/TcgEngine/Scripts/GameClient/HandCardBack.cs b/Assets/TcgEngine/Scripts/GameClient/HandCardBack.cs index 48f8cb1..84b7afb 100644 --- a/Assets/TcgEngine/Scripts/GameClient/HandCardBack.cs +++ b/Assets/TcgEngine/Scripts/GameClient/HandCardBack.cs @@ -12,6 +12,9 @@ namespace TcgEngine.Client public class HandCardBack : MonoBehaviour { public Image card_sprite; + + [Header("Dynamic Art Path")] + [SerializeField] private string cardback_path; private RectTransform rect; @@ -21,19 +24,79 @@ namespace TcgEngine.Client { card_list.Add(this); rect = GetComponent(); - SetCardback(null); + + // 如果有设置路径,自动加载 + if (!string.IsNullOrEmpty(cardback_path)) + { + LoadCardbackSprite(); + } + else + { + SetCardback(null); + } } private void OnDestroy() { card_list.Remove(this); } + + /// + /// 在 Inspector 中修改值时自动重新加载 + /// + private void OnValidate() + { + if (Application.isPlaying && !string.IsNullOrEmpty(cardback_path)) + { + LoadCardbackSprite(); + } + } public void SetCardback(CardbackData cb) { if (cb != null) card_sprite.sprite = cb.GetCardback(); } + + /// + /// 设置卡背图片,使用本地图片路径 + /// + public void SetCardbackPath(string path) + { + cardback_path = path; + LoadCardbackSprite(); + } + + /// + /// 获取当前卡背路径 + /// + public string GetCardbackPath() + { + return cardback_path; + } + + /// + /// 加载卡背图片 + /// + private void LoadCardbackSprite() + { + if (!string.IsNullOrEmpty(cardback_path)) + { + Sprite dynamicSprite = SpriteLoader.Get()?.LoadSprite(cardback_path); + if (dynamicSprite != null) + { + card_sprite.sprite = dynamicSprite; + } + else + { + Debug.LogWarning($"HandCardBack 卡背图片加载失败: {cardback_path}"); + } + } + else + { + Debug.LogWarning($"HandCardBack cardback_path为空"); + } + } public RectTransform GetRect() { diff --git a/Assets/TcgEngine/Scripts/GameClient/OpponentHand.cs b/Assets/TcgEngine/Scripts/GameClient/OpponentHand.cs index 35ca081..d0fbb48 100644 --- a/Assets/TcgEngine/Scripts/GameClient/OpponentHand.cs +++ b/Assets/TcgEngine/Scripts/GameClient/OpponentHand.cs @@ -17,6 +17,12 @@ namespace TcgEngine.Client public float card_spacing = 100f; public float card_angle = 10f; public float card_offset_y = 10f; + + [Header("Cardback Settings")] + [Tooltip("是否使用路径方式加载卡背图片")] + public bool usePathMode = false; + [Tooltip("卡背图片路径,仅在 usePathMode 为 true 时使用")] + public string cardback_path = ""; private List cards = new List(); @@ -37,8 +43,20 @@ namespace TcgEngine.Client { GameObject new_card = Instantiate(card_prefab, card_area); HandCardBack hand_card = new_card.GetComponent(); - CardbackData cbdata = CardbackData.Get(player.cardback); - hand_card.SetCardback(cbdata); + + // 根据设置选择加载方式 + if (usePathMode && !string.IsNullOrEmpty(cardback_path)) + { + // 使用路径方式 + hand_card.SetCardbackPath(cardback_path); + } + else + { + // 使用传统的 CardbackData 方式 + CardbackData cbdata = CardbackData.Get(player.cardback); + hand_card.SetCardback(cbdata); + } + RectTransform card_rect = new_card.GetComponent(); card_rect.anchoredPosition = new Vector2(0f, 100f); cards.Add(hand_card);