private void BuildNavMesh(bool Async) { Bounds navMeshBounds = new Bounds(Player.transform.position, NavMeshSize); List <NavMeshBuildMarkup> markups = new List <NavMeshBuildMarkup>(); List <NavMeshModifier> modifiers; if (Surface.collectObjects == CollectObjects.Children) { modifiers = new List <NavMeshModifier>(GetComponentsInChildren <NavMeshModifier>()); } else { modifiers = NavMeshModifier.activeModifiers; } for (int i = 0; i < modifiers.Count; i++) { if (((Surface.layerMask & (1 << modifiers[i].gameObject.layer)) == 1) && modifiers[i].AffectsAgentType(Surface.agentTypeID)) { markups.Add(new NavMeshBuildMarkup() { root = modifiers[i].transform, overrideArea = modifiers[i].overrideArea, area = modifiers[i].area, ignoreFromBuild = modifiers[i].ignoreFromBuild }); } } if (Surface.collectObjects == CollectObjects.Children) { NavMeshBuilder.CollectSources(transform, Surface.layerMask, Surface.useGeometry, Surface.defaultArea, markups, Sources); } else { NavMeshBuilder.CollectSources(navMeshBounds, Surface.layerMask, Surface.useGeometry, Surface.defaultArea, markups, Sources); } Sources.RemoveAll(source => source.component != null && source.component.gameObject.GetComponent <NavMeshAgent>() != null); if (Async) { NavMeshBuilder.UpdateNavMeshDataAsync(NavMeshData, Surface.GetBuildSettings(), Sources, new Bounds(Player.transform.position, NavMeshSize)); } else { NavMeshBuilder.UpdateNavMeshData(NavMeshData, Surface.GetBuildSettings(), Sources, new Bounds(Player.transform.position, NavMeshSize)); } }
// creates the navmesh data static NavMeshData InitializeBakeData(NavMeshSurface surface) { var emptySources = new List <NavMeshBuildSource>(); var emptyBounds = new Bounds(); return(UnityEngine.AI.NavMeshBuilder.BuildNavMeshData(surface.GetBuildSettings(), emptySources, emptyBounds, surface.transform.position, surface.transform.rotation)); }
public void BuildNavMesh() { Awake(); // remove existing navMeshSurfaces foreach (NavMeshSurface navMeshSurface in navMeshRoot.GetComponents <NavMeshSurface>()) { Destroy(navMeshSurface); } int agentTypeCount = UnityEngine.AI.NavMesh.GetSettingsCount(); if (agentTypeCount < 1) { return; } for (int i = 0; i < agentTypeCount; ++i) { NavMeshBuildSettings settings = UnityEngine.AI.NavMesh.GetSettingsByIndex(i); NavMeshSurface navMeshSurface = navMeshRoot.AddComponent <NavMeshSurface>(); navMeshSurface.agentTypeID = settings.agentTypeID; NavMeshBuildSettings actualSettings = navMeshSurface.GetBuildSettings(); navMeshSurface.useGeometry = NavMeshCollectGeometry.RenderMeshes; // or you can use RenderMeshes //navMeshSurface.layerMask = true; // remove existing agents from the navmesh layermask navMeshSurface.layerMask -= LayerMask.GetMask("Agents"); navMeshSurface.layerMask -= LayerMask.GetMask("Ignore Raycast"); navMeshSurface.BuildNavMesh(); } this.navMeshInitialized = true; }
/// <summary> /// Creates the NavMeshData /// </summary> /// <param name="surface"></param> /// <returns></returns> private NavMeshData InitializeBakeData() { List <NavMeshBuildSource> buildSources = new List <NavMeshBuildSource>(); Bounds bounds = new Bounds(primaryViewer.Transform.position, new Vector3(100f, 50f, 100f)); NavMeshBuilder.CollectSources(transform, navMeshSurface.layerMask, NavMeshCollectGeometry.PhysicsColliders, 0, new List <NavMeshBuildMarkup>(), buildSources); return(NavMeshBuilder.BuildNavMeshData(navMeshSurface.GetBuildSettings(), buildSources, bounds, navMeshSurface.transform.position, navMeshSurface.transform.rotation)); }
void BuilNavMesh(WG_TerrainBuilder builder, List <WG_LocationController> locations, bool bakeNavMesh) { for (int i = 0; i < locations.Count; i++) { GameObject ground = locations[i].groundGO; NavMeshSurface surface = ground.AddComponent <NavMeshSurface>(); } if (bakeNavMesh) { //call bake from the first location if (locations.Count > 0) { NavMeshSurface navSurface = locations[0].groundGO.GetComponent <NavMeshSurface>(); NavMeshBuildSettings settings = navSurface.GetBuildSettings(); builder.SaveNavMeshData(navSurface.navMeshData); } } }
public void BuildNavMesh() { int agentTypeCount = NavMesh.GetSettingsCount(); if (agentTypeCount < 1) { return; } for (int i = 0; i < navMeshElements.Count; ++i) { if(navMeshElements[i]) navMeshElements[i].transform.SetParent(gameObject.transform, true); } for (int i = 0; i < agentTypeCount; ++i) { NavMeshBuildSettings settings = NavMesh.GetSettingsByIndex(i); NavMeshSurface navMeshSurface = gameObject.AddComponent<NavMeshSurface>(); navMeshSurface.agentTypeID = settings.agentTypeID; NavMeshBuildSettings actualSettings = navMeshSurface.GetBuildSettings(); navMeshSurface.useGeometry = NavMeshCollectGeometry.PhysicsColliders; // or you can use RenderMeshes navMeshSurface.BuildNavMesh(); } }
public void DefaultSettingsMatchBuiltinSettings() { var bs = surface.GetBuildSettings(); Assert.AreEqual(NavMesh.GetSettingsByIndex(0), bs); }