示例#1
0
        private Dictionary <Vector3Int, Direction> FindFreeSpacesAroundRoad(List <Vector3Int> roadPositions)
        {
            Dictionary <Vector3Int, Direction> freeSpaces = new Dictionary <Vector3Int, Direction>();

            foreach (var position in roadPositions)
            {
                var neighbourDirections = PlacementHelper.FindNeighbour(position, roadPositions);
                foreach (Direction direction in Enum.GetValues(typeof(Direction)))
                {
                    if (neighbourDirections.Contains(direction) == false)
                    {
                        var newPosition = position + PlacementHelper.GetOffsetFromDirection(direction);
                        if (freeSpaces.ContainsKey(newPosition))
                        {
                            continue;
                        }
                        freeSpaces.Add(newPosition, PlacementHelper.GetReverseDirection(direction));
                    }
                }
            }
            return(freeSpaces);
        }
示例#2
0
        public void FixRoad()
        {
            foreach (var position in fixRoadCandidates)
            {
                List <Direction> neighbourDirections = PlacementHelper.FindNeighbour(position, roadDictionary.Keys);

                Quaternion rotation = Quaternion.identity;

                if (neighbourDirections.Count == 1)
                {
                    Destroy(roadDictionary[position]);
                    if (neighbourDirections.Contains(Direction.Down))
                    {
                        rotation = Quaternion.Euler(0, 90, 0);
                    }
                    else if (neighbourDirections.Contains(Direction.Left))
                    {
                        rotation = Quaternion.Euler(0, 180, 0);
                    }
                    else if (neighbourDirections.Contains(Direction.Up))
                    {
                        rotation = Quaternion.Euler(0, -90, 0);
                    }
                    roadDictionary[position] = Instantiate(roadEnd, position, rotation, transform);
                }
                else if (neighbourDirections.Count == 2)
                {
                    if (
                        neighbourDirections.Contains(Direction.Up) && neighbourDirections.Contains(Direction.Down) ||
                        neighbourDirections.Contains(Direction.Right) && neighbourDirections.Contains(Direction.Left)
                        )
                    {
                        continue;
                    }
                    Destroy(roadDictionary[position]);
                    if (neighbourDirections.Contains(Direction.Up) && neighbourDirections.Contains(Direction.Right))
                    {
                        rotation = Quaternion.Euler(0, 90, 0);
                    }
                    else if (neighbourDirections.Contains(Direction.Right) && neighbourDirections.Contains(Direction.Down))
                    {
                        rotation = Quaternion.Euler(0, 180, 0);
                    }
                    else if (neighbourDirections.Contains(Direction.Down) && neighbourDirections.Contains(Direction.Left))
                    {
                        rotation = Quaternion.Euler(0, -90, 0);
                    }
                    roadDictionary[position] = Instantiate(roadCorner, position, rotation, transform);
                }
                else if (neighbourDirections.Count == 3)
                {
                    Destroy(roadDictionary[position]);
                    if (neighbourDirections.Contains(Direction.Right) &&
                        neighbourDirections.Contains(Direction.Down) &&
                        neighbourDirections.Contains(Direction.Left)
                        )
                    {
                        rotation = Quaternion.Euler(0, 90, 0);
                    }
                    else if (neighbourDirections.Contains(Direction.Down) &&
                             neighbourDirections.Contains(Direction.Left) &&
                             neighbourDirections.Contains(Direction.Up))
                    {
                        rotation = Quaternion.Euler(0, 180, 0);
                    }
                    else if (neighbourDirections.Contains(Direction.Left) &&
                             neighbourDirections.Contains(Direction.Up) &&
                             neighbourDirections.Contains(Direction.Right))
                    {
                        rotation = Quaternion.Euler(0, -90, 0);
                    }
                    roadDictionary[position] = Instantiate(road3way, position, rotation, transform);
                }
                else
                {
                    Destroy(roadDictionary[position]);
                    roadDictionary[position] = Instantiate(road4way, position, rotation, transform);
                }
            }
        }