示例#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 GameObject[] tileObjects;                                            // this will contain all the GameObjects for visualisation purposes, their array index corresponds with the index of our Tiles


        void Start()
        {
            hexMap   = new HexMap <int, bool>(HexMapBuilder.CreateRectangularShapedMap(mapSize), 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
            tileObjects = new GameObject[hexMap.TilesByPosition.Count];                                 //creates an array with the size equal to the number on tiles of the map

            foreach (var tile in hexMap.Tiles)                                                          //loops through all the tiles, assigns them a random value and instantiates and positions a gameObject for each of them.
            {
                tile.Data = (Random.Range(0, 4));
                GameObject instance = GameObject.Instantiate(tilePrefab);
                instance.GetComponent <Renderer>().material = materials[tile.Data];
                instance.name = "MapTile_" + tile.Position;
                instance.transform.position = tile.CartesianPosition;
                tileObjects[tile.Index]     = instance;
            }

            foreach (var edge in hexMap.Edges) //we randomly spawn a GameObject on some corners (could be representing walls or rivers or anything else)
            {
                int randomNumber = Random.Range(0, 100);
                if (randomNumber > 89)
                {
                    edge.Data = true;
                    GameObject instance = GameObject.Instantiate(edgePrefab);
                    instance.name = "MapEdge_" + edge.Position;
                    instance.transform.position = edge.CartesianPosition;
                    instance.transform.rotation = Quaternion.Euler(0, edge.EdgeAlignmentAngle, 0);
                    //as we don't change the edges during runtime we don't need to add the gameObjects of the edges to an array as we don't need to manipulate them later on
                }
            }

            SetupCamera(); //set camera settings so that the map is captured by it
        }
示例#3
0
    void Start()
    {
        hexMap      = new HexMap(HexMapBuilder.CreateRectangularShapedMap(mapSize), null);
        tiles       = new TileData[hexMap.TileCount];
        tileObjects = new GameObject[hexMap.TileCount];

        hexMouse = gameObject.AddComponent <HexMouse>();
        hexMouse.Init(hexMap);
        SetupCamera();
        InitMapData();
        InitMapVisualisation();
    }
示例#4
0
        private HexMap <int> hexMap;                                             // our map. For this example we create a map where an integer represents the data of each tile (which we don't actually use yet in this example)


        void Start()
        {
            hexMap = new HexMap <int>(HexMapBuilder.CreateRectangularShapedMap(mapSize), null); //creates a HexMap using one of the pre-defined shapes in the static MapBuilder Class

            foreach (var tile in hexMap.Tiles)                                                  //loops through all the tiles, assigns them a random value and instantiates and positions a gameObject for each of them.
            {
                GameObject instance = GameObject.Instantiate(tilePrefab);
                instance.transform.position = tile.CartesianPosition;
            }

            Camera.main.transform.position = new Vector3(hexMap.MapSizeData.center.x, 4, hexMap.MapSizeData.center.z); // centers the camera and moves it 5 units above the XZ-plane
            Camera.main.orthographic       = true;                                                                     //for this example we use an orthographic camera.
            Camera.main.transform.rotation = Quaternion.Euler(90, 0, 0);                                               //rotates the camera to it looks at the XZ-plane
            Camera.main.orthographicSize   = hexMap.MapSizeData.extents.z * 2 * 0.8f;                                  // sets orthographic size of the camera.
        }