Inheritance: MonoBehaviour
Esempio n. 1
0
    void Update()
    {
        PhotonView photonView = PhotonView.Get(this);

        //When launching the match, if we haven't spawn yet we do
        if (inMatch)
        {
            timeCounter += Time.deltaTime;

            mat_soldat_bleu  = Resources.Load("texture_soldat_bleu", typeof(Material)) as Material;
            mat_soldat_rouge = Resources.Load("texture_soldat_rouge", typeof(Material)) as Material;

            if (isSpawned == false && timeCounter >= 5.0f)
            {
                GameObject  playerCre = PhotonNetwork.Instantiate("playerCreator", new Vector3(0, 0, 0), Quaternion.identity, 0);
                playerSpawn playSpawn = playerCre.GetComponent <playerSpawn>();
                playSpawn.enabled = true;

                isSpawned = true;
            }
        }

        /*---------------- IF WE'RE IN THE LOBBY WE ACTIVATE THE LOBBY CHAT -------------*/
        roomLobbyChat lobbyChat = GetComponent <roomLobbyChat>();

        if (inMatch == false)
        {
            if (photonView.isMine)
            {
                lobbyChat.enabled = true;
            }

            /*-------------------- GUI ---------------------*/

            //When the mode and map are chosen we can start
            if (chosenMode != "" && chosenMapNum != -1)
            {
                //We get the start button
                GameObject UIPanel     = GameObject.Find("roomLobbyUI");
                Transform  startButton = UIPanel.transform.Find("StartButton");
                Button     startBut    = startButton.gameObject.GetComponent <Button>();
                startBut.interactable = true;
            }
        }
        else
        {
            lobbyChat.enabled = false;
        }

        //When a new player joins we tell him we're in a match

        /*if(PhotonNetwork.playerList.Length != (redCount + blueCount) && PhotonNetwork.isMasterClient)
         * {
         *      if(inMatch)
         *              photonView.RPC("isInMatch", PhotonTargets.Others, null);
         * }*/
    }
    /*---------------------------- UPDATE ----------------------------*/

    // Update is called once per frame
    void Update()
    {
        PhotonView photonView = PhotonView.Get(this);

        /*------------------------- VERIFYING SYNCHRONIZATION -------------*/
        //We check if we have the scores of everyone

        /*if(!isUpdated) //We're not updated
         * {
         *      if(updateCounter >= 2.0f)
         *      {
         *              int myID = photonView.owner.ID;
         *
         *              photonView.RPC("updateMe", PhotonTargets.MasterClient, null);
         *              updateCounter = 0f;
         *              Debug.Log("Requesting update");
         *      }
         *      else
         *      {
         *              updateCounter += Time.deltaTime;
         *      }
         * }
         *
         * /*----------------------------- WE UPDATE THE PLAYERS REGULARLY -----------*/
        if (PhotonNetwork.isMasterClient)
        {
            /*if(updateTimer >= 2.0f)
             * {
             *      string theTeamScores = blueScore + ";" + redScore;
             *      photonView.RPC("updateTeamScores", PhotonTargets.Others, theTeamScores);
             *      updateTimer = 0f;
             * }
             * else
             * {
             *      updateTimer += Time.deltaTime;
             * }*/

            if (pingUpdate >= 5.0f)
            {
                pingFunction();
                pingUpdate = 0f;
            }
            else
            {
                pingUpdate += Time.deltaTime;
            }
            pingTimer += Time.deltaTime;
        }

        /*--------------------------------------------------------------------*/

        //When our playerCreator is created we add ourself on the scoreboards
        playerSpawn playSpawn = GetComponent <playerSpawn>();


        //Managing the kills

        //We update the last shot each frame
        foreach (Transform child in transform)
        {
            if (child.name != "globalHUD" && child.name != "scoreBoardUI" && child.name != "InGameMenu" && child.name != "littleScoreBoardUI" && child.name != "PlayerHUD")
            {
                playerNetwork playSet = child.GetComponent <playerNetwork>();
                myLastShot = playSet.lastShot;
            }
        }

        //If we're killed we add the kill and update the score
        if (wasKilled)
        {
            PhotonPlayer    killer            = PhotonPlayer.Find(myLastShot);
            PunPlayerScores playerScoreScript = GetComponent <PunPlayerScores>();
            ScoreExtensions.AddScore(killer, 1);

            int myID = photonView.owner.ID;
            //photonView.RPC("addKill", killer, null);
            //photonView.RPC("addKill", PhotonTargets.All, myLastShot);

            if (myTeam == "Blue")
            {
                //photonView.RPC("addRedKill", PhotonTargets.All, myLastShot);
                //photonView.RPC("addRedKill", PhotonTargets.All, null);
                TeamExtensions.AddTeamScore("Red");
                //photonView.RPC("addBlueDeath", PhotonTargets.All, myID);
            }
            else
            {
                //photonView.RPC("addBlueKill", PhotonTargets.All, myLastShot);
                //photonView.RPC("addBlueKill", PhotonTargets.All, null);
                TeamExtensions.AddTeamScore("Blue");
                //photonView.RPC("addRedDeath", PhotonTargets.All, myID);
            }

            PhotonPlayer myPlayer = PhotonPlayer.Find(myID);
            //addDeath();
            DeathExtensions.AddDeath(myPlayer, 1);

            //KILLFEED
            TeamExtensions.AddKillFeed(myLastShot, myID);
            wasKilled = false;
        }

        /*--------------------------- SCOREBOARD ----------------------*/

        //We get the scoreboard object
        Transform scoreB = transform.Find("scoreBoardUI");

        //Drawing the score
        if (Input.GetKeyDown(KeyCode.Tab))
        {
            drawTheScore = true;
        }
        if (Input.GetKeyUp(KeyCode.Tab))
        {
            drawTheScore = false;
        }

        if (photonView.isMine)
        {
            if (drawTheScore || isMatchEnded)            //If the player press tab we activate the board
            {
                scoreB.gameObject.active = true;
            }
            else
            {
                scoreB.gameObject.active = false;
            }
        }
        else
        {
            scoreB.gameObject.active = false;
        }

        /*------------------------------ TIMER ------------------------*/

        //At the end of the match the masterclient stops it
        if (matchTimer <= 0f)
        {
            if (PhotonNetwork.isMasterClient)
            {
                photonView.RPC("stopMatch", PhotonTargets.All, null);
            }
        }
        else
        {
            matchTimer -= Time.deltaTime;

            //if(PhotonNetwork.isMasterClient)
            //updateMatchTimer();
        }
    }
Esempio n. 3
0
    /*---------------------------- UPDATE ----------------------------*/

    // Update is called once per frame
    void Update()
    {
        PhotonView photonView = PhotonView.Get(this);

        /*------------------------- VERIFYING SYNCHRONIZATION -------------*/
        //We check if we have the scores of everyone
        int numberOfScores = countPlayers();

        if (numberOfScores != PhotonNetwork.playerList.Length)        //We do not have all scores
        {
            if (updateCounter >= 2.0f)
            {
                int myID = photonView.owner.ID;

                photonView.RPC("updateMe", PhotonTargets.All, myID);
                updateCounter = 0f;
                Debug.Log("Requesting update");
            }
            else
            {
                updateCounter += Time.deltaTime;
            }
        }

        /*--------------------------------------------------------------------*/

        //When our playerCreator is created we add ourself on the scoreboards
        playerSpawn playSpawn = GetComponent <playerSpawn>();


        //While we're not on the scoreboard we try to be added
        if (addedOnBoard == false)
        {
            //We make a string out of our gamertag and playerID
            string myTag = PlayerPrefs.GetString("Gamertag");
            int    myID  = photonView.owner.ID;

            //If we have all the components we send the RPC
            if (myTeam == "Blue" || myTeam == "Red")
            {
                string tagTeamID = myID.ToString() + ";" + myTag + ";" + myTeam;

                if (PhotonNetwork.isMasterClient)
                {
                    photonView.RPC("addOnBoard", PhotonTargets.All, tagTeamID);
                }
                else
                {
                    photonView.RPC("addOnBoard", PhotonTargets.All, tagTeamID);
                    photonView.RPC("updateMe", PhotonTargets.All, myID);
                }

                /*if(photonView.isMine)
                 * {
                 *      addOnBoard(tagTeamID);
                 * }*/
                addedOnBoard = true;
            }
        }


        //Managing the kills

        //We update the last shot each frame
        foreach (Transform child in transform)
        {
            if (child.name != "globalHUD" && child.name != "scoreBoardUI" && child.name != "InGameMenu")
            {
                playerNetwork playSet = child.GetComponent <playerNetwork>();
                myLastShot = playSet.lastShot;
            }
        }

        //If we're killed we add the kill and update the score
        if (wasKilled)
        {
            int myID = photonView.owner.ID;
            if (myTeam == "Blue")
            {
                photonView.RPC("addRedKill", PhotonTargets.All, myLastShot);
                photonView.RPC("addBlueDeath", PhotonTargets.All, myID);
            }
            else
            {
                photonView.RPC("addBlueKill", PhotonTargets.All, myLastShot);
                photonView.RPC("addRedDeath", PhotonTargets.All, myID);
            }
            wasKilled = false;
        }

        /*--------------------------- SCOREBOARD ----------------------*/

        //We get the scoreboard object
        Transform scoreB = transform.Find("scoreBoardUI");

        //Drawing the score
        if (Input.GetKeyDown(KeyCode.Tab))
        {
            drawTheScore = true;
        }
        if (Input.GetKeyUp(KeyCode.Tab))
        {
            drawTheScore = false;
        }

        if (photonView.isMine)
        {
            if (drawTheScore)            //If the player press tab we activate the board
            {
                scoreB.gameObject.active = true;
            }
            else
            {
                scoreB.gameObject.active = false;
            }
        }
        else
        {
            scoreB.gameObject.active = false;
        }
    }