Fix sell hitch: batch footprint un-stamp; warn on missing SellEffectSpawner
TowerInstance.StampFootprint now writes walkability via SetWalkableBatch instead of per-tile SetWalkable, so despawning (selling) a 2x2 tower fires one OnWalkabilityChanged / enemy re-path instead of four — matching placement and removing the frame hitch on sell. PlaySellEffectRpc now logs a one-time warning when no SellEffectSpawner is in the scene, since a missing spawner silently suppressed the coin VFX and sound. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
parent
86bc916c49
commit
1794f65b19
2 changed files with 29 additions and 2 deletions
|
|
@ -1,4 +1,5 @@
|
|||
// Assets/_Project/Scripts/Gameplay/TowerInstance.cs
|
||||
using System.Collections.Generic;
|
||||
using Unity.Netcode;
|
||||
using UnityEngine;
|
||||
using TD.Core;
|
||||
|
|
@ -511,11 +512,20 @@ namespace TD.Gameplay
|
|||
? resolvedDefinition.FootprintSize
|
||||
: new Vector2Int(2, 2);
|
||||
|
||||
// Collect the footprint, then stamp walkability as a BATCH so a single
|
||||
// OnWalkabilityChanged fires for the whole footprint. Per-tile SetWalkable fires
|
||||
// that event once PER TILE — on despawn (sell) that meant up to 4 full enemy A*
|
||||
// re-paths for a 2×2 tower in one frame, which was the sell hitch. Placement
|
||||
// batches for the same reason (TowerPlacementManager.StampWalkable). Occupancy
|
||||
// doesn't fire walkability events, so it stays per-tile.
|
||||
var footprint = new List<Vector2Int>(footprintSize.x * footprintSize.y);
|
||||
foreach (var tile in GridCoordinates.GetFootprintTiles(anchorTile.Value, footprintSize))
|
||||
{
|
||||
loader.SetWalkable(tile, walkable);
|
||||
footprint.Add(tile);
|
||||
loader.SetOccupied(tile, occupied);
|
||||
}
|
||||
|
||||
loader.SetWalkableBatch(footprint, walkable);
|
||||
}
|
||||
|
||||
// Reused per-instance across color updates to avoid per-call GC allocation.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue