Exemplo n.º 1
0
    private void ProcessPacket(IPacket p, NetworkManager.Protocol pt)
    {
        if (pt == NetworkManager.Protocol.UDP)
        {
            return;
        }

        if (p is Start_Game)
        {
            var s = (Start_Game)p;
            InitHandler(true, s.ip, s.port);
            StartCoroutine(LoadScene(_sceneNames[2]));
        }
        else if (p is Login_Ack)
        {
            var s = (Login_Ack)p;
            StartCoroutine(LoadScene(_sceneNames[1]));
        }
        else if (p is Queue_Ack)
        {
            var s = (Queue_Ack)p;
            if (s.ack == true)
            {
                if (s.req == 0)
                {
                    Debug.Log("QUEUE 등록 성공");
                }
                else if (s.req == 1)
                {
                    Debug.Log("Queue 취소 성공");
                }
            }
            else
            {
                if (s.req == 0)
                {
                    Debug.Log("Queue 등록 실패");
                }
                else if (s.req == 1)
                {
                    Debug.Log("Queue 취소 실패");
                }
            }
        }
        else if (p is Match_Succeed)
        {
            var s = (Match_Succeed)p;
            Debug.Log("매칭 성사");
            //매칭 성사 UI 변경
        }
        else if (p is Match_End)
        {
            _inGame = false;
            InitHandler(false);
        }
    }
Exemplo n.º 2
0
    private void ProcessPacket(IPacket p, NetworkManager.Protocol pt)
    {
        if (pt == NetworkManager.Protocol.TCP)
        {
            if (p is Player_Init)
            {
                //받았을때 클라이언트 생성(아군 적군 모두)
                var s = (Player_Init)p;

                CreatePlayerObject(s.clientIdx, s.hp, TotalUtility.ToUnityVectorChange(s.startPos), s.startLook, s.assign, s.character, s.weapon1, s.weapon2, s.item);
                if (s.assign)
                {
                    NetworkManager.Instance.SendPacket(new Player_Ready(clientPlayerNum), NetworkManager.Protocol.TCP);
                }
            }
            else if (p is Player_Reset)
            {
                var s = (Player_Reset)p;
                ResetPlayerVar(s.clientIdx, s.hp, s.startPos, s.LookPosYrot);
            }
            //else if (p is Round_Start)
            //{
            //    var s = (Round_Start)p;
            //}
            //else if (p is Round_End)
            //{
            //    var s = (Round_End)p;
            //}
            else if (p is Match_End)
            {
                var s = (Match_End)p;
                NetworkManager.Instance.RecvHandler -= ProcessPacket;
            }
            else if (p is Round_Timer)
            {
                //Timer countdown == 0  : 타이머를 시작 1 : 타이머 종료
                var s = (Round_Timer)p;
            }
            else if (p is Player_Input)
            {
                //Player key 관련 처리
                var s = (Player_Input)p;
                if (playerList[s.clientIdx] == null)
                {
                    return;
                }
                playerList[s.clientIdx].KeyDownClient(s.key, s.down);
            }
            else if (p is Player_Grounded)
            {
                //player isGrounded 처리
                var s = (Player_Grounded)p;
                if (playerList[s.clientIdx] == null)
                {
                    return;
                }
                playerList[s.clientIdx].IsGroundedFromServer = s.state;
            }
            else if (p is Use_Item)
            {
                //폭탄 던지기
                var s = (Use_Item)p;
                if (playerList[s.clientIdx] == null)
                {
                    return;
                }
                if (playerList[s.clientIdx] != null)
                {
                    playerList[s.clientIdx].weaponManagerSc.UseItem(s.clientIdx, TotalUtility.ToUnityVectorChange(s.pos), TotalUtility.ToUnityVectorChange(s.rot));
                }
            }
            else if (p is Throw_BombAnim)
            {
                var s = (Throw_BombAnim)p;
                if (playerList[s.clientIdx] != null)
                {
                    playerList[s.clientIdx].animSc.anim.SetTrigger("Shoot");
                }
            }

            else if (p is Player_Sync)
            {
                //체력 설정
                var s = (Player_Sync)p;
            }
            else if (p is Player_Recover)
            {
                var s = (Player_Recover)p;
                if (playerList[s.clientIdx] != null)
                {
                    playerList[s.clientIdx].weaponManagerSc.UseItem(s.clientIdx, Vector3.zero, Vector3.zero);
                }
            }
            else if (p is Player_Dead)
            {
                //주금
                var s = (Player_Dead)p;
                if (playerList[s.clientIdx] != null)
                {
                    playerList[s.clientIdx].Death();
                }
            }
            else if (p is Round_Result)
            {
                var s = (Round_Result)p;
                Debug.Log("Round 결과 패킷 받음");
            }
            else if (p is Match_End)
            {
            }

            //총알 생성
            //폭탄 던지기
            //체력회복
            //주금
            //데미지받는부분

            //else if()
        }
        else
        {
            if (p is Player_Info)
            {
                //싱크(적편에게만 적용)
                var s = (Player_Info)p;
                if (playerList[s.clientIdx] == null)
                {
                    return;
                }

                if (clientPlayerNum != s.clientIdx)
                {
                    var i = s.clientIdx;
                    //Position
                    if (playerList[i] != null)
                    {
                        playerList[i].transform.position = TotalUtility.ToUnityVectorChange(s.pos);

                        playerList[i].lookTarget = TotalUtility.ToUnityVectorChange(s.lookTarget);
                    }
                }
            }
        }
    }
Exemplo n.º 3
0
    private void ProcessPacket(IPacket p, NetworkManager.Protocol pt)
    {
        if (pt == NetworkManager.Protocol.UDP)
        {
            return;
        }

        if (p is Player_Sync)
        {
            var s = (Player_Sync)p;
            SetHpValue(s.hp);
        }
        else if (p is Player_Recover)
        {
            var s = (Player_Recover)p;
            SetHpValue(s.amount);
        }
        else if (p is Round_Stat)
        {
            var s = (Round_Stat)p;
            curRound.text      = "Round " + s.curRound;
            redTeamScore.text  = s.pointRed.ToString();
            blueTeamScore.text = s.pointBlue.ToString();
        }
        else if (p is Round_Result)
        {
            var s = (Round_Result)p;
            switch (s.winTeam)
            {
            case 0:
                roundResultText.text = "<color=blue>BLUE</color> Team Win !";
                break;

            case 1:
                roundResultText.text = "<color=red>RED</color> Team Win !";
                break;
            }
            roundResultText.gameObject.SetActive(true);
        }
        else if (p is Player_Reset)
        {
            var s = (Player_Reset)p;
            SetHpValue(s.hp);
            InitRound();
        }
        else if (p is Player_Init)
        {
            var s = (Player_Init)p;
            if (s.assign)
            {
                SetHpValue(s.hp);
            }
        }
        else if (p is Round_Timer)
        {
            var s = (Round_Timer)p;
            if (s.countDown > 0)
            {
                roundTimerText.gameObject.SetActive(true);
                StartCoroutine(TimerStart(s.countDown));
            }
            else if (s.countDown == 0)
            {
                StartCoroutine(TimerStartEnd());
            }
        }
        else if (p is Match_End)
        {
            var s = (Match_End)p;

            StartCoroutine(EndMatch(s.win));
        }
    }