コード例 #1
0
        /// <summary>
        /// Sets the material of this cell to a specified color.
        /// </summary>
        /// <param name="position">The world space coordinates under which a HexCell resides..</param>
        /// <param name="color">The color to set the tile</param>
        public void ColorCell(Vector3 position, Color color)
        {
            position = transform.InverseTransformPoint(position);
            MapCoordinates coordinates = MapCoordinates.FromPosition(position);
            int            index       = coordinates.X + coordinates.Z * Width + coordinates.Z / 2;
            HexCell        cell        = _cells[index];

            cell.Color = color;
            _hexMesh.Triangulate(_cells);
        }
コード例 #2
0
 private void OperationSelecter()
 {
     switch (curMode)
     {
     case BattleOperationMode.SelectTarget:
         Vector3 targetPos;
         if (GameOperation.Instance.MapPosSelector(out targetPos))
         {
             selectPos = MapCoordinates.FromPosition(targetPos);
         }
         ;
         break;
     }
 }
コード例 #3
0
 private void OnSingleDown(GestureData data)
 {
     if (curMode == BattleOperationMode.Normal)
     {
         Vector3 targetPos;
         if (GameOperation.Instance.MapPosSelector(out targetPos))
         {
             if (onTouchMap != null)
             {
                 onTouchMap.Invoke(MapCoordinates.FromPosition(targetPos));
             }
         }
         ;
     }
 }
コード例 #4
0
    void CreateCell(int x, int z, int i)
    {
        Vector3 position;

        position.x = (x + 0.5f) * MapConstant.sideLength;
        position.y = 0;
        position.z = (z + 0.5f) * MapConstant.sideLength;

        MapCell cell = cells[i] = Instantiate <MapCell>(cellPrefab);

        cell.transform.SetParent(mapCellRoot.transform, false);
        cell.transform.localPosition = position;
        cell.coordinates             = MapCoordinates.FromPosition(position);
        cell.color = defaultColor;

        Text label = Instantiate <Text>(cellLabelPrefab, gridCanvas.transform, false);

        label.rectTransform.SetParent(gridCanvas.transform);
        label.rectTransform.anchoredPosition = new Vector2(position.x, position.z);
        label.text = cell.coordinates.ToStringOnSeparateLines();
    }
コード例 #5
0
    private void OnLongTap(GestureData data)
    {
        if (selectUnit != null)
        {
            Vector3        tapMapPos;
            MapCoordinates tapMapCoord;

            //检测 长按的地图位是否包含有效单位
            if (GameOperation.Instance.MapPosSelector(data.pos, out tapMapPos))
            {
                tapMapCoord = MapCoordinates.FromPosition(tapMapPos);
                if (selectPath.Count > 0)
                {
                    MapCoordinates pathEnd   = selectPath[selectPath.Count - 1];
                    var            addPath   = MapManager.Instance.FindPath(pathEnd, tapMapCoord);
                    var            astarPath = MapManager.Instance.FindPath(selectUnit.pos, tapMapCoord);


                    if ((selectPath.Count + addPath.Count - 1) > astarPath.Count)
                    {
                        selectPath = astarPath;
                    }
                    else
                    {
                        for (int i = 1; i < addPath.Count; ++i)
                        {
                            selectPath.Add(addPath[i]);
                        }
                    }
                }
                else
                {
                    var astarPath = MapManager.Instance.FindPath(selectUnit.pos, tapMapCoord);

                    selectPath = astarPath;
                }
            }
        }
    }
コード例 #6
0
    //=========================== event ================================

    private void OnLongTapDown(GestureData data)
    {
        Vector3        tapMapPos;
        MapCoordinates tapMapCoord;
        Unit           unit;

        //检测 长按的地图位是否包含有效单位
        if (GameOperation.Instance.MapPosSelector(data.pos, out tapMapPos))
        {
            tapMapCoord = MapCoordinates.FromPosition(tapMapPos);
            if (MapManager.Instance.FindUnit(tapMapCoord, out unit))
            {
                selectUnit = unit;
                SwitchOperationMode(BattleOperationMode.SelectPath);
            }
            else
            {
                return;
            }
        }
        ;
    }