Ejemplo n.º 1
0
 private void DevisualizeMoves()
 {
     foreach (var move in _visualizedMoves)
     {
         _visualization.ClearSelectedMove(move);
     }
     _visualizedMoves.Clear();
 }
Ejemplo n.º 2
0
    public virtual void VisualizeMove()
    {
        //Only visualize if allowed to move.
        if (!_isSelectingMove)
        {
            return;
        }


        if (_visualizedMove != null)
        {
            if (InputManager.GetMouseButtonDown(0))
            {
                _moveChoiceCallback(_visualizedMove);
                _isSelectingMove = false;
                _visualization.ClearSelectedMove(_visualizedMove.Location);
                _visualizedMove = null;
            }
        }

        var        ray = _camera.ScreenPointToRay(InputManager.mousePosition);
        RaycastHit hit;

        if (Physics.Raycast(ray, out hit, 100f))
        {
            if (hit.transform == null || hit.transform.GetComponent <Tile>() == null)
            {
                return;
            }
            var hitLocation = hit.transform.GetComponent <Tile>().Location;


            if (hitLocation == _visualizedLocation)
            {
                return;
            }

            if (_visualizedMove != null)
            {
                _visualization.ClearSelectedMove(_visualizedMove.Location);
            }
            _visualizedLocation = hitLocation;

            var candidateMove = new Move(_visualizedLocation);

            _visualizedMove = candidateMove;

            foreach (var move in _validMoves)
            {
                if (move.Equals(candidateMove))
                {
                    _visualization.SelectMove(candidateMove.Location, _board.IsLeftPlayerMove ? TileState.Black :TileState.White);
                    return;
                }
            }

            _visualizedMove = null;
        }
        else
        {
            //No longer mousing over a valid move
            if (_visualizedMove != null)
            {
                _visualization.ClearSelectedMove(_visualizedMove.Location);
                _visualizedMove = null;
            }
        }
    }