Minimap!
This commit is contained in:
parent
f7720a9915
commit
6c37e569ab
18 changed files with 1169 additions and 323 deletions
|
|
@ -4,6 +4,7 @@ using Unity.Netcode;
|
|||
using UnityEngine;
|
||||
using TD.Core;
|
||||
using TD.Towers;
|
||||
using TD.UI.Minimap;
|
||||
|
||||
namespace TD.Gameplay
|
||||
{
|
||||
|
|
@ -42,7 +43,7 @@ namespace TD.Gameplay
|
|||
/// <c>TowerCombat</c> component added to the same prefab.</para>
|
||||
/// </remarks>
|
||||
[RequireComponent(typeof(NetworkObject))]
|
||||
public class TowerInstance : NetworkBehaviour
|
||||
public class TowerInstance : NetworkBehaviour, IMinimapEntity
|
||||
{
|
||||
// ----- Networked state ------------------------------------------------
|
||||
|
||||
|
|
@ -167,6 +168,9 @@ namespace TD.Gameplay
|
|||
// Apply owner color to the mesh renderer.
|
||||
ApplyOwnerColor();
|
||||
|
||||
// Register for minimap rendering.
|
||||
MinimapEntityRegistry.Register(this);
|
||||
|
||||
if (resolvedDefinition != null)
|
||||
{
|
||||
Debug.Log($"[TowerInstance] Spawned '{resolvedDefinition.DisplayName}' " +
|
||||
|
|
@ -180,6 +184,33 @@ namespace TD.Gameplay
|
|||
// Un-stamp the footprint when the tower is destroyed (sold, wave end, etc.)
|
||||
// so the tiles become walkable and buildable again.
|
||||
StampFootprint(walkable: true, occupied: false);
|
||||
|
||||
MinimapEntityRegistry.Deregister(this);
|
||||
}
|
||||
|
||||
// ----- IMinimapEntity -------------------------------------------------
|
||||
//
|
||||
// Towers are static, so WorldPosition is cheap (no movement to track). Color reflects
|
||||
// the replicated ownerSlot; reads safely on every client because ownerSlot is set in
|
||||
// OnNetworkSpawn before this entity is added to the registry.
|
||||
|
||||
Vector3 IMinimapEntity.WorldPosition => transform.position;
|
||||
Color IMinimapEntity.MinimapColor => PlayerColors.Get(ownerSlot.Value);
|
||||
MinimapIconKind IMinimapEntity.IconKind => MinimapIconKind.Tower;
|
||||
|
||||
// Tower footprint in world units. Uses the larger axis if the footprint isn't square,
|
||||
// so an Nx1 tower still occupies its full long-side on the minimap.
|
||||
// Falls back to one tile if the definition hasn't resolved yet (transient, harmless).
|
||||
float IMinimapEntity.MinimapWorldSize
|
||||
{
|
||||
get
|
||||
{
|
||||
if (resolvedDefinition == null) return GridCoordinates.TILE_SIZE;
|
||||
int extent = Mathf.Max(
|
||||
resolvedDefinition.FootprintSize.x,
|
||||
resolvedDefinition.FootprintSize.y);
|
||||
return extent * GridCoordinates.TILE_SIZE;
|
||||
}
|
||||
}
|
||||
|
||||
// ----- Private helpers ------------------------------------------------
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue