Park/Rides/RideBounds.cs
using System;
/// <summary>
/// Defines the bounds of a ride for pathfinding and placement. I don't think it's actually being used by anything right now.
/// </summary>
public sealed class RideBounds : Component
{
[Property] public BBox Bounds { get; set; } = BBox.FromPositionAndSize( 0, 64 );
[Property] int GridSize { get; set; } = 32;
protected override void DrawGizmos()
{
base.DrawGizmos();
Gizmo.Draw.Color = Color.Yellow;
Gizmo.Draw.LineBBox( Bounds );
if ( !Gizmo.IsSelected ) return;
Gizmo.Draw.Color = Color.Yellow.WithAlpha( 0.25f );
Gizmo.Draw.SolidBox( Bounds );
if ( Gizmo.Control.BoundingBox( "bbox", Bounds, out var newBounds ) )
{
Bounds = newBounds;
}
}
[Button( "Snap To Grid" )]
void SnapToGrid()
{
var gridSize = GridSize;
var min = Bounds.Mins;
var max = Bounds.Maxs;
min.x = MathF.Round( min.x / gridSize ) * gridSize;
min.y = MathF.Round( min.y / gridSize ) * gridSize;
max.x = MathF.Round( max.x / gridSize ) * gridSize;
max.y = MathF.Round( max.y / gridSize ) * gridSize;
min.z = MathF.Round( min.z / gridSize ) * gridSize;
max.z = MathF.Round( max.z / gridSize ) * gridSize;
Bounds = new BBox( min, max );
}
public BBox GetBounds()
{
return Bounds;
}
}