Exemplo n.º 1
0
    protected void MakeHexMap()
    {
        switch (mapShape)
        {
        case MapShape.Rectangle:
            HexMap = new HexMap <TileData, EdgeData>(HexMapBuilder.CreateRectangularShapedMap(rectDimensions));
            break;

        case MapShape.Hexagon:
            HexMap = new HexMap <TileData, EdgeData>(HexMapBuilder.CreateHexagonalShapedMap(hexRadius));
            break;

        default:
            throw new ArgumentOutOfRangeException();
        }



        TileObjects = new GameObject[HexMap.TilesByPosition.Count];

        foreach (Tile <TileData> tile in HexMap.Tiles)
        {
            InstantiateNewTerrainTile(grassTilePrefab, tile);
        }
    }
        private List <GameObject> visionMarkers;                     //we will use this to display the border of the vision range

        void Start()
        {
            hexMap   = new HexMap <int>(HexMapBuilder.CreateHexagonalShapedMap(mapRadius), null); //creates a HexMap using one of the pre-defined shapes in the static MapBuilder Class
            hexMouse = gameObject.AddComponent <HexMouse>();                                      //we attach the HexMouse script to the same gameObject this script is attached to, could also attach it anywhere else
            hexMouse.Init(hexMap);                                                                //initializes the HexMouse

            InitMap();
            SetupCamera(); //set camera settings so that the map is captured by it
        }
    private void MakeHexMap()
    {
        hexMap        = new HexMap <int, bool>(HexMapBuilder.CreateHexagonalShapedMap(mapRadius));
        tileObjects   = new GameObject[hexMap.TilesByPosition.Count];
        visionMarkers = new List <GameObject>();

        foreach (Tile <int> tile in hexMap.Tiles)
        {
            var         types             = Enum.GetValues(typeof(TerrainType));
            Random      random            = new Random();
            TerrainType randomTerrainType = (TerrainType)types.GetValue(Random.Range(0, types.Length));

            GameObject tilePrefab = GetPrefab(randomTerrainType);
            Debug.Log(tilePrefab + " --- " + tile);
            InstantiateNewTerrainTile(tilePrefab, tile);
            tile.Data = (int)randomTerrainType;
        }
    }
Exemplo n.º 4
0
    private GameObject[] tileObjects; // this will contain all the GameObjects for visualisation purposes, their array index corresponds with the index of our Tiles

    // TODO move the settings to the GameController
    /// <summary>
    /// Generates a new HexMap of environments, at the given offset
    /// </summary>
    /// <returns>The generated map</returns>
    public HexMap <Environment> GenerateMap(int offset)
    {
        Debug.Assert(tilePrefabs != null);

        HexMap <Environment> hexMap = new HexMap <Environment>(HexMapBuilder.CreateHexagonalShapedMap(mapSize), null);

        tileObjects = new GameObject[hexMap.TilesByPosition.Count];      //creates an array with the size equal to the number on tiles of the map
        Transform newMap = new GameObject("HexMap_" + offset).transform; // Make a new folder to put the tiles in

        foreach (var tile in hexMap.Tiles)
        {
            int        i        = Random.Range(0, tilePrefabs.Count);
            GameObject instance = Instantiate(tilePrefabs[i], newMap);
            tile.Data     = instance.GetComponent <Environment>();
            instance.name = instance.name + "_" + tile.Position;
            instance.transform.position = tile.CartesianPosition;
            tileObjects[tile.Index]     = instance;
        }

        return(hexMap);
    }