네트워크 멀티플레이 대응
This commit is contained in:
@@ -4,9 +4,9 @@ using UnityEngine;
|
||||
|
||||
namespace Northbound
|
||||
{
|
||||
public class Building : NetworkBehaviour, IDamageable, IVisionProvider, ITeamMember
|
||||
public class Building : DamageableNetworkBehaviour, IVisionProvider, ITeamMember
|
||||
{
|
||||
[Header("References")]
|
||||
[Header("Building Data")]
|
||||
public BuildingData buildingData;
|
||||
|
||||
[Header("Runtime Info")]
|
||||
@@ -14,52 +14,34 @@ namespace Northbound
|
||||
public int rotation; // 0-3 (0=0°, 1=90°, 2=180°, 3=270°)
|
||||
|
||||
[Header("Team")]
|
||||
[Tooltip("건물의 팀 (플레이어/적대세력/몬스터/중립)")]
|
||||
[Tooltip("Building team (Player/Enemy/Monster/Neutral)")]
|
||||
public TeamType initialTeam = TeamType.Player;
|
||||
|
||||
[Header("Ownership (for pre-placed buildings)")]
|
||||
[Tooltip("씬에 미리 배치된 건물의 경우 여기서 소유자 설정 (0 = 중립, 1+ = 플레이어 ID)")]
|
||||
[Tooltip("For pre-placed buildings, set owner here (0 = neutral, 1+ = player ID)")]
|
||||
public ulong initialOwnerId = 0;
|
||||
[Tooltip("사전 배치 건물인가요? 체크하면 initialOwnerId를 사용합니다")]
|
||||
[Tooltip("Is this a pre-placed building? If checked, uses initialOwnerId")]
|
||||
public bool useInitialOwner = false;
|
||||
|
||||
[Header("Health")]
|
||||
public bool showHealthBar = true;
|
||||
[Header("Health Bar")]
|
||||
public GameObject healthBarPrefab;
|
||||
|
||||
[Header("Visual Effects")]
|
||||
public GameObject destroyEffectPrefab;
|
||||
public GameObject damageEffectPrefab;
|
||||
public Transform effectSpawnPoint;
|
||||
|
||||
[Header("Debug")]
|
||||
public bool showGridBounds = true;
|
||||
public Color gridBoundsColor = Color.cyan;
|
||||
|
||||
// 현재 체력
|
||||
private NetworkVariable<int> _currentHealth = new NetworkVariable<int>(
|
||||
0,
|
||||
NetworkVariableReadPermission.Everyone,
|
||||
NetworkVariableWritePermission.Server
|
||||
);
|
||||
|
||||
// 건물 소유자 (사전 배치 건물 또는 동적 건물 모두 지원)
|
||||
private NetworkVariable<ulong> _ownerId = new NetworkVariable<ulong>(
|
||||
0,
|
||||
NetworkVariableReadPermission.Everyone,
|
||||
NetworkVariableWritePermission.Server
|
||||
);
|
||||
|
||||
// 건물 팀
|
||||
private NetworkVariable<TeamType> _team = new NetworkVariable<TeamType>(
|
||||
TeamType.Neutral,
|
||||
NetworkVariableReadPermission.Everyone,
|
||||
NetworkVariableWritePermission.Server
|
||||
);
|
||||
|
||||
// 이벤트
|
||||
public event Action<int, int> OnHealthChanged; // (current, max)
|
||||
public event Action OnDestroyed;
|
||||
public event Action<TeamType> OnTeamChanged;
|
||||
|
||||
private BuildingHealthBar _healthBar;
|
||||
@@ -70,63 +52,54 @@ namespace Northbound
|
||||
{
|
||||
base.OnNetworkSpawn();
|
||||
|
||||
if (IsServer)
|
||||
if (IsOwner)
|
||||
{
|
||||
// 체력 초기화
|
||||
if (_currentHealth.Value == 0)
|
||||
if (maxHealth == 0)
|
||||
{
|
||||
_currentHealth.Value = buildingData != null ? buildingData.maxHealth : 100;
|
||||
maxHealth = buildingData != null ? buildingData.maxHealth : 100;
|
||||
_currentHealth.Value = maxHealth;
|
||||
}
|
||||
|
||||
// 팀 초기화
|
||||
if (_team.Value == TeamType.Neutral)
|
||||
{
|
||||
_team.Value = initialTeam;
|
||||
}
|
||||
|
||||
// 소유자 초기화 (사전 배치 건물 체크)
|
||||
if (useInitialOwner && _ownerId.Value == 0)
|
||||
{
|
||||
_ownerId.Value = initialOwnerId;
|
||||
// Debug.Log($"<color=cyan>[Building] 사전 배치 건물 '{buildingData?.buildingName ?? gameObject.name}' 소유자: {initialOwnerId}, 팀: {_team.Value}</color>");
|
||||
}
|
||||
else if (!useInitialOwner && _ownerId.Value == 0)
|
||||
{
|
||||
// 동적 생성 건물은 NetworkObject의 Owner 사용
|
||||
_ownerId.Value = OwnerClientId;
|
||||
}
|
||||
|
||||
|
||||
_lastRegenTime = Time.time;
|
||||
|
||||
// FogOfWar 시스템에 시야 제공자로 등록
|
||||
if (buildingData != null && buildingData.providesVision)
|
||||
{
|
||||
FogOfWarSystem.Instance?.RegisterVisionProvider(this);
|
||||
}
|
||||
}
|
||||
|
||||
// 이벤트 구독
|
||||
_currentHealth.OnValueChanged += OnHealthValueChanged;
|
||||
_team.OnValueChanged += OnTeamValueChanged;
|
||||
|
||||
// 체력바 생성
|
||||
if (showHealthBar && healthBarPrefab != null)
|
||||
{
|
||||
CreateHealthBar();
|
||||
base.InitializeHealthBar();
|
||||
}
|
||||
|
||||
// 초기 체력 UI 업데이트
|
||||
UpdateHealthUI();
|
||||
UpdateTeamVisuals();
|
||||
}
|
||||
|
||||
public override void OnNetworkDespawn()
|
||||
{
|
||||
_currentHealth.OnValueChanged -= OnHealthValueChanged;
|
||||
base.OnNetworkDespawn();
|
||||
|
||||
_team.OnValueChanged -= OnTeamValueChanged;
|
||||
|
||||
// FogOfWar 시스템에서 제거
|
||||
if (IsServer && buildingData != null && buildingData.providesVision)
|
||||
if (IsOwner && buildingData != null && buildingData.providesVision)
|
||||
{
|
||||
FogOfWarSystem.Instance?.UnregisterVisionProvider(this);
|
||||
}
|
||||
@@ -134,38 +107,33 @@ namespace Northbound
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (!IsServer || buildingData == null)
|
||||
if (!IsOwner || buildingData == null)
|
||||
return;
|
||||
|
||||
// 자동 체력 회복
|
||||
if (buildingData.autoRegenerate && _currentHealth.Value < buildingData.maxHealth)
|
||||
if (buildingData.autoRegenerate && _currentHealth.Value < maxHealth)
|
||||
{
|
||||
if (Time.time - _lastRegenTime >= 1f)
|
||||
{
|
||||
int regenAmount = Mathf.Min(buildingData.regenPerSecond, buildingData.maxHealth - _currentHealth.Value);
|
||||
int regenAmount = Mathf.Min(buildingData.regenPerSecond, maxHealth - _currentHealth.Value);
|
||||
_currentHealth.Value += regenAmount;
|
||||
_lastRegenTime = Time.time;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 건물 초기화 (BuildingManager가 동적 생성 시 호출)
|
||||
/// </summary>
|
||||
public void Initialize(BuildingData data, Vector3Int gridPos, int rot, ulong ownerId, TeamType team = TeamType.Player)
|
||||
{
|
||||
buildingData = data;
|
||||
gridPosition = gridPos;
|
||||
rotation = rot;
|
||||
|
||||
// 이미 스폰된 경우
|
||||
if (IsServer && IsSpawned)
|
||||
if (IsOwner && IsSpawned)
|
||||
{
|
||||
_currentHealth.Value = data.maxHealth;
|
||||
maxHealth = data.maxHealth;
|
||||
_currentHealth.Value = maxHealth;
|
||||
_ownerId.Value = ownerId;
|
||||
_team.Value = team;
|
||||
|
||||
// 시야 제공자 등록
|
||||
|
||||
if (data.providesVision)
|
||||
{
|
||||
FogOfWarSystem.Instance?.RegisterVisionProvider(this);
|
||||
@@ -175,22 +143,28 @@ namespace Northbound
|
||||
_isInitialized = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 건물 소유권 변경 (점령 등)
|
||||
/// </summary>
|
||||
public void SetOwner(ulong newOwnerId, TeamType newTeam)
|
||||
{
|
||||
if (!IsServer) return;
|
||||
if (!IsOwner)
|
||||
{
|
||||
SetOwnerServerRpc(newOwnerId, newTeam);
|
||||
return;
|
||||
}
|
||||
|
||||
SetOwnerServerRpc(newOwnerId, newTeam);
|
||||
}
|
||||
|
||||
[ServerRpc]
|
||||
private void SetOwnerServerRpc(ulong newOwnerId, TeamType newTeam)
|
||||
{
|
||||
ulong previousOwner = _ownerId.Value;
|
||||
TeamType previousTeam = _team.Value;
|
||||
|
||||
|
||||
_ownerId.Value = newOwnerId;
|
||||
_team.Value = newTeam;
|
||||
|
||||
Debug.Log($"<color=yellow>[Building] {buildingData?.buildingName ?? "건물"} 소유권 변경: {previousOwner} → {newOwnerId}, 팀: {TeamManager.GetTeamName(previousTeam)} → {TeamManager.GetTeamName(newTeam)}</color>");
|
||||
Debug.Log($"<color=yellow>[Building] {buildingData?.buildingName ?? "Building"} ownership changed: {previousOwner} → {newOwnerId}, team: {TeamManager.GetTeamName(previousTeam)} → {TeamManager.GetTeamName(newTeam)}</color>");
|
||||
|
||||
// 시야 제공자 재등록 (소유자가 바뀌었으므로)
|
||||
if (buildingData != null && buildingData.providesVision)
|
||||
{
|
||||
FogOfWarSystem.Instance?.UnregisterVisionProvider(this);
|
||||
@@ -204,7 +178,18 @@ namespace Northbound
|
||||
|
||||
public void SetTeam(TeamType team)
|
||||
{
|
||||
if (!IsServer) return;
|
||||
if (!IsOwner)
|
||||
{
|
||||
SetTeamServerRpc(team);
|
||||
return;
|
||||
}
|
||||
|
||||
SetTeamServerRpc(team);
|
||||
}
|
||||
|
||||
[ServerRpc]
|
||||
private void SetTeamServerRpc(TeamType team)
|
||||
{
|
||||
_team.Value = team;
|
||||
}
|
||||
|
||||
@@ -212,17 +197,12 @@ namespace Northbound
|
||||
{
|
||||
OnTeamChanged?.Invoke(newValue);
|
||||
UpdateTeamVisuals();
|
||||
Debug.Log($"<color=cyan>[Building] {buildingData?.buildingName ?? "건물"} 팀 변경: {TeamManager.GetTeamName(previousValue)} → {TeamManager.GetTeamName(newValue)}</color>");
|
||||
Debug.Log($"<color=cyan>[Building] {buildingData?.buildingName ?? "Building"} team changed: {TeamManager.GetTeamName(previousValue)} → {TeamManager.GetTeamName(newValue)}</color>");
|
||||
}
|
||||
|
||||
private void UpdateTeamVisuals()
|
||||
{
|
||||
// 팀 색상으로 건물 외곽선이나 이펙트 변경 가능
|
||||
// 예: Renderer의 emission 색상 변경
|
||||
Color teamColor = TeamManager.GetTeamColor(_team.Value);
|
||||
|
||||
// 여기에 실제 비주얼 업데이트 로직 추가
|
||||
// 예: outline shader, emission, particle system 색상 등
|
||||
}
|
||||
|
||||
#endregion
|
||||
@@ -240,65 +220,85 @@ namespace Northbound
|
||||
|
||||
public bool IsActive()
|
||||
{
|
||||
// 건물이 스폰되어 있고, 파괴되지 않았으며, 시야 제공 설정이 켜져있어야 함
|
||||
return IsSpawned && !IsDestroyed() && buildingData != null && buildingData.providesVision;
|
||||
return IsSpawned && !IsDead() && buildingData != null && buildingData.providesVision;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IDamageable Implementation
|
||||
#region IDamageable Overrides
|
||||
|
||||
public void TakeDamage(int damage, ulong attackerId)
|
||||
protected override void Die(ulong killerId)
|
||||
{
|
||||
if (!IsServer)
|
||||
base.Die(killerId);
|
||||
|
||||
if (!IsOwner) return;
|
||||
|
||||
Debug.Log($"<color=red>[Building] {buildingData?.buildingName ?? "Building"} ({TeamManager.GetTeamName(_team.Value)}) destroyed! Attacker: {killerId}</color>");
|
||||
|
||||
InvokeOnDestroyed();
|
||||
NotifyDestroyedClientRpc();
|
||||
|
||||
if (buildingData != null && buildingData.providesVision)
|
||||
{
|
||||
// 클라이언트는 서버에 요청
|
||||
TakeDamageServerRpc(damage, attackerId);
|
||||
FogOfWarSystem.Instance?.UnregisterVisionProvider(this);
|
||||
}
|
||||
|
||||
if (BuildingManager.Instance != null)
|
||||
{
|
||||
BuildingManager.Instance.RemoveBuilding(this);
|
||||
}
|
||||
|
||||
Invoke(nameof(DespawnBuilding), 0.5f);
|
||||
}
|
||||
|
||||
private void DespawnBuilding()
|
||||
{
|
||||
if (IsOwner && NetworkObject != null)
|
||||
{
|
||||
NetworkObject.Despawn(true);
|
||||
}
|
||||
}
|
||||
|
||||
[ClientRpc]
|
||||
private void NotifyDestroyedClientRpc()
|
||||
{
|
||||
if (!IsOwner)
|
||||
{
|
||||
InvokeOnDestroyed();
|
||||
}
|
||||
}
|
||||
|
||||
public override void TakeDamage(int damage, ulong attackerId)
|
||||
{
|
||||
if (!IsOwner)
|
||||
{
|
||||
TakeDamageOwnerRpc(damage, attackerId);
|
||||
return;
|
||||
}
|
||||
|
||||
// 무적 건물
|
||||
if (buildingData != null && buildingData.isIndestructible)
|
||||
{
|
||||
Debug.Log($"<color=yellow>[Building] {buildingData.buildingName}은(는) 무적입니다.</color>");
|
||||
Debug.Log($"<color=yellow>[Building] {buildingData.buildingName} is indestructible.</color>");
|
||||
return;
|
||||
}
|
||||
|
||||
// 이미 파괴됨
|
||||
if (_currentHealth.Value <= 0)
|
||||
return;
|
||||
|
||||
// 공격자의 팀 확인 (팀 공격 방지)
|
||||
var attackerObj = NetworkManager.Singleton.SpawnManager.SpawnedObjects[attackerId];
|
||||
var attackerTeamMember = attackerObj?.GetComponent<ITeamMember>();
|
||||
|
||||
|
||||
if (attackerTeamMember != null)
|
||||
{
|
||||
if (!TeamManager.CanAttack(attackerTeamMember, this))
|
||||
{
|
||||
Debug.Log($"<color=yellow>[Building] {TeamManager.GetTeamName(attackerTeamMember.GetTeam())} 팀은 {TeamManager.GetTeamName(_team.Value)} 팀을 공격할 수 없습니다.</color>");
|
||||
Debug.Log($"<color=yellow>[Building] {TeamManager.GetTeamName(attackerTeamMember.GetTeam())} team cannot attack {TeamManager.GetTeamName(_team.Value)} team.</color>");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// 데미지 적용
|
||||
int actualDamage = Mathf.Min(damage, _currentHealth.Value);
|
||||
_currentHealth.Value -= actualDamage;
|
||||
|
||||
Debug.Log($"<color=red>[Building] {buildingData?.buildingName ?? "건물"} ({TeamManager.GetTeamName(_team.Value)})이(가) {actualDamage} 데미지를 받았습니다. 남은 체력: {_currentHealth.Value}/{buildingData?.maxHealth ?? 100}</color>");
|
||||
|
||||
// 데미지 이펙트
|
||||
ShowDamageEffectClientRpc();
|
||||
|
||||
// 체력이 0이 되면 파괴
|
||||
if (_currentHealth.Value <= 0)
|
||||
{
|
||||
DestroyBuilding(attackerId);
|
||||
}
|
||||
base.TakeDamage(damage, attackerId);
|
||||
}
|
||||
|
||||
[Rpc(SendTo.Server)]
|
||||
private void TakeDamageServerRpc(int damage, ulong attackerId)
|
||||
[Rpc(SendTo.Owner)]
|
||||
private void TakeDamageOwnerRpc(int damage, ulong attackerId)
|
||||
{
|
||||
TakeDamage(damage, attackerId);
|
||||
}
|
||||
@@ -307,179 +307,63 @@ namespace Northbound
|
||||
|
||||
#region Health Management
|
||||
|
||||
/// <summary>
|
||||
/// 건물 파괴
|
||||
/// </summary>
|
||||
private void DestroyBuilding(ulong attackerId)
|
||||
public new int GetMaxHealth()
|
||||
{
|
||||
if (!IsServer)
|
||||
return;
|
||||
|
||||
Debug.Log($"<color=red>[Building] {buildingData?.buildingName ?? "건물"} ({TeamManager.GetTeamName(_team.Value)})이(가) 파괴되었습니다! (공격자: {attackerId})</color>");
|
||||
|
||||
// 파괴 이벤트 발생
|
||||
OnDestroyed?.Invoke();
|
||||
NotifyDestroyedClientRpc();
|
||||
|
||||
// 파괴 이펙트
|
||||
ShowDestroyEffectClientRpc();
|
||||
|
||||
// FogOfWar 시스템에서 제거
|
||||
if (buildingData != null && buildingData.providesVision)
|
||||
{
|
||||
FogOfWarSystem.Instance?.UnregisterVisionProvider(this);
|
||||
}
|
||||
|
||||
// BuildingManager에서 제거
|
||||
if (BuildingManager.Instance != null)
|
||||
{
|
||||
BuildingManager.Instance.RemoveBuilding(this);
|
||||
}
|
||||
|
||||
// 네트워크 오브젝트 파괴 (약간의 딜레이)
|
||||
Invoke(nameof(DespawnBuilding), 0.5f);
|
||||
return buildingData != null ? buildingData.maxHealth : 100;
|
||||
}
|
||||
|
||||
private void DespawnBuilding()
|
||||
public new float GetHealthPercentage()
|
||||
{
|
||||
if (IsServer && NetworkObject != null)
|
||||
{
|
||||
NetworkObject.Despawn(true);
|
||||
}
|
||||
int maxHp = GetMaxHealth();
|
||||
return maxHp > 0 ? (float)_currentHealth.Value / maxHp : 0f;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 체력 회복
|
||||
/// </summary>
|
||||
public void Heal(int amount)
|
||||
{
|
||||
if (!IsServer)
|
||||
return;
|
||||
|
||||
if (buildingData == null)
|
||||
return;
|
||||
|
||||
int healAmount = Mathf.Min(amount, buildingData.maxHealth - _currentHealth.Value);
|
||||
_currentHealth.Value += healAmount;
|
||||
|
||||
Debug.Log($"<color=green>[Building] {buildingData.buildingName}이(가) {healAmount} 회복되었습니다. 현재 체력: {_currentHealth.Value}/{buildingData.maxHealth}</color>");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 현재 체력
|
||||
/// </summary>
|
||||
public int GetCurrentHealth() => _currentHealth.Value;
|
||||
|
||||
/// <summary>
|
||||
/// 최대 체력
|
||||
/// </summary>
|
||||
public int GetMaxHealth() => buildingData != null ? buildingData.maxHealth : 100;
|
||||
|
||||
/// <summary>
|
||||
/// 체력 비율 (0.0 ~ 1.0)
|
||||
/// </summary>
|
||||
public float GetHealthPercentage()
|
||||
{
|
||||
int maxHealth = GetMaxHealth();
|
||||
return maxHealth > 0 ? (float)_currentHealth.Value / maxHealth : 0f;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 파괴되었는지 여부
|
||||
/// </summary>
|
||||
public bool IsDestroyed() => _currentHealth.Value <= 0;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Health UI
|
||||
|
||||
private void CreateHealthBar()
|
||||
protected override void InitializeHealthBar()
|
||||
{
|
||||
if (_healthBar != null)
|
||||
return;
|
||||
|
||||
GameObject healthBarObj = Instantiate(healthBarPrefab, transform);
|
||||
_healthBar = healthBarObj.GetComponent<BuildingHealthBar>();
|
||||
|
||||
if (_healthBar != null)
|
||||
if (healthBarPrefab != null)
|
||||
{
|
||||
_healthBar.Initialize(this);
|
||||
GameObject healthBarObj = Instantiate(healthBarPrefab, transform);
|
||||
_healthBar = healthBarObj.GetComponent<BuildingHealthBar>();
|
||||
|
||||
if (_healthBar != null)
|
||||
{
|
||||
_healthBar.Initialize(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateHealthUI()
|
||||
protected override void UpdateHealthUI()
|
||||
{
|
||||
if (_healthBar != null)
|
||||
{
|
||||
_healthBar.UpdateHealth(_currentHealth.Value, GetMaxHealth());
|
||||
}
|
||||
|
||||
OnHealthChanged?.Invoke(_currentHealth.Value, GetMaxHealth());
|
||||
}
|
||||
|
||||
private void OnHealthValueChanged(int previousValue, int newValue)
|
||||
{
|
||||
UpdateHealthUI();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Visual Effects
|
||||
|
||||
[ClientRpc]
|
||||
private void ShowDamageEffectClientRpc()
|
||||
{
|
||||
if (damageEffectPrefab != null)
|
||||
{
|
||||
Transform spawnPoint = effectSpawnPoint != null ? effectSpawnPoint : transform;
|
||||
GameObject effect = Instantiate(damageEffectPrefab, spawnPoint.position, spawnPoint.rotation);
|
||||
Destroy(effect, 2f);
|
||||
}
|
||||
}
|
||||
|
||||
[ClientRpc]
|
||||
private void ShowDestroyEffectClientRpc()
|
||||
{
|
||||
if (destroyEffectPrefab != null)
|
||||
{
|
||||
Transform spawnPoint = effectSpawnPoint != null ? effectSpawnPoint : transform;
|
||||
GameObject effect = Instantiate(destroyEffectPrefab, spawnPoint.position, spawnPoint.rotation);
|
||||
Destroy(effect, 3f);
|
||||
}
|
||||
}
|
||||
|
||||
[ClientRpc]
|
||||
private void NotifyDestroyedClientRpc()
|
||||
{
|
||||
if (!IsServer)
|
||||
{
|
||||
OnDestroyed?.Invoke();
|
||||
}
|
||||
InvokeOnHealthChanged(_currentHealth.Value, GetMaxHealth());
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Grid Bounds
|
||||
|
||||
/// <summary>
|
||||
/// Gets the grid-based bounds (from BuildingData width/length/height)
|
||||
/// This is used for placement validation, NOT the actual collider bounds
|
||||
/// Bounds are slightly shrunk to allow adjacent buildings to touch
|
||||
/// </summary>
|
||||
public Bounds GetGridBounds()
|
||||
{
|
||||
if (buildingData == null) return new Bounds(transform.position, Vector3.one);
|
||||
|
||||
Vector3 gridSize = buildingData.GetSize(rotation);
|
||||
|
||||
// Shrink slightly to allow buildings to be adjacent without Intersects() returning true
|
||||
Vector3 shrunkSize = gridSize - Vector3.one * 0.01f;
|
||||
return new Bounds(transform.position + Vector3.up * gridSize.y * 0.5f, shrunkSize);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Legacy method, use GetGridBounds() instead
|
||||
/// </summary>
|
||||
public Bounds GetBounds()
|
||||
{
|
||||
return GetGridBounds();
|
||||
@@ -495,50 +379,15 @@ namespace Northbound
|
||||
|
||||
Bounds bounds = GetGridBounds();
|
||||
|
||||
// 팀 색상으로 표시
|
||||
Color teamColor = Application.isPlaying ? TeamManager.GetTeamColor(_team.Value) : TeamManager.GetTeamColor(initialTeam);
|
||||
Gizmos.color = new Color(teamColor.r, teamColor.g, teamColor.b, 0.3f);
|
||||
Gizmos.DrawWireCube(bounds.center, bounds.size);
|
||||
}
|
||||
|
||||
private void OnDrawGizmosSelected()
|
||||
{
|
||||
if (buildingData == null) return;
|
||||
Gizmos.color = teamColor;
|
||||
Gizmos.DrawWireSphere(transform.position + Vector3.up * 2f, 0.5f);
|
||||
|
||||
Bounds bounds = GetGridBounds();
|
||||
Gizmos.color = Color.yellow;
|
||||
Gizmos.DrawWireCube(bounds.center, bounds.size);
|
||||
|
||||
// Draw grid position
|
||||
if (BuildingManager.Instance != null)
|
||||
{
|
||||
Vector3 worldPos = BuildingManager.Instance.GridToWorld(gridPosition);
|
||||
Gizmos.color = Color.magenta;
|
||||
Gizmos.DrawSphere(worldPos, 0.2f);
|
||||
}
|
||||
|
||||
// Draw vision range (if provides vision)
|
||||
if (buildingData.providesVision)
|
||||
{
|
||||
Gizmos.color = Color.cyan;
|
||||
Gizmos.DrawWireSphere(transform.position, buildingData.visionRange);
|
||||
}
|
||||
|
||||
// Draw team info label
|
||||
#if UNITY_EDITOR
|
||||
if (Application.isPlaying)
|
||||
{
|
||||
string teamName = TeamManager.GetTeamName(_team.Value);
|
||||
UnityEditor.Handles.Label(transform.position + Vector3.up * 3f,
|
||||
$"Owner: {_ownerId.Value}\nTeam: {teamName}");
|
||||
}
|
||||
else if (useInitialOwner)
|
||||
{
|
||||
string teamName = TeamManager.GetTeamName(initialTeam);
|
||||
UnityEditor.Handles.Label(transform.position + Vector3.up * 3f,
|
||||
$"Initial Owner: {initialOwnerId}\nTeam: {teamName}");
|
||||
}
|
||||
#endif
|
||||
UnityEditor.Handles.Label(transform.position + Vector3.up * 3f,
|
||||
$"{buildingData.buildingName}\nHP: {_currentHealth.Value}/{maxHealth}");
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
Reference in New Issue
Block a user