Exemple #1
0
    // Update is called once per frame
    void Update()
    {
        if (isLocalPlayer && player != null && (player.state == PlayerState.BUILDING || player.state == PlayerState.SETUP))
        {
            Ray        ray = GameManager.Instance.mainCamera.ScreenPointToRay(Input.mousePosition);
            RaycastHit hit;
            bool       hitSuccess = Physics.Raycast(ray, out hit, 100f);

            if (hitSuccess)
            {
                // Inspection
                if (hit.collider.gameObject.GetComponent <Inspectable>() != null)
                {
                    GameManager.Instance.guiManager.inspectionText.text = hit.collider.gameObject.GetComponent <Inspectable>().inspectionText;
                }
                else
                {
                    GameManager.Instance.guiManager.inspectionText.text = "";
                }

                // Should only be able to place during placement phase on this player's turn.
                if (GameManager.Instance.IsPlayerTurn(player))
                {
                    // Placement
                    BoardHandler boardHandler = GameManager.Instance.GetGame().GetBoardHandler();

                    VertexRenderer vertex = hit.collider.gameObject.GetComponent <VertexRenderer>();
                    EdgeRenderer   edge   = hit.collider.gameObject.GetComponent <EdgeRenderer>();

                    // Show valid placement option if possible
                    if (vertex != null || edge != null)
                    {
                        // Settlement
                        if (vertex != null)
                        {
                            // Show ghost for settlement
                            if (boardHandler.CanPlaceSettlement(player, vertex.col, vertex.row, vertex.vertexSpec))
                            {
                                UpdatePlacementGhost(settlementPrefab, vertex.transform);
                                if (Input.GetKeyDown(GameManager.PLACEMENT_KEY))
                                {
                                    playerController.CmdPlaceSettlement(vertex.col, vertex.row, (int)vertex.vertexSpec);
                                }
                            }
                            else if (boardHandler.CanPlaceCity(player, vertex.col, vertex.row, vertex.vertexSpec))
                            {
                                UpdatePlacementGhost(cityPrefab, vertex.transform);
                                if (Input.GetKeyDown(GameManager.PLACEMENT_KEY))
                                {
                                    playerController.CmdPlaceCity(vertex.col, vertex.row, (int)vertex.vertexSpec);
                                }
                            }
                        }

                        // Road
                        if (edge != null)
                        {
                            // Show ghost for road
                            if (boardHandler.CanPlaceRoad(player, edge.col, edge.row, edge.edgeSpec))
                            {
                                UpdatePlacementGhost(roadPrefab, edge.transform);
                                if (Input.GetKeyDown(GameManager.PLACEMENT_KEY))
                                {
                                    playerController.CmdPlaceRoad(edge.col, edge.row, (int)edge.edgeSpec);
                                }
                            }
                        }
                    }
                }

                else
                {
                    DestroyPlacementGhost();
                }
            }
        }

        if (player != null)
        {
            int playerIndex = GameManager.Instance.GetGame().GetPlayerIndexById(player.GetId());
            color = GameManager.Instance.playerColors[playerIndex];
            transform.position = GameManager.Instance.playerPositions[playerIndex];
            transform.rotation = Quaternion.Euler(GameManager.Instance.playerRotations[playerIndex]);
        }
    }