/// <summary>
        /// initialize all tiles
        /// </summary>
        public void InitAllTiles()
        {
            Dictionary <Vector3Int, float> tilesCost = new Dictionary <Vector3Int, float>();

            foreach (KeyValuePair <Vector3Int, TileBase> kv in m_Tiles)
            {
                TileBase tile = kv.Value;
                tile.Init();

                tile.SetColor(tile.m_Property.m_Type);

                if (tile.m_Property.m_Type == eTileType.Movable)
                {
                    if (tile.m_Unit == null)
                    {
                        tilesCost.Add(kv.Key, 1f);
                    }
                    else
                    {
                        tilesCost.Add(kv.Key, 0f);
                    }
                }
                else
                {
                    tilesCost.Add(kv.Key, 0f);
                }
            }

            m_Grid.UpdateGrid(tilesCost);

            m_MovableTiles.Clear();
            m_AttackableTiles.Clear();
            m_Paths.Clear();
        }
예제 #2
0
    protected virtual void GenerateGrid()
    {
        //for every pixel in image
        for (int x = 0; x < gridImage.width; x++)
        {
            for (int y = 0; y < gridImage.height; y++)
            {
                //get color pixel from grid image
                Color pixel = gridImage.GetPixel(x, y);

                //instantiate tile
                TileBase tile = Instantiate(SelectTile(pixel), transform);
                tile.transform.position = startPosition + new Vector3(x * tileSize.x, 0, y * tileSize.z);
                tile.transform.rotation = Quaternion.identity;

                //init tile and add to dictionary
                Vector2Int positionInGrid = new Vector2Int(x, y);
                tile.Init(pixel, positionInGrid);
                Grid.Add(positionInGrid, tile);
            }
        }
    }