コード例 #1
0
        private void CheckTileClick()
        {
            if (Input.GetMouseButtonDown(0))
            {
                mouseDownPosition = Input.mousePosition;
            }

            // Check left click released.
            if (!Input.GetMouseButtonUp(0))
            {
                return;
            }

            // Check for drag.
            if (Input.mousePosition != mouseDownPosition)
            {
                return;
            }

            // Check UI click-through.
            if (EventSystem.current.IsPointerOverGameObject())
            {
                return;
            }

            // Vector3 test = Camera.main.ScreenToWorldPoint(Input.mousePosition);
            // Debug.Log("World point:" + test);
            Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);

            Vector3    worldPoint    = ray.GetPoint(-ray.origin.z / ray.direction.z);
            Vector3Int position      = map.WorldToCell(worldPoint);
            MapTile    someOtherTile = GetTileWithZ(position);

            if (someOtherTile != null)
            {
                // Notify the click event for things like the ToolBar or other user feedback.
                TileClickedEvent?.Invoke(this, new TileClickArgs(someOtherTile));

                // Focus onto structure
                if (someOtherTile.Structure != null)
                {
                    camera.GetComponent <CameraDrag>().PanTo(new Vector3(worldPoint.x, worldPoint.y, 0));
                }
            }
        }
コード例 #2
0
ファイル: BaseUnit.cs プロジェクト: jcnast/Commander
    void TileClicked(TileClickedEvent e)
    {
        if(curState == UnitState.RecievingOrders){
            // if activePathTiles exist
            if(activePathTiles.Count > 0){
                // determine if clicked tile is active
                int index = activePathTiles.FindIndex((x) => (x.CurrentTile == e.baseTile));
                if(index >= 0){
                    // if tile is active, set position of order
                    List<Vector3> orderPath = new List<Vector3>();

                    // follow Path Tiles back to null to create list of path tiles
                    while(activePathTiles[index].CurrentTile != null){
                        // add tile to path
                        orderPath.Add(activePathTiles[index].CurrentTile.transform.position);
                        // find next tile
                        index = activePathTiles.FindIndex(x => x.CurrentTile == activePathTiles[index].PreviousTile);
                        // if no more in path, stop
                        if(index < 0){
                            break;
                        }
                    }
                    SetOrderValues(orderPath, e.baseTile);

                    // and clear active tiles (as one was chosen)
                    ClearActiveTiles();
                }else{ // Tile is not a member of activePathTiles
                    // do nothing
                }
            }else{
                if(orderUI.activeSelf){// if UI is open, close UI
                    orderUI.SetActive(false);
                }else if(activePathTiles.Count != 0){// if tiles are active
                    // do nothing
                }
            }
        }
    }
コード例 #3
0
ファイル: SideManager.cs プロジェクト: jcnast/Commander
    // what to do when a tile was clicked
    void TileClicked(TileClickedEvent e)
    {
        // things to do during side set up (can only access the specific tiles)
        if(Array.Find(sidePieces, x => x == e.Tile.gameObject)){
            // if side is being selected, send event saying one has been chosen
            if(curState == SideState.SideSelect && !selected){
                selected = true;

                Events.instance.Raise( new SideSelectedEvent(gameObject));
                LightAllTiles(false);
            // place unit on one of the tiles along the side
            }else if(curState == SideState.UnitPlacing){
                Events.instance.Raise(new SingleUnitPlacedEvent(e.Tile, unitRotation));
            }
        }
    }
コード例 #4
0
ファイル: PlayerManager.cs プロジェクト: jcnast/Commander
 // what to do when a tile was clicked
 void TileClicked(TileClickedEvent e)
 {
 }