using UnityEngine; using System.Collections.Generic; /// /// 增益系统管理器(单例) /// 管理全局增益效果的应用 /// public class BuffSystem : MonoBehaviour { private static BuffSystem instance; public static BuffSystem Instance { get { if (instance == null) { var go = new GameObject("BuffSystem"); instance = go.AddComponent(); DontDestroyOnLoad(go); } return instance; } } private void Awake() { if (instance != null && instance != this) { Destroy(gameObject); return; } instance = this; } /// /// 应用群体治疗增益 /// public void ApplyGroupHeal(float healAmount) { var allies = FindObjectsOfType(); int healedCount = 0; foreach (var unit in allies) { var team = unit.GetComponent(); if (team != null && team.teamId == 0) // 友方 { var healthBar = unit.GetComponent(); if (healthBar != null) { healthBar.Heal(healAmount); healedCount++; } } } Debug.Log($"群体治疗:治疗了 {healedCount} 个友方单位,每个恢复 {healAmount} 生命"); } /// /// 应用全局攻速增益 /// public void ApplyGlobalAttackSpeedBuff(float speedMultiplier) { var allies = FindObjectsOfType(); int buffedCount = 0; foreach (var unit in allies) { var team = unit.GetComponent(); if (team != null && team.teamId == 0) // 友方 { // 使用 UnitBase 的攻速倍增系统 unit.MultiplyAttackSpeed(speedMultiplier, 3f); // 最高3倍攻速 buffedCount++; } } Debug.Log($"全局攻速增益:{buffedCount} 个友方单位攻速提升 {(speedMultiplier - 1) * 100}%"); } /// /// 应用全局攻击力增益 /// public void ApplyGlobalAttackBuff(float attackMultiplier) { var allies = FindObjectsOfType(); int buffedCount = 0; foreach (var unit in allies) { var team = unit.GetComponent(); if (team != null && team.teamId == 0) // 友方 { unit.attackPower *= attackMultiplier; buffedCount++; } } Debug.Log($"全局攻击增益:{buffedCount} 个友方单位攻击力提升 {(attackMultiplier - 1) * 100}%"); } /// /// 应用全局生命增益 /// public void ApplyGlobalHealthBuff(float healthMultiplier) { var allies = FindObjectsOfType(); int buffedCount = 0; foreach (var unit in allies) { var team = unit.GetComponent(); if (team != null && team.teamId == 0) // 友方 { var healthBar = unit.GetComponent(); if (healthBar != null) { healthBar.maxHealth *= healthMultiplier; healthBar.currentHealth *= healthMultiplier; buffedCount++; } } } Debug.Log($"全局生命增益:{buffedCount} 个友方单位生命值提升 {(healthMultiplier - 1) * 100}%"); } }