Ejemplo n.º 1
0
    // Update is called once per frame
    void Update()
    {
        if(!string.IsNullOrWhiteSpace(PlayerHost.MultiplayerSession.P1Country) &&
           !string.IsNullOrWhiteSpace(PlayerHost.MultiplayerSession.P2Country))
        {
            // gameObject.SetActive(false);
            transform.parent.gameObject.SetActive(false);
            Debug.Log("both players ready");

            PlayerHost.MultiplayerSession.CountryPl = CountryModel.GetCountryByShortName(PlayerHost.MultiplayerSession.P1Country);
            PlayerHost.MultiplayerSession.CountryP2 = CountryModel.GetCountryByShortName(PlayerHost.MultiplayerSession.P2Country);

            RuntimeAnimatorController player1Controller = PlayerHost.MultiplayerSession.CountryPl.ControllerBottom1;
            RuntimeAnimatorController player2Controller = PlayerHost.MultiplayerSession.CountryP2.ControllerTop1;

            CountryModel p1country = PlayerHost.MultiplayerSession.CountryPl;
            CountryModel p2country = PlayerHost.MultiplayerSession.CountryP2;

            // server.NetworkObjects.transform.Find("player1").GetComponent<Animator>().runtimeAnimatorController = player1Controller;
            //server.NetworkObjects.transform.Find("player2").GetComponent<Animator>().runtimeAnimatorController = player2Controller;
            int count = server.NetworkObjects.transform.childCount;
            for(int i = 0; i < count; i++)
            {
                Transform t = server.NetworkObjects.transform.GetChild(i);

                Animator animator = t.GetComponent<Animator>(); 

                MultiplayerAIController ai = t.GetComponent<MultiplayerAIController>();

                HostPlayerController hplayer = t.GetComponent<HostPlayerController>();
                NetworkClientController cplayer = t.GetComponent<NetworkClientController>();


                if (t.name.Contains("player1"))
                {
                    animator.runtimeAnimatorController = player1Controller;
                    if (ai != null)
                    {
                        ai.SetSpeed(p1country.RawSpeed);
                        ai.SetPower(p1country.RawPower);
                        ai.SetInt(p1country.RawInt);
                    }else if(hplayer != null)
                    {
                        hplayer.SetSpeed(p1country.RawSpeed);
                        hplayer.SetPower(p1country.RawPower);
                        hplayer.SetInt(p1country.RawInt);
                    }

                }
                else if (t.name.Contains("player2"))
                {
                    animator.runtimeAnimatorController = player2Controller;
                    if (ai != null)
                    {
                        ai.SetSpeed(p2country.RawSpeed);
                        ai.SetPower(p2country.RawPower);
                        ai.SetInt(p2country.RawInt);
                    }
                    else if (cplayer != null)
                    {
                        cplayer.SetSpeed(p2country.RawSpeed);
                        cplayer.SetPower(p2country.RawPower);
                        cplayer.SetInt(p2country.RawInt);
                    }

                }
            }

            //server.NetworkObjects.SetActive(true);

            server.MultiplayerUIScript.ShowModal("Loading...");
            server.Send("HOSTACTION|PICKINGSDONE%" + PlayerHost.MultiplayerSession.P1Country + "%" + PlayerHost.MultiplayerSession.P2Country
                , true);

            ScoreboardUI.Scoreboard.SetPlayer1Name("Player 1" + "(" + PlayerHost.MultiplayerSession.P1Country + ")");
            ScoreboardUI.Scoreboard.SetPlayer2Name("Player 2" + "(" + PlayerHost.MultiplayerSession.P2Country + ")");
        }
    }
Ejemplo n.º 2
0
    private void OnHostAction(string[] data)
    {
        switch (data[0])
        {
        case "PICKINGSDONE":

            GameObject.Find("Canvas").transform.Find("CountrySelection").gameObject.SetActive(false);
            P1Country = CountryModel.GetCountryByShortName(data[1]);
            P2Country = CountryModel.GetCountryByShortName(data[2]);

            RuntimeAnimatorController player1Controller = P1Country.ControllerTop2;
            RuntimeAnimatorController player2Controller = P2Country.ControllerBottom2;

            //  NetworkObjects.transform.Find("player1").GetComponent<Animator>().runtimeAnimatorController = player1Controller;
            // NetworkObjects.transform.Find("player2").GetComponent<Animator>().runtimeAnimatorController = player2Controller;

            int count = NetworkObjects.transform.childCount;
            for (int i = 0; i < count; i++)
            {
                Transform t = NetworkObjects.transform.GetChild(i);

                Animator animator = t.GetComponent <Animator>();

                if (t.name.Contains("player1"))
                {
                    animator.runtimeAnimatorController = player1Controller;
                }
                else if (t.name.Contains("player2"))
                {
                    animator.runtimeAnimatorController = player2Controller;
                }
            }


            ScoreboardUI.Scoreboard.SetPlayer1Name("Player 1" + "(" + data[1] + ")");
            ScoreboardUI.Scoreboard.SetPlayer2Name("Player 2" + "(" + data[2] + ")");

            NetworkObjects.SetActive(true);
            NetUI.ShowModal("Loading...");

            Invoke("ReadyToPlay", 3f);
            break;

        case "SHOWMODAL":
            NetUI.ShowModal(data[1]);
            break;

        case "CLOSEMODAL":
            NetUI.CloseModal();
            break;

        case "YOUWON":
            NetUI.OpenModalWin();
            break;

        case "YOULOSE":
            NetUI.OpenModalLose();
            break;

        case "DELAY":
            DelayReducer.REQUESTED_DELAY = float.Parse(data[1]);

            if (int.Parse(data[2]) == 2)
            {
                Destroy(NetworkObjects.transform.Find("player1ai1").gameObject);
                Destroy(NetworkObjects.transform.Find("player2ai1").gameObject);
            }

            Debug.Log("requested delay is set to " + data[1] + "ms");
            break;
        }
    }