예제 #1
0
    void RecieveMessage(Message msg)
    {
        print("MESSAGE RECIEVED " + msg);
        switch (msg.type)
        {
        case MessageTypes.PlayerJoined:

            print("A NEW CHALLENGER APPROACHES");
            PlayerJoinedMessage pjm = (PlayerJoinedMessage)msg;
            m_playerController.AddPlayer(new PlayerData {
                index = pjm.id, color = pjm.color, icon = (PhoneUserIcon)pjm.icon, name = pjm.name
            });

            if (onPlayerCountChange != null)
            {
                onPlayerCountChange.Invoke(m_playerController.PlayerCount);
            }


            break;

        case MessageTypes.PlayerLeft:

            PlayerLeftMessage plm = (PlayerLeftMessage)msg;
            m_playerController.RemovePlayer(plm.id);

            if (onPlayerCountChange != null)
            {
                onPlayerCountChange.Invoke(m_playerController.PlayerCount);
            }
            SceneManager.LoadScene(0);
            break;

        case MessageTypes.PlayerMove:
            PlayerMoveMessage      pmm    = (PlayerMoveMessage)msg;
            ThirdPersonUserControl player = ThirdPersonUserControl.players[pmm.pid - 1];
            //if(pmm.x != null && pmm.y != null)
            player.setAxis(pmm.x, pmm.y);
            if (pmm.jmp)
            {
                player.jump = pmm.jmp;
            }
            if (pmm.drp)
            {
                player.drop = pmm.drp;
            }
            break;

        case MessageTypes.PlayerAction:
            PlayerActionMessage pam = (PlayerActionMessage)msg;
            print(pam + " sad");
            if (pam.jump)
            {
                ThirdPersonUserControl.players[pam.pid - 1].jump = true;
            }
            else
            {
                ThirdPersonUserControl.players[pam.pid - 1].drop = true;
            }
            break;
        }
    }