Components/NoRespawnZone.cs

A component that defines a box-shaped spatial zone where respawn positions should not be stored or accepted. It stores a local Size, tests whether a world position is inside by transforming to local space, and draws debug gizmos (wireframe and translucent solid) in the editor.

namespace Machines.Race;

/// <summary>
/// Box zone where respawn positions are never saved or accepted; purely spatial, no collider needed.
/// </summary>
public sealed class NoRespawnZone : Component
{
	/// <summary>
	/// Box size centred on the GameObject in local space.
	/// </summary>
	[Property]
	public Vector3 Size { get; set; } = new( 512f, 512f, 256f );

	/// <summary>
	/// Whether a world position is inside this zone.
	/// </summary>
	public bool Contains( Vector3 pos )
	{
		var local = WorldTransform.PointToLocal( pos );
		return BBox.FromPositionAndSize( Vector3.Zero, Size ).Contains( local );
	}

	protected override void DrawGizmos()
	{
		var box = BBox.FromPositionAndSize( Vector3.Zero, Size );

		Gizmo.Draw.Color = Color.Red.WithAlpha( 0.6f );
		Gizmo.Draw.LineBBox( box );

		Gizmo.Draw.Color = Color.Red.WithAlpha( Gizmo.IsSelected ? 0.2f : 0.08f );
		Gizmo.Draw.SolidBox( box );
	}
}