Files
sbox-public/engine/Sandbox.Engine/Resources/NavMeshAreaDefinition.cs
s&box team 71f266059a Open source release
This commit imports the C# engine code and game files, excluding C++ source code.

[Source-Commit: ceb3d758046e50faa6258bc3b658a30c97743268]
2025-11-24 09:05:18 +00:00

66 lines
1.8 KiB
C#

using Sandbox.Navigation;
namespace Sandbox.Engine.Resources;
/// <summary>
/// Defines a navigation area resource for use in navigation meshes.
/// </summary>
[AssetType( Name = "NavArea Definition", Extension = "navarea", Category = "World" )]
public sealed class NavMeshAreaDefinition : GameResource
{
/// <summary>
/// Debug color for this Area.
/// </summary>
public Color Color { get; set; } = Color.Random;
internal const float CostMultiplierMax = 100f;
internal const float CostMultiplierMin = 1f;
/// <summary>
/// How much costlier it is to cross this Area.
/// Will be clamped.
/// </summary>
[Range( CostMultiplierMin, CostMultiplierMax )]
public float CostMultiplier { get => _costMultiplier; set => _costMultiplier = MathX.Clamp( value, CostMultiplierMin, CostMultiplierMax ); }
private float _costMultiplier = 1.0f;
/// <summary>
/// Gets or sets the priority level for the area definition.
/// Higher values take precedence if multiple areas overlap.
/// </summary>
/// <remarks>Changing this value may trigger updates to the navigation mesh.</remarks>
public int Priority
{
get => _priority;
set
{
_priority = value;
IToolsDll.Current?.RunEvent<NavMesh.IEventListener>( x => x.OnAreaDefinitionChanged() );
if ( Game.ActiveScene.IsValid() )
{
Game.ActiveScene.NavMesh?.UpdateAreaIds();
}
}
}
private int _priority = 0;
protected override void PostLoad()
{
PostReload();
}
protected override void PostReload()
{
IToolsDll.Current?.RunEvent<NavMesh.IEventListener>( x => x.OnAreaDefinitionChanged() );
if ( Game.ActiveScene.IsValid() )
{
Game.ActiveScene.NavMesh?.UpdateAreaIds();
}
}
protected override Bitmap CreateAssetTypeIcon( int width, int height )
{
return CreateSimpleAssetTypeIcon( "explore", width, height );
}
}