using UnityEngine;
///
/// 单位阵营标记:用阵营 ID 替代 Unity Tag 判断敌我关系。
/// 支持 PVP:客户端只需设置 GameManager.LocalPlayerTeamId,所有单位的敌我判断自动正确。
///
public class UnitTeam : MonoBehaviour
{
[Header("阵营 ID")]
[Tooltip("0 = 玩家1阵营,1 = 玩家2阵营,2+ = 其他阵营")]
public int teamId = 0;
///
/// 判断目标是否为敌人(不同阵营)
///
public bool IsEnemy(GameObject other)
{
if (other == null) return false;
var otherTeam = other.GetComponent();
if (otherTeam == null) return false;
return otherTeam.teamId != this.teamId;
}
///
/// 判断目标是否为友军(相同阵营)
///
public bool IsFriendly(GameObject other)
{
if (other == null) return false;
var otherTeam = other.GetComponent();
if (otherTeam == null) return false;
return otherTeam.teamId == this.teamId;
}
///
/// 判断是否属于本地玩家阵营
///
public bool IsLocalPlayerTeam()
{
if (GameManager.Instance == null) return teamId == 0;
return teamId == GameManager.Instance.LocalPlayerTeamId;
}
}