More major updates to tools, added map area volume, made gold manager network managed per player.
This commit is contained in:
parent
b44eeaeeff
commit
56dc775c68
18 changed files with 632 additions and 283 deletions
103
Assets/_Project/Levels/MapAreaVolume.cs
Normal file
103
Assets/_Project/Levels/MapAreaVolume.cs
Normal file
|
|
@ -0,0 +1,103 @@
|
|||
using UnityEngine;
|
||||
using TD.Core;
|
||||
|
||||
#if UNITY_EDITOR
|
||||
using UnityEditor;
|
||||
#endif
|
||||
|
||||
namespace TD.Levels
|
||||
{
|
||||
/// <summary>
|
||||
/// Authoring volume defining the playable map area — the bounds the builder can move within
|
||||
/// and the camera can pan to. Has no gameplay payload (no owner, no placement validity, no
|
||||
/// spawner data, no leak target). Multiple instances are allowed; their union defines the
|
||||
/// "map area" as referenced in the per-tile data layering spec.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Map area = where the player's attention can go.
|
||||
/// Gameplay area = union of PlayerZone, Spawner, LeakExit, Goal volumes (where rules apply).
|
||||
/// Buffer area = map area minus gameplay area (visible terrain, no gameplay, no building).
|
||||
///
|
||||
/// Coverage rule: every gameplay volume's tiles must be a subset of the map area. The bake
|
||||
/// validates this in Phase 5 (P5-12) and fails with a hard error if any gameplay volume
|
||||
/// pokes outside the map area.
|
||||
///
|
||||
/// Drawn as a thicker outline only (no fill) so it reads as a boundary marker rather than
|
||||
/// as a translucent overlay on top of the gameplay volumes. The "always show" toggle on
|
||||
/// LevelAuthoring defaults to true for this volume type because the map boundary is
|
||||
/// generally useful to see during all authoring, not just when this volume is selected.
|
||||
/// </remarks>
|
||||
public class MapAreaVolume : VolumeBase
|
||||
{
|
||||
// Map area draws BELOW player zones (which sit at 0.05). Just above the LevelAuthoring
|
||||
// map-bounds line (0.01) so it doesn't z-fight with that wireframe.
|
||||
private const float FillYLevel = 0.02f;
|
||||
|
||||
protected override bool GetAlwaysShowToggle(LevelAuthoring authoring)
|
||||
{
|
||||
return authoring.alwaysShowMapArea;
|
||||
}
|
||||
|
||||
private void OnDrawGizmosSelected()
|
||||
{
|
||||
DrawGizmosCore();
|
||||
}
|
||||
|
||||
private void OnDrawGizmos()
|
||||
{
|
||||
if (ShouldDrawAlwaysOn())
|
||||
{
|
||||
DrawGizmosCore();
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawGizmosCore()
|
||||
{
|
||||
Color baseColor = PlayerColors.MapArea;
|
||||
DrawThickRectangularOutline(baseColor, yLevel: FillYLevel);
|
||||
|
||||
#if UNITY_EDITOR
|
||||
var col = Collider;
|
||||
if (col != null)
|
||||
{
|
||||
Vector3 labelPos = new Vector3(col.bounds.center.x, FillYLevel + 0.1f, col.bounds.center.z);
|
||||
Handles.Label(labelPos, "Map Area");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
// Draws the volume's tight tile rectangle as a thicker outline. Unity's Gizmos.DrawLine
|
||||
// has no width parameter, so we approximate thickness by drawing the rectangle three
|
||||
// times with small lateral offsets. The offsets are in tile units; 0.04 reads as a
|
||||
// visibly thicker line at typical scene-view zoom without looking like multiple lines.
|
||||
private void DrawThickRectangularOutline(Color outlineColor, float yLevel)
|
||||
{
|
||||
if (!TryGetTightTileRect(out Vector2Int minTile, out Vector2Int maxTile)) return;
|
||||
|
||||
const float thickness = 0.04f;
|
||||
float halfTile = GridCoordinates.TILE_SIZE * 0.5f;
|
||||
|
||||
// Three concentric rectangles: the original edge, slightly inset, slightly outset.
|
||||
DrawOutlineAtInset(minTile, maxTile, halfTile, yLevel, 0f, outlineColor);
|
||||
DrawOutlineAtInset(minTile, maxTile, halfTile, yLevel, +thickness, outlineColor);
|
||||
DrawOutlineAtInset(minTile, maxTile, halfTile, yLevel, -thickness, outlineColor);
|
||||
}
|
||||
|
||||
private static void DrawOutlineAtInset(Vector2Int minTile, Vector2Int maxTile, float halfTile,
|
||||
float yLevel, float inset, Color color)
|
||||
{
|
||||
Vector3 sw = new Vector3(minTile.x - halfTile - inset, yLevel, minTile.y - halfTile - inset);
|
||||
Vector3 se = new Vector3(maxTile.x + halfTile + inset, yLevel, minTile.y - halfTile - inset);
|
||||
Vector3 ne = new Vector3(maxTile.x + halfTile + inset, yLevel, maxTile.y + halfTile + inset);
|
||||
Vector3 nw = new Vector3(minTile.x - halfTile - inset, yLevel, maxTile.y + halfTile + inset);
|
||||
|
||||
Color prev = Gizmos.color;
|
||||
Gizmos.color = color;
|
||||
Gizmos.DrawLine(sw, se);
|
||||
Gizmos.DrawLine(se, ne);
|
||||
Gizmos.DrawLine(ne, nw);
|
||||
Gizmos.DrawLine(nw, sw);
|
||||
Gizmos.color = prev;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue