``` docs(changelog): 更新项目变更日志 - 添加新的版本记录 - 修正已知问题描述 - 更新功能特性说明 ``` 注意:由于您提供的code differences部分为空,以上是一个示例模板。实际使用时请根据具体的代码变更内容来填写相应的type、scope、subject和body信息。
48 lines
1.3 KiB
C#
48 lines
1.3 KiB
C#
using UnityEngine;
|
|
|
|
/// <summary>
|
|
/// 单位阵营标记:用阵营 ID 替代 Unity Tag 判断敌我关系。
|
|
/// 支持 PVP:客户端只需设置 GameManager.LocalPlayerTeamId,所有单位的敌我判断自动正确。
|
|
/// </summary>
|
|
public class UnitTeam : MonoBehaviour
|
|
{
|
|
[Header("阵营 ID")]
|
|
[Tooltip("0 = 玩家1阵营,1 = 玩家2阵营,2+ = 其他阵营")]
|
|
public int teamId = 0;
|
|
|
|
/// <summary>
|
|
/// 判断目标是否为敌人(不同阵营)
|
|
/// </summary>
|
|
public bool IsEnemy(GameObject other)
|
|
{
|
|
if (other == null) return false;
|
|
|
|
var otherTeam = other.GetComponent<UnitTeam>();
|
|
if (otherTeam == null) return false;
|
|
|
|
return otherTeam.teamId != this.teamId;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 判断目标是否为友军(相同阵营)
|
|
/// </summary>
|
|
public bool IsFriendly(GameObject other)
|
|
{
|
|
if (other == null) return false;
|
|
|
|
var otherTeam = other.GetComponent<UnitTeam>();
|
|
if (otherTeam == null) return false;
|
|
|
|
return otherTeam.teamId == this.teamId;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 判断是否属于本地玩家阵营
|
|
/// </summary>
|
|
public bool IsLocalPlayerTeam()
|
|
{
|
|
if (GameManager.Instance == null) return teamId == 0;
|
|
return teamId == GameManager.Instance.LocalPlayerTeamId;
|
|
}
|
|
}
|