private void FillAlgorithmsDropdown() { _algorithmsDropdown.options.Clear(); _availableAlgorithms = PathfindersFactory.GetAvailablePathfinderTypes(); if (_availableAlgorithms != null) { for (int i = 0; i < _availableAlgorithms.Length; i++) { Dropdown.OptionData option = new Dropdown.OptionData(_availableAlgorithms[i].ToString()); _algorithmsDropdown.options.Add(option); } } }
private IEnumerator FindPathCoroutine() { MapNode start = StartTile.Node; MapNode end = EndTile.Node; IPathfinder algo = PathfindersFactory.GetPathfinderForType(Settings.Pathfinder); yield return(algo.FindPath( start, end, Settings.AnimateSearch, (node) => { if (!node.HasObstacle) { Tile tile = _nodeToTile[node]; tile.SetColor(Color.green); if (_tileDebugStyle == TileDebugStyle.Cost) { tile.ShowCost(); } } }, (node) => { if (!node.HasObstacle) { Tile tile = _nodeToTile[node]; tile.SetColor(Color.gray); if (_tileDebugStyle == TileDebugStyle.Cost) { tile.ShowCost(); } } } )); List <MapNode> path = new List <MapNode>(); MapNode current = end.CameFrom; while (current != null) { if (current.CameFrom == null && current != start) { path = null; break; } if (current != start) { path.Add(current); } current = current.CameFrom; } if (path != null && path.Count > 0) { for (int i = path.Count - 1; i >= 0; i--) { if (!path[i].HasObstacle) { _nodeToTile[path[i]].SetColor(Color.white); yield return(new WaitForSeconds(0.05f)); } } } else { //notify the player string message = "Could not find a path"; Debug.Log(message); MessagePanel.ShowMessage(message); } yield return(null); }