/** Updates the meshes used in OnDrawGizmos to visualize the navmesh */
		void UpdateDebugMeshes () {
			var graph = target as RecastGraph;

			var tiles = graph.GetTiles();

			if (tiles == null || tiles.Length != gizmoMeshes.Count) {
				// Destroy all previous meshes
				UnloadGizmoMeshes();
			}

			if (tiles != null) {
				// Update navmesh vizualizations for
				// the tiles that have been changed
				for (int i = 0; i < tiles.Length; i++) {
					if (i < gizmoMeshes.Count && gizmoMeshes[i].tile == tiles[i]) {
						// Tile is still valid, don't update it
					} else {
						// Tile needs to be updated
						var newTile = new GizmoTile {
							tile = tiles[i],
							surfaceMesh = CreateNavmeshSurfaceVisualization(tiles[i]),
							outlineMesh = CreateNavmeshOutlineVisualization(tiles[i])
						};

						if (i < gizmoMeshes.Count) {
							// Destroy and replace existing mesh
							Mesh.DestroyImmediate(gizmoMeshes[i].surfaceMesh);
							Mesh.DestroyImmediate(gizmoMeshes[i].outlineMesh);
							gizmoMeshes[i] = newTile;
						} else {
							gizmoMeshes.Add(newTile);
						}
					}
				}
			}
		}
예제 #2
0
        /** Updates the meshes used in OnDrawGizmos to visualize the navmesh */
        void UpdateDebugMeshes()
        {
            var graph = target as RecastGraph;

            var tiles = graph.GetTiles();

            if (tiles == null || tiles.Length != gizmoMeshes.Count)
            {
                // Destroy all previous meshes
                UnloadGizmoMeshes();
            }

            if (tiles != null)
            {
                // Update navmesh vizualizations for
                // the tiles that have been changed
                for (int i = 0; i < tiles.Length; i++)
                {
                    bool validTile = i < gizmoMeshes.Count && gizmoMeshes[i].tile == tiles[i];

                    // Calculate a hash of the tile
                    int       hash      = 0;
                    const int HashPrime = 31;
                    var       nodes     = tiles[i].nodes;
                    for (int j = 0; j < nodes.Length; j++)
                    {
                        hash = hash * HashPrime;
                        var node = nodes[j];
                        hash ^= node.position.GetHashCode();
                        hash ^= 17 * (node.connections != null ? node.connections.Length : -1);
                        hash ^= 19 * (int)node.Penalty;
                        hash ^= 41 * (int)node.Tag;
                        hash ^= 57 * (int)node.Area;
                    }

                    hash ^= 67 * (int)AstarPath.active.debugMode;
                    hash ^= 73 * AstarPath.active.debugFloor.GetHashCode();
                    hash ^= 79 * AstarPath.active.debugRoof.GetHashCode();

                    validTile = validTile && hash == gizmoMeshes[i].hash;

                    if (!validTile)
                    {
                        // Tile needs to be updated
                        var newTile = new GizmoTile {
                            tile        = tiles[i],
                            hash        = hash,
                            surfaceMesh = CreateNavmeshSurfaceVisualization(tiles[i]),
                            outlineMesh = CreateNavmeshOutlineVisualization(tiles[i])
                        };

                        if (i < gizmoMeshes.Count)
                        {
                            // Destroy and replace existing mesh
                            Mesh.DestroyImmediate(gizmoMeshes[i].surfaceMesh);
                            Mesh.DestroyImmediate(gizmoMeshes[i].outlineMesh);
                            gizmoMeshes[i] = newTile;
                        }
                        else
                        {
                            gizmoMeshes.Add(newTile);
                        }
                    }
                }
            }
        }
예제 #3
0
		/** Updates the meshes used in OnDrawGizmos to visualize the navmesh */
		void UpdateDebugMeshes () {
			var graph = target as RecastGraph;

			var tiles = graph.GetTiles();

			if (tiles == null || tiles.Length != gizmoMeshes.Count) {
				// Destroy all previous meshes
				UnloadGizmoMeshes();
			}

			if (tiles != null) {
				// Update navmesh vizualizations for
				// the tiles that have been changed
				for (int i = 0; i < tiles.Length; i++) {
					bool validTile = i < gizmoMeshes.Count && gizmoMeshes[i].tile == tiles[i];

					// Calculate a hash of the tile
					int hash = 0;
					const int HashPrime = 31;
					var nodes = tiles[i].nodes;
					for (int j = 0; j < nodes.Length; j++) {
						hash = hash*HashPrime;
						var node = nodes[j];
						hash ^= node.position.GetHashCode();
						hash ^= 17 * (node.connections != null ? node.connections.Length : -1);
						hash ^= 19 * (int)node.Penalty;
						hash ^= 41 * (int)node.Tag;
						hash ^= 57 * (int)node.Area;
					}

					hash ^= 67 * (int)AstarPath.active.debugMode;
					hash ^= 73 * AstarPath.active.debugFloor.GetHashCode();
					hash ^= 79 * AstarPath.active.debugRoof.GetHashCode();

					validTile = validTile && hash == gizmoMeshes[i].hash;

					if (!validTile) {
						// Tile needs to be updated
						var newTile = new GizmoTile {
							tile = tiles[i],
							hash = hash,
							surfaceMesh = CreateNavmeshSurfaceVisualization(tiles[i]),
							outlineMesh = CreateNavmeshOutlineVisualization(tiles[i])
						};

						if (i < gizmoMeshes.Count) {
							// Destroy and replace existing mesh
							Mesh.DestroyImmediate(gizmoMeshes[i].surfaceMesh);
							Mesh.DestroyImmediate(gizmoMeshes[i].outlineMesh);
							gizmoMeshes[i] = newTile;
						} else {
							gizmoMeshes.Add(newTile);
						}
					}
				}
			}
		}