editor/AdvancedMappingTools/Geometry/NavLinkEditor.cs

Editor tool that places NavMesh links. Draws a beam between two picked points with marker boxes at each end and creates a NavMeshLink component with the verified endpoints as a hidden, non-colliding guide.

namespace AdvancedMappingTools;

/// <summary>
/// A NavMesh link between two points. It only carries the verified link endpoints;
/// how an agent crosses it (walk, ladder, jump) is up to the game through LinkEntered/LinkExited.
/// </summary>
[ToolCategory( "Navigation" )]
[Title( "Nav Link" ), Icon( "route" )]
public sealed class NavLinkEditor( PrimitiveTool tool ) : LineEditor( tool )
{
	protected override bool AllowsHeight => true;

	protected override bool IsShapeValid => Start.Distance( End ) > 1.0f;

	protected override void BuildMesh( MeshKit kit )
	{
		kit.Material = TrimMaterial;
		kit.Beam( Start, End, 2.0f, 2.0f );
		kit.Box( Start - new Vector3( 3.0f, 3.0f, 0.0f ), Start + new Vector3( 3.0f, 3.0f, 12.0f ) );
		kit.Box( End - new Vector3( 3.0f, 3.0f, 0.0f ), End + new Vector3( 3.0f, 3.0f, 12.0f ) );
	}

	protected override void OnBuilt( MeshComponent component )
	{
		// The marker is an editor guide only: no collision and no draw in game.
		component.HideInGame = true;
		component.Collision = MeshComponent.CollisionType.None;

		var link = component.GameObject.Components.Create<NavMeshLink>();

		link.WorldStartPosition = Start;
		link.WorldEndPosition = End;
	}
}