public void MapResources() { bundles = new ResourceBundleDictionary(); for (int i = 0; i < types.Length; ++i) { PathMap typeMap = types[i]; typeMap.Clear(); } ResourceMapper.Run(bundles, ref types); }
private void CreateEntryAndExit() { Vector2Int p1 = FindOpenArea(border, border, width / 4, height - border); Vector2Int p2 = FindOpenArea(width - border - width / 4, border, width - width / 8, height - border); if (UnityEngine.Random.value < .5) { entryPoint = p1; exitPoint = p2; } else { entryPoint = p2; exitPoint = p1; } // Pathfind from exit to entry { PathMap path = new PathMap(this); path.StartSearch(entryPoint, Mathf.Infinity); bool found = path.UpdateUntilPathFound(exitPoint); //path.UpdateAll(); bool found = true; if (found) { //path.Print(); Vector2Int sq = exitPoint; //Debug.LogFormat("Pathfinding from {0}", sq); while (sq != entryPoint) { PathMap.Node node = path.nodes[sq.y, sq.x]; //Debug.LogFormat("At {0}: cost {1} direction {2}", sq, node.cost, node.direction.GetCharacter()); Vector3 worldPos = Game.GridToWorldPosition(sq); if (GetTile(sq) != Tile.Floor) { //Debug.LogFormat("Changing {0} from {1} to floor", sq, GetTile(sq)); #if UNITY_EDITOR Debug.DrawLine(worldPos + new Vector3(-.5f, -.5f, 0), worldPos + new Vector3(.5f, .5f, 0), Color.red, 5); #endif SetTile(sq, Tile.Floor); } Assert.IsTrue(node.direction.deltaPosition.sqrMagnitude != 0); sq += node.direction.GetOpposite().deltaPosition; #if UNITY_EDITOR Debug.DrawLine(worldPos, Game.GridToWorldPosition(sq), Color.green, 5); #endif } } else { Debug.LogWarning("No path found from entry to exit - creating a corridor"); MakeCorridor(entryPoint, exitPoint, Tile.Bedrock); } pathToPlayer = path; pathToPlayer.Clear(); } SetTile(entryPoint, Tile.Floor); SetTile(exitPoint, Tile.Exit); }