public void NavMeshCanBeRemovedAndAdded() { surface.BuildNavMesh(); Assert.IsTrue(HasNavMeshAtOrigin()); surface.RemoveData(); Assert.IsFalse(HasNavMeshAtOrigin()); surface.AddData(); Assert.IsTrue(HasNavMeshAtOrigin()); }
public const int MAX_WALL = 7; //can change this to create a geant map // Start is called before the first frame update void Start() { float begin = Time.realtimeSinceStartup; this.seed = Mathf.FloorToInt(Random.value * int.MaxValue); Random.InitState(seed); MapGeneration(); surface.BuildNavMesh(); surface.AddData(); //Add the surface to the singleton Nav Mesh NavMeshTriangulation navMeshTriangulation = NavMesh.CalculateTriangulation(); DebugDisplayTriangle(navMeshTriangulation); MapGraph mapGraph = GenerateGraph(navMeshTriangulation); mapGraph.DeugDrawGrahp(); Debug.Log("Generation took " + (Time.realtimeSinceStartup - begin) + " seconds"); GenerateLights(mapGraph); TemporaryPlayerGeneration(mapGraph); surface.RemoveData(); //Remove the surface to the singleton NavMesh surface_enemy.BuildNavMesh(); GenerateEnemies(5, mapGraph); gameObject.BroadcastMessage("StartTheGame"); }
IEnumerator AsyncBake() { if (surface == null) { yield break; } data = InitializeBakeData(surface); operation = surface.UpdateNavMesh(data); if (operation == null) { yield break; } while (!operation.isDone) { yield return(null); } surface.RemoveData(); surface.navMeshData = data; if (surface.isActiveAndEnabled) { surface.AddData(); } operation = null; }
private IEnumerator Co_RebuildNavMeshes() { yield return(new WaitForFixedUpdate()); //TODO this may get expensive with a lot of enemies, if it is noticeable then make a //static bool on GameController that Mirror checks every update //if it's true, then don't update the enemy2D that frame var enemies = GameObject.FindGameObjectsWithTag("Enemy"); foreach (var item in enemies) { item.GetComponent <Mirror>().DontMirror(); } FireProofSurface.RemoveData(); yield return(new WaitForFixedUpdate()); FireProofSurface.BuildNavMesh(); WalkingSurface.RemoveData(); yield return(new WaitForFixedUpdate()); WalkingSurface.BuildNavMesh(); foreach (var item in enemies) { item.GetComponent <Mirror>().Mirror3DObject(); } }
void ClearSurface(NavMeshSurface navSurface) { #if UNITY_2018_3_OR_NEWER var hasNavMeshData = navSurface.navMeshData != null; StoreNavMeshDataIfInPrefab(navSurface); #endif var assetToDelete = GetNavMeshAssetToDelete(navSurface); navSurface.RemoveData(); #if UNITY_2018_3_OR_NEWER if (hasNavMeshData) { SetNavMeshData(navSurface, null); EditorSceneManager.MarkSceneDirty(navSurface.gameObject.scene); } if (assetToDelete) { AssetDatabase.DeleteAsset(AssetDatabase.GetAssetPath(assetToDelete)); } #else navSurface.navMeshData = null; EditorUtility.SetDirty(navSurface); if (assetToDelete) { AssetDatabase.DeleteAsset(AssetDatabase.GetAssetPath(assetToDelete)); EditorSceneManager.MarkSceneDirty(navSurface.gameObject.scene); } #endif }
protected override void OnUpdate() { var commandBuffer = new EntityCommandBuffer(Allocator.TempJob); var chunks = hybridQuery.CreateArchetypeChunkArray(Allocator.TempJob); var entityType = GetArchetypeChunkEntityType(); var translationType = GetArchetypeChunkComponentType <Translation>(true); var matrixType = GetArchetypeChunkComponentType <CellSystem.MatrixComponent>(true); var localToWorldType = GetArchetypeChunkComponentType <LocalToWorld>(true); var meshType = GetArchetypeChunkSharedComponentType <RenderMesh>(); for (int c = 0; c < chunks.Length; c++) { var chunk = chunks[c]; var entities = chunk.GetNativeArray(entityType); var translations = chunk.GetNativeArray(translationType); var matrixComponents = chunk.GetNativeArray(matrixType); var localToWorldComponents = chunk.GetNativeArray(localToWorldType); for (int e = 0; e < entities.Length; e++) { Entity entity = entities[e]; float3 position = translations[e].Value; CellSystem.MatrixComponent matrix = matrixComponents[e]; float4x4 localToWorld = localToWorldComponents[e].Value; Mesh mesh = chunk.GetSharedComponentData <RenderMesh>(meshType, entityManager).mesh; GameObject sectorGameObject = GameObject.Instantiate(sectorPrefab, position, Quaternion.identity); sectorGameObject.GetComponent <MeshCollider>().sharedMesh = mesh; NavMeshSurface navMeshComponent = sectorGameObject.GetComponent <NavMeshSurface>(); NavMeshBuildSettings settings = NavMesh.GetSettingsByID(0); List <NavMeshBuildSource> sources = CreateNavMeshSource(matrix.width, navMeshComponent, mesh, localToWorld); Bounds bounds = CalculateWorldBounds(sources, position); NavMeshData data = NavMeshBuilder.BuildNavMeshData(settings, sources, bounds, position, Quaternion.identity); if (data != null) { data.name = sectorGameObject.name; navMeshComponent.RemoveData(); navMeshComponent.navMeshData = data; if (navMeshComponent.isActiveAndEnabled) { navMeshComponent.AddData(); } } commandBuffer.AddComponent <Tags.HybridGameObjectCreated>(entity, new Tags.HybridGameObjectCreated()); commandBuffer.AddSharedComponent <GameObjectComponent>(entity, new GameObjectComponent { gameObject = sectorGameObject }); } } commandBuffer.Playback(entityManager); commandBuffer.Dispose(); chunks.Dispose(); }
/// <summary> /// Sets up the navigation mesh surface. /// Call when a new arena has been created. /// </summary> private void RefreshNavMeshSurfaceBake() { // removes any previously made nav mesh bake (I think, not actually sure???) _navMeshSurface.RemoveData(); // creates a new nav mesh _navMeshSurface.BuildNavMesh(); }
void Update() { if (Input.GetKeyDown(KeyCode.F)) { //StopAllCoroutines(); foreach (Tile spawnedTile in spawnedTiles) { if (spawnedTile != null) { Destroy(spawnedTile.gameObject); } } //StartCoroutine(Generate()); NavigationMesh.RemoveData(); Generate(); } }
void GenerateNewLevel() { DestroyAllChildren(); ResetMatrix(); GenerateMatrix(); GenerateLevel(); DestroyWalls(); if (!_isEditMode) { StartCoroutine(GenNavMesh()); } else { _navMesh.RemoveData(); _navMesh.BuildNavMesh(); } }
void Update() { if (BuildingController.Status == 10) { _navmeshsurface.RemoveData(); _navmeshsurface.BuildNavMesh(); BuildingController.Status = 255; } }
public void Shuffle() { wealthValue = ProgressionManager.GetWealthValue(); LoadBuilding(wealthValue); randomMaterials.ApplyRandomColors(); NavMeshSurface.RemoveData(); StartCoroutine(nameof(BuildNavMesh), wealthValue); }
void Update() { if (Input.GetButtonDown("Fire1")) { surface.Bake(); } else if (Input.GetButtonDown("Fire2")) { surface.RemoveData(); } }
void ClearSurface(NavMeshSurface navSurface) { // Destroy and remove from disk var destroy = navSurface.bakedNavMeshData; navSurface.RemoveData(); if (destroy) { DestroyImmediate(destroy, true); // Explicitly set the scene as dirty EditorSceneManager.MarkSceneDirty(navSurface.gameObject.scene); } }
void ClearSurface(NavMeshSurface navSurface) { var assetToDelete = GetNavMeshAssetToDelete(navSurface); navSurface.RemoveData(); navSurface.navMeshData = null; EditorUtility.SetDirty(navSurface); if (assetToDelete) { AssetDatabase.DeleteAsset(AssetDatabase.GetAssetPath(assetToDelete)); EditorSceneManager.MarkSceneDirty(navSurface.gameObject.scene); } }
void ClearSurface(NavMeshSurface navSurface) { // Destroy and remove from disk var destroy = navSurface.bakedNavMeshData; navSurface.RemoveData(); if (destroy) { AssetDatabase.DeleteAsset(AssetDatabase.GetAssetPath(destroy)); ApplyIfPrefab(navSurface); // Explicitly set the scene as dirty EditorSceneManager.MarkSceneDirty(navSurface.gameObject.scene); } }
public static void UpdateNavMesh(NavMeshSurface surface, Vector3 size, AiController aiController, float updateDistance) { if (!(Vector3.Distance(aiController.transform.position, surface.transform.position) >= updateDistance)) { return; } surface.RemoveData(); surface.size = size; surface.transform.position = aiController.transform.position; surface.BuildNavMesh(); }
public static AsyncOperation BuildNavMeshAsync(this NavMeshSurface surface) { surface.RemoveData(); surface.navMeshData = new NavMeshData(surface.agentTypeID) { name = surface.gameObject.name, position = surface.transform.position, rotation = surface.transform.rotation }; if (surface.isActiveAndEnabled) { surface.AddData(); } return(surface.UpdateNavMesh(surface.navMeshData)); }
private void Update() { if (operation == null) { return; } if (operation.isDone) { surface.RemoveData(); surface.navMeshData = data; if (surface.isActiveAndEnabled) { surface.AddData(); } SceneView.RepaintAll(); operation = null; } }
// called by startcoroutine whenever you want to build the navmesh IEnumerator BuildNavmesh(NavMeshSurface surface) { Debug.Log("building navmesh"); foreach (NPC_Navigation npc in NPCs) { npc.gameObject.SetActive(false); } // get the data for the surface var data = InitializeBakeData(surface); surface.RemoveData(); surface.navMeshData = null; Application.backgroundLoadingPriority = ThreadPriority.Low; // start building the navmesh asyncop = surface.UpdateNavMesh(data); // wait until the navmesh has finished baking yield return(asyncop); //Debug.Log("finished"); // you need to save the baked data back into the surface surface.navMeshData = data; // call AddData() to finalize it surface.AddData(); foreach (NPC_Navigation npc in NPCs) { npc.gameObject.SetActive(true); npc.AdjustPosition(); if (Application.isPlaying) { npc.SetNewRandomTarget(); } } }
// Update is called once per frame void Update() { if (Input.GetButtonDown("Fire1")) { if (!baked) { plateau.Bake(); baked = true; } } else if (Input.GetButtonDown("Fire2")) { if (baked) { plateau.RemoveData(); baked = false; } } }
void ClearSurface(NavMeshSurface navSurface) { var hasNavMeshData = navSurface.navMeshData != null; StoreNavMeshDataIfInPrefab(navSurface); var assetToDelete = GetNavMeshAssetToDelete(navSurface); navSurface.RemoveData(); if (hasNavMeshData) { SetNavMeshData(navSurface, null); EditorSceneManager.MarkSceneDirty(navSurface.gameObject.scene); } if (assetToDelete) { AssetDatabase.DeleteAsset(AssetDatabase.GetAssetPath(assetToDelete)); } }
public IEnumerator BuildNavMesh() { Debug.Log("[Level] Building nav mesh..."); // https://github.com/Unity-Technologies/NavMeshComponents/issues/97 _navMeshSurface.RemoveData(); _navMeshSurface.navMeshData = new NavMeshData(_navMeshSurface.agentTypeID) { name = _navMeshSurface.gameObject.name, position = _navMeshSurface.transform.position, rotation = _navMeshSurface.transform.rotation }; _navMeshSurface.AddData(); AsyncOperation asyncOp = _navMeshSurface.UpdateNavMesh(_navMeshSurface.navMeshData); while (!asyncOp.isDone) { yield return(null); } }
/// <summary> /// Builds the NavMesh based on current active chunks that have colliders active. /// </summary> private IEnumerator BuildNavMeshAsync() { if (currentNavmeshBuilderId != int.MaxValue) { currentNavmeshBuilderId++; } else { currentNavmeshBuilderId = 0; } int navMeshBuilderId = currentNavmeshBuilderId; IsBuildingNavmesh = true; // Get the data for the surface NavMeshData data = InitializeBakeData(); // Start building the navmesh AsyncOperation async = navMeshSurface.UpdateNavMesh(data); // Wait until the navmesh has finished baking yield return(async); if (currentNavmeshBuilderId == navMeshBuilderId) { // Remove current data navMeshSurface.RemoveData(); // Save the new data into the surface navMeshSurface.navMeshData = data; // Finalize / Apply navMeshSurface.AddData(); IsBuildingNavmesh = false; } }
void Start() { surface.RemoveData(); surface.BuildNavMesh(); }
public void DeleteMap() { navMeshSurface.RemoveData(); _map.DeleteObjects(); Destroy(_map.gameObject); }
private void RebakeMap() { surface.RemoveData(); surface.BuildNavMesh(); }
void UpdateNavMesh() { surf.RemoveData(); surf.transform.position = transform.position; surf.BuildNavMesh(); }
private void UpdateNavMesh() { surface.RemoveData(); surface.transform.position = transform.position; surface.BuildNavMesh(); }
public static void UpdateNavMesh(NavMeshSurface surface) { surface.RemoveData(); surface.BuildNavMesh(); }
void UpdateNavMesh() { surface.RemoveData(); surface.transform.position = transform.position; surface.Bake(); }