// Assuming the SceneNavigation component is attached to this GameObject
var sceneNavigation = GetComponent<SceneNavigation>();
// Configure some SceneNavigation settings
sceneNavigation.UseSceneData = true; // Use scene data for NavMesh generation
sceneNavigation.CustomAgent = false; // Use pre-configured agents
// Define navigable surfaces, e.g., floor
sceneNavigation.NavigableSurfaces = MRUKAnchor.SceneLabels.FLOOR;
// Find and assign NavMeshAgents in the scene so that they will be automatically assigned to the NavMesh
sceneNavigation.Agents = new List<NavMeshAgent>(FindAnyObjectByType<NavMeshAgent>());
// Optionally, handle the NavMesh initialization event
sceneNavigation.OnNavMeshInitialized.AddListener(() =>
{
Debug.Log("NavMesh has been successfully initialized.");
});
// Build the NavMesh for the current scene
sceneNavigation.BuildSceneNavMesh();AgentClimb
: float |
The height of discontinuities in the level the agent can climb over (i.e.
steps and stairs). Default is 0.04f.
Signature
float AgentClimb |
AgentHeight
: float |
How much vertical clearance space must exist.
Default is 0.5f.
Signature
float AgentHeight |
AgentIndex
: int |
The agent's used that is going to be used to build the NavMesh.
Signature
int AgentIndex |
AgentMaxSlope
: float |
Maximum slope the agent can walk up.
Default is 5.5f.
Signature
float AgentMaxSlope |
AgentRadius
: float |
The minimum distance to the walls where the navigation mesh can exist.
Default is 0.2f.
Signature
float AgentRadius |
Agents
: List< NavMeshAgent > |
The agents that will be assigned to the NavMesh generated with the scene data.
Signature
List<NavMeshAgent> Agents |
BuildOnSceneLoaded
: MRUK.RoomFilter |
When the scene data is loaded, this controls what room(s) will be used when baking the NavMesh.
Signature
MRUK.RoomFilter BuildOnSceneLoaded |
CollectGeometry
: NavMeshCollectGeometry |
Used for specifying the type of geometry to collect when building a NavMesh.
Default is PhysicsColliders.
Signature
NavMeshCollectGeometry CollectGeometry |
CollectObjects
: CollectObjects |
Used for specifying the type of objects to include when building a NavMesh.
Default is Children.
Signature
CollectObjects CollectObjects |
CustomAgent
: bool |
Determines whether a custom NavMeshAgent configuration should be used.
If true, a new agent will be created when building the NavMesh.
Signature
bool CustomAgent |
Layers
: LayerMask |
A bitmask representing the layers to consider when selecting what that will be used for baking.
Signature
LayerMask Layers |
NavigableSurfaces
: MRUKAnchor.SceneLabels |
The scene objects that will contribute to the creation of the NavMesh.
These are the surfaces that the agent can walk on.
Signature
MRUKAnchor.SceneLabels NavigableSurfaces |
OverrideTileSize
: bool |
Allows overriding the default tile size used in NavMesh generation.
Enable this to specify a custom tile size.
Signature
bool OverrideTileSize |
OverrideVoxelSize
: bool |
Allows overriding the default voxel size used in NavMesh generation.
Enable this to specify a custom voxel size.
Signature
bool OverrideVoxelSize |
SceneObstacles
: MRUKAnchor.SceneLabels |
The scene objects that will carve a hole in the NavMesh.
Signature
MRUKAnchor.SceneLabels SceneObstacles |
TileSize
: int |
Specifies the tile size for the NavMesh if OverrideTileSize is enabled.
Represents the width and height of the square tiles in world units.
Signature
int TileSize |
UseSceneData
: bool |
Determines whether scene data should be used for NavMesh generation.
When enabled, the NavMesh will be generated using the scene data provided by the MRUKAnchor objects.
Signature
bool UseSceneData |
VoxelSize
: float |
The NavMesh voxel size in world length units.
Should be 4-6 voxels per character diameter.
Signature
float VoxelSize |
Obstacles
: Dictionary< MRUKAnchor, GameObject >
[Get] |
Gets a dictionary mapping MRUKAnchor objects to their corresponding GameObjects that represent obstacles in the environment.
Signature
Dictionary<MRUKAnchor, GameObject> Obstacles |
OnNavMeshInitialized
: UnityEvent
[Get] |
Event triggered when the navigation mesh has been initialized.
Signature
UnityEvent OnNavMeshInitialized |
Surfaces
: Dictionary< MRUKAnchor, GameObject >
[Get] |
Gets a dictionary mapping MRUKAnchor objects to their corresponding GameObjects that represent surfaces in the environment.
Signature
Dictionary<MRUKAnchor, GameObject> Surfaces |
BuildSceneNavMesh
()
|
Creates a navigation mesh for the entire scene.
Signature
void BuildSceneNavMesh() Returns void |
BuildSceneNavMeshForRoom
(
room
)
|
Creates a navigation mesh for the scene.
This method creates a navigation mesh by collecting geometry from the scene, building the navigation mesh data, and adding it to the NavMesh. Currently, Unity does not allow the creation of custom NavMeshAgents at runtime. It also assigns the created navigation mesh to all NavMeshAgents in the scene.
Signature
void BuildSceneNavMeshForRoom(MRUKRoom room=null) Parameters room: MRUKRoom
Optional parameter for the MRUKRoom to create the NavMesh for. If not provided, obstacles will be created for all rooms.
Returns void |
BuildSceneNavMeshForRoom
(
room
, clearExistingNavMesh
)
|
Creates a navigation mesh for the scene with option to preserve existing navmesh data.
This method creates a navigation mesh by collecting geometry from the scene, building the navigation mesh data, and adding it to the NavMesh. When clearExistingNavMesh is false, this allows building navmesh for individual rooms without clearing previously built room navmeshes.
Signature
void BuildSceneNavMeshForRoom(MRUKRoom room, bool clearExistingNavMesh) Parameters room: MRUKRoom
Optional parameter for the MRUKRoom to create the NavMesh for. If not provided, obstacles will be created for all rooms.
clearExistingNavMesh: bool
If true, clears existing NavMesh data before building. If false, adds to existing NavMesh. Default is true to maintain backward compatibility.
Returns void |
ClearObstacle
(
anchor
)
|
Clears the obstacle associated with the given MRUKAnchor from the Obstacles dictionary.
Signature
void ClearObstacle(MRUKAnchor anchor) Parameters Returns void |
ClearObstacles
(
room
)
|
Clears all obstacles from the Obstacles dictionary associated with the given MRUKRoom.
If no room is specified, all obstacles are cleared.
Signature
void ClearObstacles(MRUKRoom room=null) Parameters room: MRUKRoom
Optional parameter for the MRUKRoom to clear the obstacles for. If not provided, all obstacles will be cleared.
Returns void |
ClearSurface
(
anchor
)
|
Clears the surface associated with the given MRUKAnchor from the Obstacles dictionary.
Signature
void ClearSurface(MRUKAnchor anchor) Parameters Returns void |
CreateNavigableSurfaces
(
room
)
|
Creating surfaces will not automatically build a new NavMesh. When changing surfaces at run time, always use BuildSceneNavMesh method
Signature
void CreateNavigableSurfaces(MRUKRoom room=null) Parameters room: MRUKRoom
Optional parameter for the MRUKRoom to create the navigable surfaces for. If not provided, navigable surfaces will be created for all rooms.
Returns void |
CreateNavMeshBuildSettings
(
agentRadius
, agentHeight
, agentMaxSlope
, agentClimb
)
|
Creates a new NavMeshBuildSettings object with the specified agent properties.
Signature
NavMeshBuildSettings CreateNavMeshBuildSettings(float agentRadius, float agentHeight, float agentMaxSlope, float agentClimb) Parameters agentRadius: float
The minimum distance to the walls where the navigation mesh can exist.
agentHeight: float
How much vertical clearance space must exist.
agentMaxSlope: float
Maximum slope the agent can walk up.
agentClimb: float
The height of discontinuities in the level the agent can climb over (i.e. steps and stairs).
Returns NavMeshBuildSettings
A new NavMeshBuildSettings object with the specified agent properties.
|
CreateNavMeshSurface
()
|
Creates a NavMeshSurface component and sets its properties.
Signature
void CreateNavMeshSurface() Returns void |
CreateObstacle
(
anchor
, shouldCarve
, carveOnlyStationary
, carvingTimeToStationary
, carvingMoveThreshold
)
|
Creates a NavMeshObstacle for the given MRUKAnchor.
Signature
void CreateObstacle(MRUKAnchor anchor, bool shouldCarve=true, bool carveOnlyStationary=false, float carvingTimeToStationary=0.2f, float carvingMoveThreshold=0.2f) Parameters shouldCarve: bool
Optional parameter that determines whether the obstacle should carve the NavMesh. Default is true.
carveOnlyStationary: bool
Optional parameter that determines whether the obstacle should only carve the NavMesh when stationary. Default is true.
carvingTimeToStationary: float
Optional parameter that sets the time in seconds an obstacle must be stationary before it starts carving the NavMesh. Default is 0.2f.
carvingMoveThreshold: float
Optional parameter that sets the minimum world space distance the obstacle must move before it is considered moving. Default is 0.2f.
Returns void |
CreateObstacles
(
room
)
|
Creates obstacles for the given MRUKRoom or all rooms if no room is specified.
Signature
void CreateObstacles(MRUKRoom room=null) Parameters room: MRUKRoom
Optional parameter for the MRUKRoom to create the obstacles for. If not provided, obstacles will be created for all rooms.
Returns void |
CreateObstacles
(
rooms
)
|
Creates obstacles for the given MRUKRoom or all rooms if no room is specified.
Signature
void CreateObstacles(List< MRUKRoom > rooms) Parameters Returns void |
RemoveNavMeshData
()
|
Removes the NavMeshData from the NavMeshSurface component.
Signature
void RemoveNavMeshData() Returns void |
ResizeNavMeshFromRoomBounds
(
surface
, room
)
|
Resizes the NavMeshSurface to fit the room bounds.
Signature
Bounds ResizeNavMeshFromRoomBounds(ref NavMeshSurface surface, MRUKRoom room=null) Parameters surface: ref NavMeshSurface
The NavMeshSurface to resize.
Returns Bounds
The bounds of the resized NavMeshSurface.
|
ResizeNavMeshFromRoomBounds
(
surface
, rooms
)
|
Resizes the NavMeshSurface to fit the room bounds.
Signature
Bounds ResizeNavMeshFromRoomBounds(ref NavMeshSurface surface, List< MRUKRoom > rooms) Parameters surface: ref NavMeshSurface
The NavMeshSurface to resize.
Returns Bounds
The bounds of the resized NavMeshSurface.
|
ToggleGlobalMeshNavigation
(
useGlobalMesh
, agentTypeID
)
|
Toggles the use of global mesh for navigation.
Signature
void ToggleGlobalMeshNavigation(bool useGlobalMesh, int agentTypeID=-1) Parameters useGlobalMesh: bool
Whether to use the global mesh to build the NavMesh
agentTypeID: int
The agent type ID to use for creating the scene nav mesh, if not specified, a new agent will be created.
Returns void |
GetFirstLayerFromLayerMask
(
layerMask
)
|
Gets the first layer included in the given LayerMask.
Signature
static int GetFirstLayerFromLayerMask(LayerMask layerMask) Parameters layerMask: LayerMask
The LayerMask to get the first layer from.
Returns int
Returns the first layer included in the LayerMask.
|
ValidateBuildSettings
(
navMeshBuildSettings
, navMeshBounds
)
|
Validates the provided NavMeshBuildSettings against the provided NavMeshBounds.
Signature
static bool ValidateBuildSettings(NavMeshBuildSettings navMeshBuildSettings, Bounds navMeshBounds) Parameters navMeshBuildSettings: NavMeshBuildSettings
The NavMeshBuildSettings to validate.
navMeshBounds: Bounds
The Bounds to validate the NavMeshBuildSettings against.
Returns bool
Returns true if the NavMeshBuildSettings are valid, false otherwise.
|