private void Draw(Vector3Int from, Vector3Int to) { ReplaceMany(_prevPath, emptyTile); _prevPath = GridPathfinder.FindPath(from, to, GridGeometry.Hex); ReplaceMany(_prevPath, highlightedTile); ReplaceOne(to, selectedTile); }
void Start() { Debug.Assert(_terrainInfo, "Terrain Info not set", this); Debug.Assert(_terrainVisualizer, "Terrain Visualizer not set", this); Debug.Assert(_lineRenderer, "Line Renderer not set", this); _pathfinder = new GridPathfinder(_terrainInfo); _terrainInfo.OnMapChange += OnMapChangeListener; }
void Awake() { HexMetrics.noiseSource = noiseSource; HexMetrics.InitializeHashGrid(seed); pathfinder = GetComponent <GridPathfinder>(); cellShaderData = gameObject.AddComponent <HexCellShaderData>(); cellShaderData.Grid = this; //CreateMap(cellCountX, cellCountZ, wrapping); }
private void Deselect() { Vector2Int targetCoordinates = gridHighlight.coordinates; bool isReachable = false; if (requiresPath && !WorldEditor.WorldEditorManager.IsWorldEditorActive) { // Check if path between old and new position is possible GridPathfinder ptf = new GridPathfinder(Grid.grid); List <Vector2Int> path = ptf.GetPath(AttachedEntity.BookmarkedCoordinates, targetCoordinates); isReachable = path != null; } else { // Check if the new position is vacant isReachable = !Grid.grid.CheckCollisionFlags(targetCoordinates, AttachedEntity.GetCollisionFlags()); } if (isReachable) { // Can move to new position AttachedEntity.Move(targetCoordinates); } else { if (WorldEditor.WorldEditorManager.IsWorldEditorActive) { // Cannot move to selected position - abort placement return; } else { // Cannot move to new position - go back to old position AttachedEntity.LoadBookmark(); } } DestroyGridHighlight(); // Update collision data AttachedEntity.UpdateCollision(); HasSelection = false; isSelected = false; UpdateRenderers(); arrow.positionCount = 0; }
private GridPosition[] SafeBuildPath(GridPosition from, GridPosition to) { if (size.Contains(from) && size.Contains(to)) { return(GridPathfinder.FindPath(from, to, geometry.Value, size)); } else if (size.Contains(to)) { return(new[] { to }); } else { return(new GridPosition[] { }); } }
public override void OnInspectorGUI() { DrawDefaultInspector(); GridPathfinder gridPathfinder = (GridPathfinder)target; if (GUILayout.Button("Debug print route result.")) { Queue <Vector2Int> path = gridPathfinder.GetPathToCell(gridPathfinder.debugTargetPosition); string pathString = ""; foreach (Vector2Int vector2Int in path.ToArray()) { pathString += vector2Int.ToString() + ", "; } Debug.Log(pathString); } }
public List <GridNode> FindPath(GridNode start, GridNode end) { return(GridPathfinder.FindPath(start, end)); }