``` docs(readme): 更新文档说明 - 添加项目使用指南 - 完善API接口描述 - 修正错误的配置示例 ``` 注意:由于您提供的code differences部分为空,无法确定具体的变更类型和范围。实际使用时请根据真实变更内容替换相应的type、scope、subject和body信息。
129 lines
3.6 KiB
C#
129 lines
3.6 KiB
C#
using UnityEngine;
|
|
using System.Collections.Generic;
|
|
|
|
/// <summary>
|
|
/// 增益系统管理器(单例)
|
|
/// 管理全局增益效果的应用
|
|
/// </summary>
|
|
public class BuffSystem : MonoBehaviour
|
|
{
|
|
private static BuffSystem instance;
|
|
public static BuffSystem Instance
|
|
{
|
|
get
|
|
{
|
|
if (instance == null)
|
|
{
|
|
var go = new GameObject("BuffSystem");
|
|
instance = go.AddComponent<BuffSystem>();
|
|
DontDestroyOnLoad(go);
|
|
}
|
|
return instance;
|
|
}
|
|
}
|
|
|
|
private void Awake()
|
|
{
|
|
if (instance != null && instance != this)
|
|
{
|
|
Destroy(gameObject);
|
|
return;
|
|
}
|
|
instance = this;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 应用群体治疗增益
|
|
/// </summary>
|
|
public void ApplyGroupHeal(float healAmount)
|
|
{
|
|
var allies = FindObjectsOfType<UnitBase>();
|
|
int healedCount = 0;
|
|
|
|
foreach (var unit in allies)
|
|
{
|
|
var team = unit.GetComponent<UnitTeam>();
|
|
if (team != null && team.teamId == 0) // 友方
|
|
{
|
|
var healthBar = unit.GetComponent<WorldHealthBar>();
|
|
if (healthBar != null)
|
|
{
|
|
healthBar.Heal(healAmount);
|
|
healedCount++;
|
|
}
|
|
}
|
|
}
|
|
|
|
Debug.Log($"群体治疗:治疗了 {healedCount} 个友方单位,每个恢复 {healAmount} 生命");
|
|
}
|
|
|
|
/// <summary>
|
|
/// 应用全局攻速增益
|
|
/// </summary>
|
|
public void ApplyGlobalAttackSpeedBuff(float speedMultiplier)
|
|
{
|
|
var allies = FindObjectsOfType<UnitBase>();
|
|
int buffedCount = 0;
|
|
|
|
foreach (var unit in allies)
|
|
{
|
|
var team = unit.GetComponent<UnitTeam>();
|
|
if (team != null && team.teamId == 0) // 友方
|
|
{
|
|
// 使用 UnitBase 的攻速倍增系统
|
|
unit.MultiplyAttackSpeed(speedMultiplier, 3f); // 最高3倍攻速
|
|
buffedCount++;
|
|
}
|
|
}
|
|
|
|
Debug.Log($"全局攻速增益:{buffedCount} 个友方单位攻速提升 {(speedMultiplier - 1) * 100}%");
|
|
}
|
|
|
|
/// <summary>
|
|
/// 应用全局攻击力增益
|
|
/// </summary>
|
|
public void ApplyGlobalAttackBuff(float attackMultiplier)
|
|
{
|
|
var allies = FindObjectsOfType<UnitBase>();
|
|
int buffedCount = 0;
|
|
|
|
foreach (var unit in allies)
|
|
{
|
|
var team = unit.GetComponent<UnitTeam>();
|
|
if (team != null && team.teamId == 0) // 友方
|
|
{
|
|
unit.attackPower *= attackMultiplier;
|
|
buffedCount++;
|
|
}
|
|
}
|
|
|
|
Debug.Log($"全局攻击增益:{buffedCount} 个友方单位攻击力提升 {(attackMultiplier - 1) * 100}%");
|
|
}
|
|
|
|
/// <summary>
|
|
/// 应用全局生命增益
|
|
/// </summary>
|
|
public void ApplyGlobalHealthBuff(float healthMultiplier)
|
|
{
|
|
var allies = FindObjectsOfType<UnitBase>();
|
|
int buffedCount = 0;
|
|
|
|
foreach (var unit in allies)
|
|
{
|
|
var team = unit.GetComponent<UnitTeam>();
|
|
if (team != null && team.teamId == 0) // 友方
|
|
{
|
|
var healthBar = unit.GetComponent<WorldHealthBar>();
|
|
if (healthBar != null)
|
|
{
|
|
healthBar.maxHealth *= healthMultiplier;
|
|
healthBar.currentHealth *= healthMultiplier;
|
|
buffedCount++;
|
|
}
|
|
}
|
|
}
|
|
|
|
Debug.Log($"全局生命增益:{buffedCount} 个友方单位生命值提升 {(healthMultiplier - 1) * 100}%");
|
|
}
|
|
}
|