Exemple #1
0
 private void VisualizeUsingPrimitives(MapGrid grid, MapData data)
 {
     PlaceStartAndExitPoints(data);
     for (int i = 0; i < data.obstacleArray.Length; i++)
     {
         if (data.obstacleArray[i])
         {
             var positionOnGrid = grid.CalculateCoordinatesFromIndex(i);
             if (positionOnGrid == data.startPosition || positionOnGrid == data.exitPosition)
             {
                 continue;
             }
             grid.SetCell(positionOnGrid.x, positionOnGrid.z, CellObjectType.Obstacle);
             if (PlaceKnightObstacle(data, positionOnGrid))
             {
                 continue;
             }
             if (dictionaryOfObstacles.ContainsKey(positionOnGrid) == false)
             {
                 CreateIndicator(positionOnGrid, Color.white, PrimitiveType.Cube);
             }
         }
     }
 }
Exemple #2
0
        private void VisualizeUsingPrefabs(MapGrid grid, MapData data)
        {
            for (int i = 0; i < data.path.Count; i++)
            {
                var position = data.path[i];
                if (position != data.exitPosition)
                {
                    grid.SetCell(position.x, position.z, CellObjectType.Road);
                }
            }
            for (int col = 0; col < grid.Width; col++)
            {
                for (int row = 0; row < grid.Length; row++)
                {
                    var cell     = grid.GetCell(col, row);
                    var position = new Vector3(cell.X, 0, cell.Z);

                    var index = grid.CalculateIndexFromCoordinates(position.x, position.z);
                    if (data.obstacleArray[index] && cell.IsTaken == false)
                    {
                        cell.ObjectType = CellObjectType.Obstacle;
                    }
                    Direction previousDirection = Direction.None;
                    Direction nextDirection     = Direction.None;
                    switch (cell.ObjectType)
                    {
                    case CellObjectType.Empty:
                        CreateIndicator(position, tileEmpty);
                        break;

                    case CellObjectType.Road:
                        if (data.path.Count > 0)
                        {
                            previousDirection = GetDirectionOfPreviousCell(position, data);
                            nextDirection     = GetDicrectionOfNextCell(position, data);
                        }
                        if (previousDirection == Direction.Up && nextDirection == Direction.Right || previousDirection == Direction.Right && nextDirection == Direction.Up)
                        {
                            CreateIndicator(position, roadTileCorner, Quaternion.Euler(0, 90, 0));
                        }
                        else if (previousDirection == Direction.Right && nextDirection == Direction.Down || previousDirection == Direction.Down && nextDirection == Direction.Right)
                        {
                            CreateIndicator(position, roadTileCorner, Quaternion.Euler(0, 180, 0));
                        }
                        else if (previousDirection == Direction.Down && nextDirection == Direction.Left || previousDirection == Direction.Left && nextDirection == Direction.Down)
                        {
                            CreateIndicator(position, roadTileCorner, Quaternion.Euler(0, -90, 0));
                        }
                        else if (previousDirection == Direction.Left && nextDirection == Direction.Up || previousDirection == Direction.Up && nextDirection == Direction.Left)
                        {
                            CreateIndicator(position, roadTileCorner);
                        }
                        else if (previousDirection == Direction.Right && nextDirection == Direction.Left || previousDirection == Direction.Left && nextDirection == Direction.Right)
                        {
                            CreateIndicator(position, roadStraight, Quaternion.Euler(0, 90, 0));
                        }
                        else
                        {
                            CreateIndicator(position, roadStraight);
                        }

                        break;

                    case CellObjectType.Obstacle:
                        int randomIndex = Random.Range(0, environmentTiles.Length);
                        CreateIndicator(position, environmentTiles[randomIndex]);
                        break;

                    case CellObjectType.Start:
                        if (data.path.Count > 0)
                        {
                            nextDirection = GetDirectionFromVectors(data.path[0], position);
                        }
                        if (nextDirection == Direction.Right || nextDirection == Direction.Left)
                        {
                            CreateIndicator(position, startTile, Quaternion.Euler(0, 90, 0));
                        }
                        else
                        {
                            CreateIndicator(position, startTile);
                        }

                        break;

                    case CellObjectType.Exit:
                        if (data.path.Count > 0)
                        {
                            previousDirection = GetDirectionOfPreviousCell(position, data);
                            switch (previousDirection)
                            {
                            case Direction.Right:
                                CreateIndicator(position, exitTile, Quaternion.Euler(0, 90, 0));
                                break;

                            case Direction.Left:
                                CreateIndicator(position, exitTile, Quaternion.Euler(0, -90, 0));
                                break;

                            case Direction.Down:
                                CreateIndicator(position, exitTile, Quaternion.Euler(0, 180, 0));
                                break;

                            default:
                                CreateIndicator(position, exitTile);
                                break;
                            }
                        }

                        break;

                    default:
                        break;
                    }
                }
            }
        }