Пример #1
0
        private void EditMode()
        {
            if (Input.GetMouseButtonDown(0))
            {
                Ray          ray = Camera.main.ScreenPointToRay(Input.mousePosition);
                RaycastHit2D hit = Physics2D.GetRayIntersection(ray);

                if (hit.collider != null)
                {
                    // Store the tile to be destroyed
                    GameObject oldTile = hit.collider.gameObject;
                    oldTile.GetComponent <HexTileEditor>().ChangeTile(this);
                }
            }

            // Saving current hex map
            if (Input.GetKeyDown(KeyCode.S))
            {
                HexMapFileSaver.SaveFile(this.tiles);
            }
        }
Пример #2
0
        public void Awake()
        {
            this.overworldGameState = OverworldState.PLANNING;

            // Delegate control of map loading to the OverworldManager.
            List <HexMapCsv> file = null;

            // Load the default map
            if (string.IsNullOrEmpty(hexGrid.mapToLoad))
            {
                HexGridGenerator.GenerateDefault(hexGrid, hexGrid.width, hexGrid.height);
            }
            // Load from file
            else
            {
                file = HexMapFileSaver.ReadFile(hexGrid.mapToLoad);
                HexGridGenerator.GenerateFromFile(hexGrid, file);
            }

            this.monsterManager.SetInitialSpawn(this.hexGrid, file);

            OverworldEventManager.Instance().onHexTileClicked += ProcessTileSelection;
        }
Пример #3
0
    /// <summary>
    /// Generate a HexGrid by providing a filename to be read, and then generated from.
    /// </summary>
    /// <param name="grid"></param>
    /// <param name="filename"></param>
    public static void GenerateFromFile(HexGrid grid, string filename)
    {
        List <HexMapCsv> file = HexMapFileSaver.ReadFile(filename);

        // Create a throwaway tile so that we can get the dimensions of it.
        Vector2 spriteSize = GetTileSize();

        foreach (HexMapCsv row in file)
        {
            if (row.TileType != TileType.Empty)
            {
                Debug.Log("HELLO");
            }

            int x = row.X;
            int z = row.Z;

            float mod = z % 2;

            Vector2 position = new Vector2((x * spriteSize.x) + ((spriteSize.x * 0.5f) * mod), (z * spriteSize.y) * 0.75f);

            grid.Tiles.Add(HexTile.Create(grid, row.TileType, position, new Vector2(x, z)));
        }
    }