예제 #1
0
        void Start()
        {
            var mapSize = HexTileMetrics.GetMapSzie(tilemapBackground);

            hexCellDebugTxtCanvas.BuildHexPosTxt(mapSize.x, mapSize.y);
            marginMeshTilemap.enabled = false;
        }
예제 #2
0
        /// <summary>
        /// 绘制标识网格
        /// </summary>
        private void DrawPrevuewCell()
        {
            if (GameDataCentre.IsAssetLoadCompleted == false)
            {
                return;
            }
            Vector2Int MouseCellPosition = GetMouseCellPosition();

            if (CurrentUnderCell != MouseCellPosition)
            {
                CurrentUnderCell = MouseCellPosition;
                TileBase tileBase;
                if (activeTileAssetName == "忽略")
                {
                    tileBase = GameDataCentre.GetRandomTileAssetDict("border");
                }
                else
                {
                    tileBase = GameDataCentre.GetRandomTileAssetDict(activeTileAssetName);
                }

                if (tileBase == null)
                {
                    Debug.LogWarning("TileAsset border didn't load");
                    return;
                }
                infoTileMap.DrawHexMeshTileCells(HexTileMetrics.GetCellInRange(CurrentUnderCell, brushSize).ToVector3Int(), tileBase);
            }
        }
예제 #3
0
        /// <summary>
        /// 检查到鼠标左键点击单元格是编辑单元格
        /// </summary>
        private void EditCell(Vector2Int cellPosition)
        {
            TileBase cell = tilemapBackground.GetTile(cellPosition.ToVector3Int());

            if (cell != null)
            {
                EditCell(HexTileMetrics.GetCellInRange(cellPosition, brushSize));
                //Debug.Log($"get cell {cell.name}");
            }
        }
예제 #4
0
        /// <summary>
        /// 显示 range 范围内其他单元格到计算坐标的距离
        /// </summary>
        /// <param name="calculayePosition">计算坐标</param>
        /// <param name="range">计算范围</param>
        private void CalculateDistance(Vector2Int source, Vector2Int destination)
        {
            var resultDict = HexTileMetrics.ShortestPath(m_HexGrid, source, destination);

            hexCellDebugTxtCanvas.Clear();
            int count = 1;

            hexCellDebugTxtCanvas.
            SetTxts(resultDict, resultDict.Select(x => (count += m_HexGrid[x].ThroughCost).ToString()).ToArray());
        }
예제 #5
0
 private void HexTileInputEvent_NewClick(object sender, HexTileInputEventArgs e)
 {
     //Debug.Log($"ClickButtomCoed:{e.ClickButtomCoed} ClickPosition:{e.ClickPosition}");
     if (SelectRoleEntity != null)
     {
         if (e.ClickButtomCoed == MouseButton.RightMouse)
         {
             SelectRoleEntity.MoveRole(HexTileMetrics.ShortestPath(hexGrid, SelectRoleEntity.RolePosition, e.ClickPosition));
         }
         if (e.ClickButtomCoed == MouseButton.LeftMouse && e.ClickPosition.ToVector3Int() != SelectRoleEntity.MoveComponent.CurrentRolePosition)
         {
             SelectRoleEntity.IsSelect = false;
             SelectRoleEntity          = null;
         }
     }
 }
예제 #6
0
        /// <summary>
        /// 从当前的Tielmap中重新初始化HexGrid
        /// </summary>
        public void ReIntiHexGrid()
        {
            Vector2Int mapSize = HexTileMetrics.GetMapSzie(tilemapBackground);

            HexCell[,] cells = new HexCell[mapSize.x, mapSize.y];
            m_HexGrid        = new HexGrid(
                hexCells: cells,
                gameAssetData: GameDataCentre,
                terrainThroughCostDict: GameDataCentre.TerrainThroughCostDict,
                hexTileMap: HexTileMap);

            for (int x = 0; x < mapSize.x; x++)
            {
                for (int y = 0; y < mapSize.y; y++)
                {
                    string     assetName;
                    Vector2Int callPosition = new Vector2Int(x, y);
                    try { assetName = tilemapBackground.GetTile(callPosition.ToVector3Int()).name; }
                    catch (NullReferenceException) { assetName = "Void00"; }
                    cells[x, y] = new HexCell(m_HexGrid, assetName, callPosition, HexGrid.CalculateNeighbor(callPosition));
                }
            }
            RoleManager.hexGrid = m_HexGrid;
        }