void HandleInput() { Ray inputRay = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit2D [] hits = Physics2D.RaycastAll(inputRay.origin, inputRay.direction); GameObject target = hits.Select(h => h.collider.transform.gameObject) .FirstOrDefault(o => o.tag == "FutureMoveSpot"); if (target == null) { target = hits.Select(h => h.collider.transform.gameObject) .FirstOrDefault(o => o.tag == "GamePiece"); } if (target != null) { if (target.tag == "FutureMoveSpot") { FutureMoveSpotScript futureSpotScript = target.GetComponent <FutureMoveSpotScript>(); MakeMove(futureSpotScript.Move); } else if (target.tag == "GamePiece" && selectedPiece == null) { Piece thisPiece = NotationParser.GetPieceByNotation(target.name); if (currentBoard.ColorToPlay != thisPiece.color || !currentBoard.GetMoves().Any(m => m.pieceToMove.Equals(thisPiece))) { return; } bool alreadyPlaced = !currentBoard.unplayedPieces.Contains(thisPiece); List <Hex> hexes = null; if (alreadyPlaced) { hexes = currentBoard.AllMoves.Where(m => thisPiece.Equals(m.pieceToMove)).Select(m => m.hex).ToList(); } else { if (currentBoard.hivailableHexes.Count == 0) { currentBoard.RefreshDependantBoardData(); } if (thisPiece.color == PieceColor.White) { hexes = currentBoard.hivailableHexes.Where(kvp => kvp.Value.WhiteCanPlace).Select(kvp => kvp.Key).ToList(); } else { hexes = currentBoard.hivailableHexes.Where(kvp => kvp.Value.BlackCanPlace).Select(kvp => kvp.Key).ToList(); } } ShowFutureMoves(thisPiece, hexes); } } else { ClearFutureMoveObjects(); } }
public void ShowFutureMoves(Piece piece, List <Hex> hexes) { ClearFutureMoveObjects(); UnhighlightSelectedPiece(); selectedPiece = piece; HighlightSelectedPiece(); GameObject futureSpotObject = GameObject.Find("FutureMoveSpot"); foreach (Hex hex in hexes) { GameObject futureSpotInstance = Instantiate(futureSpotObject); FutureMoveSpotScript script = futureSpotInstance.GetComponent <FutureMoveSpotScript>(); var hexDrawing = GameService.GetFutureMoveDrawing(hex, 100, new Vector3()); futureSpotInstance.transform.SetPositionAndRotation(hexDrawing._center, Quaternion.identity); futureMoveObjects.Add(futureSpotInstance); script.Move = Move.GetMove(piece, hex); } }