예제 #1
0
    void OnGUI()
    {
        currentAmmo   = weaponController.GetWeaponCurrentAmmo();
        spareAmmo     = weaponController.GetWeaponSpareAmmo();
        currentHealth = healthController.GetCurrentHP();

        if (choosingTeam)            // true at start of game only
        {
            Screen.lockCursor         = false;
            movementController.inMenu = true;
            weaponController.DisableWeapons();

            GUI.Label(new Rect(Screen.width / 2, Screen.height / 2 - 25, 100, 10), "Choose your team...", HUDStyle_small);
            GUI.DrawTexture(new Rect(Screen.width / 2 - 320, Screen.height / 2 - 40, 640, 100), gui_background, ScaleMode.StretchToFill);

            if (GUI.Button(new Rect(Screen.width / 2 - 300, Screen.height / 2, 300, 40), "Red Team", RedTeamStyle))
            {
                choosingTeam              = false;
                hudEnabled                = true;
                Screen.lockCursor         = true;
                movementController.inMenu = false;
                weaponController.EnableWeapons();
                networkManager.EnterBattle(1);                 // Enter the battle in team 1 (red)
            }
            if (GUI.Button(new Rect(Screen.width / 2, Screen.height / 2, 300, 40), "Blue Team", BlueTeamStyle))
            {
                choosingTeam              = false;
                hudEnabled                = true;
                Screen.lockCursor         = true;
                movementController.inMenu = false;
                weaponController.EnableWeapons();
                networkManager.EnterBattle(2);                 // Enter the battle in team 2 (blue)
            }
        }

        if (switchingTeam)            // true if player selects the "switch team" option from the in-game menu
        {
            Screen.lockCursor         = false;
            movementController.inMenu = true;
            hudEnabled = false;
            weaponController.DisableWeapons();

            GUI.Label(new Rect(Screen.width / 2, Screen.height / 2 - 25, 100, 10), "Choose your team...", HUDStyle_small);
            GUI.DrawTexture(new Rect(Screen.width / 2 - 320, Screen.height / 2 - 40, 640, 100), gui_background, ScaleMode.StretchToFill);

            if (GUI.Button(new Rect(Screen.width / 2 - 300, Screen.height / 2, 300, 40), "Red Team", RedTeamStyle))
            {
                switchingTeam             = false;
                hudEnabled                = true;
                isMenuOpen                = false;
                Screen.lockCursor         = true;
                movementController.inMenu = false;
                weaponController.EnableWeapons();
                networkManager.networkView.RPC("SwitchTeam", RPCMode.All, networkManager.my.playerInfo, 1);
            }
            if (GUI.Button(new Rect(Screen.width / 2, Screen.height / 2, 300, 40), "Blue Team", BlueTeamStyle))
            {
                switchingTeam             = false;
                hudEnabled                = true;
                isMenuOpen                = false;
                Screen.lockCursor         = true;
                movementController.inMenu = false;
                weaponController.EnableWeapons();
                networkManager.networkView.RPC("SwitchTeam", RPCMode.All, networkManager.my.playerInfo, 2);
            }
        }

        if (hudEnabled)            // true after team selection is complete (in a team match) or immediately at the start of the game (if free-for-all)

        {
            GUI.DrawTexture(new Rect(crosshair_xMin, crosshair_yMin, crosshairImage.width, crosshairImage.height), crosshairImage);
            GUI.Label(new Rect(Screen.width - 200, Screen.height - 100, 200, 50), "Boosts: " + boostController.currBoosts, HUDStyle_small);
            GUI.Label(new Rect(Screen.width - 200, Screen.height - 50, 200, 50), currentAmmo + " / " + spareAmmo, HUDStyle_large);

            currWidth = 300 * (currentHealth / maxHealth);

            GUI.Label(new Rect(0, Screen.height - 75, 90, 18), "Armor:", HUDStyle_small);
            GUI.Label(new Rect(140, Screen.height - 80, 30, 30), " " + currentHealth, HUDStyle_large);

            GUI.BeginGroup(new Rect(20, Screen.height - 50, currWidth, 35));;
            GUI.DrawTexture(new Rect(0, 0, 400, 35), healthBar, ScaleMode.StretchToFill);
            GUI.EndGroup();
        }

        if (isMenuOpen)                       // on pressing "escape"
        {
            if (networkManager.gameType == 0) // standard menu
            {
                GUI.DrawTexture(new Rect(Screen.width - 375, 25, 350, 100), gameMenuBG, ScaleMode.StretchToFill);

                if (GUI.Button(new Rect(Screen.width - 350, 40, 300, 40), "Exit to Main Menu", GameMenuStyle))
                {
                    NetworkManager.DisconnectFromServer();
                }
            }
            else                 // menu with switch team option
            {
                GUI.DrawTexture(new Rect(Screen.width - 375, 25, 350, 150), gameMenuBG, ScaleMode.StretchToFill);

                if (GUI.Button(new Rect(Screen.width - 350, 40, 300, 40), "Exit to Main Menu", GameMenuStyle))
                {
                    NetworkManager.DisconnectFromServer();
                }

                if (GUI.Button(new Rect(Screen.width - 350, 100, 300, 40), "Change Team", GameMenuStyle))
                {
                    switchingTeam = true;
                }
            }
        }

        if (isScoreboardOpen || finalScoreboardOpen)            // on pressing "tab"

        {
            if (networkManager.gameType == 0)               // Free-for-all scoreboard (no team separation)

            {
                GUI.DrawTexture(new Rect(50, 50, Screen.width - 100, Screen.height - 150), scoreboardBG, ScaleMode.StretchToFill);

                var newList = allPlayers.OrderByDescending(x => x.score).ToList();

                for (int i = 0; i < newList.Count; i++)
                {
                    if (networkManager.FindPlayer(newList[i].playerInfo) == networkManager.my)                         // Highlight the name/score in yellow if it's me
                    {
                        GUI.Label(new Rect(150, 100 + (i + 1) * 50, 500, 20), newList[i].name + "  " + newList[i].score, MyScoreStyle);
                    }
                    else
                    {
                        GUI.Label(new Rect(150, 100 + (i + 1) * 50, 500, 20), newList[i].name + "  " + newList[i].score, ScoreBoardStyle);
                    }
                }

                if (finalScoreboardOpen)
                {
                    GUI.Label(new Rect(300, Screen.height - 300, 500, 20), newList[0].name + " wins!", ScoreBoardStyle);
                }
            }
            else                 // Team scoreboard

            {
                GUI.DrawTexture(new Rect(50, 50, Screen.width - 100, Screen.height - 150), scoreboardBG, ScaleMode.StretchToFill);

                var redList  = redPlayers.OrderByDescending(x => x.score).ToList();
                var blueList = bluePlayers.OrderByDescending(x => x.score).ToList();

                GUI.Label(new Rect(150, 100, 500, 20), "Red score: " + networkManager.redScore, ScoreBoardStyle);
                GUI.Label(new Rect(Screen.width / 2 + 50, 100, 500, 20), "Blue score: " + networkManager.blueScore, ScoreBoardStyle);

                for (int r = 0; r < redList.Count; r++)                   //print out red team's scores

                {
                    if (networkManager.FindPlayer(redList[r].playerInfo) == networkManager.my)
                    {
                        GUI.Label(new Rect(150, 150 + (r + 1) * 50, 500, 20), redList[r].name + "  " + redList[r].score, MyScoreStyle);
                    }
                    else
                    {
                        GUI.Label(new Rect(150, 150 + (r + 1) * 50, 500, 20), redList[r].name + "  " + redList[r].score, ScoreBoardStyle);
                    }
                }
                for (int b = 0; b < redList.Count; b++)                   //print out blue team's scores

                {
                    if (networkManager.FindPlayer(blueList[b].playerInfo) == networkManager.my)
                    {
                        GUI.Label(new Rect(Screen.width / 2 + 50, 150 + (b + 1) * 50, 500, 20), blueList[b].name + "  " + blueList[b].score, MyScoreStyle);
                    }
                    else
                    {
                        GUI.Label(new Rect(Screen.width / 2 + 50, 150 + (b + 1) * 50, 500, 20), blueList[b].name + "  " + blueList[b].score, ScoreBoardStyle);
                    }
                }

                if (finalScoreboardOpen)
                {
                    if (networkManager.redScore > networkManager.blueScore)
                    {
                        GUI.Label(new Rect(300, Screen.height - 300, 500, 20), "Red team wins!", ScoreBoardStyle);
                    }
                    else
                    {
                        GUI.Label(new Rect(300, Screen.height - 300, 500, 20), "Blue team wins!", ScoreBoardStyle);
                    }
                }
            }
        }
    }