using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class BuffSelectionController : MonoBehaviour { private static BuffSelectionController _instance; public static BuffSelectionController Instance { get { if (_instance == null) { _instance = FindObjectOfType(); if (_instance == null) { var canvas = GameObject.Find("TowerDefenseCanvas"); var targetObj = canvas != null ? canvas : new GameObject("BuffSelectionControllerManager"); _instance = targetObj.AddComponent(); } } return _instance; } } public static float KillGoldMultiplier = 1.0f; // 全局击杀金币收益倍率 public enum BuffType { AttackPower, // 1. 攻击力 (+6% / +12% / +20%) MaxHealth, // 2. 最大生命值 (+10% / +18% / +30%) AttackSpeed, // 3. 攻击速度 (+5% / +10% / +16%) CritRate, // 4. 暴击率 (+6% / +12% / +20%) Lifesteal, // 5. 通用吸血 (+4% / +8% / +14%) SkillCharge, // 6. 技能充能 (+8% / +15% / +25%) SummonerCD, // 7. 召唤师技能CD (-5% / -10% / -18%) SummonerPower, // 8. 召唤师技能威力 (+8% / +15% / +25%) AttackRange, // 9. 攻击射程 (+0.5米 / +1.0米 / +1.8米) DamageReduction, // 10. 伤害减免 (+5% / +10% / +16%) Shield, // 11. 护盾生成 (15% / 25% / 40% MaxHP) KillGold, // 12. 击杀金币 (+15% / +30% / +50%) GoldBonus, // 特殊 1: 招财进宝 (+30 / +60 / +100 金币) EmergencyHeal // 特殊 2: 紧急救急 (恢复 25% / 40% / 60% HP) } public enum BuffQuality { Common, // 初级 (白色 55%) Rare, // 中级 (紫色 35%) Epic // 高级 (金色 10%) } public class BuffOption { public BuffType type; public BuffQuality quality; public int targetHeroIndex; // -1 表示【全体英雄】或【全局】,0~4 表示指定单体英雄 public string targetName; public float rawValue; // 单体原始加成数值 (如 0.06f) public float finalValue; // 计算 40% 折扣后的最终加成数值 public string titleText; public string descText; public Color qualityColor; public string qualityName; public Sprite iconSprite; // 英雄头像 / 全体头像 } [Header("UI 节点引用")] public GameObject buffSelectionWindow; public Transform cardsContainer; [Header("品质边框 Sprites")] public Sprite commonBorderSprite; // 铜 (初级) public Sprite rareBorderSprite; // 银 (中级) public Sprite epicBorderSprite; // 金 (高级) public Sprite legendaryBorderSprite; // 红 (最高级) [Header("头像 Sprites")] public Sprite allIconSprite; // 全体/全局头像 (all.png) private bool isWindowShowing = false; private void Awake() { if (_instance == null) { _instance = this; } } /// /// 触发 3 选 1 增益弹窗(自动暂停游戏) /// public void ShowBuffSelection() { if (isWindowShowing) return; EnsureUIReferences(); if (buffSelectionWindow == null || cardsContainer == null) { Debug.LogWarning("BuffSelectionController: UI 节点缺失,无法弹出 3 选 1。"); return; } // 生成 3 个随机卡片 List options = GenerateThreeOptions(); RenderOptionsUI(options); buffSelectionWindow.SetActive(true); isWindowShowing = true; Time.timeScale = 0f; // 暂停游戏让玩家做选择 } private void RenderOptionsUI(List options) { int cardCount = cardsContainer.childCount; for (int i = 0; i < cardCount; i++) { var card = cardsContainer.GetChild(i); if (i < options.Count) { card.gameObject.SetActive(true); SetupCardUI(card, options[i]); } else { card.gameObject.SetActive(false); } } } private void SetupCardUI(Transform cardTransform, BuffOption option) { Text buffNameText = cardTransform.Find("BuffName")?.GetComponent(); Text descText = cardTransform.Find("Description")?.GetComponent(); if (buffNameText != null) { buffNameText.text = $"[{option.qualityName}] {option.titleText}"; buffNameText.color = option.qualityColor; } if (descText != null) { descText.text = option.descText; } // 设置目标英雄 / 全体 Icon 头像 Image iconImage = cardTransform.Find("Icon")?.GetComponent(); if (iconImage != null && option.iconSprite != null) { iconImage.sprite = option.iconSprite; iconImage.enabled = true; } // 设置品质边框 (仅更换 buffImage 节点的源图像,不修改缩放和位置) Image borderImage = cardTransform.Find("buffImage")?.GetComponent(); if (borderImage != null) { Sprite borderSprite = GetQualityBorderSprite(option.quality); if (borderSprite != null) { borderImage.sprite = borderSprite; } } // 卡牌整体点击选定 Button selectBtn = cardTransform.GetComponent