Ejemplo n.º 1
0
    IEnumerator StartCount()
    {
        Debug.Log("현재 상태 : " + GameManager.instance.gameState);
        StartCountMessage msg = new StartCountMessage(START_COUNT);

        // 카운트 다운
        for (int i = 0; i < START_COUNT + 1; ++i)
        {
            msg.time = START_COUNT - i;
            BackEndMatchManager.instance.SendDataToInGame(msg);
            yield return(new WaitForSeconds(1)); //1초 단위

            Debug.Log("게임 시작 : " + i);
        }

        // 게임 시작 메시지를 전송
        GameStartMessage gameStartMessage = new GameStartMessage();

        BackEndMatchManager.instance.SendDataToInGame(gameStartMessage);
    }
Ejemplo n.º 2
0
    public void OnRecieve(MatchRelayEventArgs args)
    {
        if (args.BinaryUserData == null)
        {
            Debug.LogWarning(string.Format("빈 데이터가 브로드캐스팅 되었습니다.\n{0} - {1}", args.From, args.ErrInfo));
            // 데이터가 없으면 그냥 리턴
            return;
        }
        Message msg = DataParser.ReadJsonData <Message>(args.BinaryUserData);

        if (msg == null)
        {
            return;
        }
        //if (BackEndMatchManager.instance.isHost != true && args.From.SessionId == myPlayerIndex)
        //{
        //    Debug.Log("패킷 받기 안됨");
        //    return;
        //}
        if (players == null)
        {
            Debug.Log("패킷 받기 안됨");
            return;
        }

        Debug.Log("패킷 받기 : " + (int)msg.type);
        switch (msg.type)
        {
        case Protocol.Type.StartCount:
            // 아무것도 못하게 하기
            StartCountMessage startCount = DataParser.ReadJsonData <StartCountMessage>(args.BinaryUserData);
            if (startCount.time == 0)
            {
                GameUI.instance.SetStartText("게임 시작");
            }
            else
            {
                GameUI.instance.SetStartText(startCount.time.ToString());
            }
            break;

        case Protocol.Type.GameStart:
            // 플레이 가능하게 하기
            GameManager.instance.ChangeState(GameManager.GameState.InGame);
            GameUI.instance.baseObj.SetActive(true);
            GameUI.instance.fadeObj.SetActive(false);
            StartCoroutine(GameUI.instance.gameTimeCheck(BackEndMatchManager.instance.matchInfos[0].matchMinute));
            break;

        case Protocol.Type.GameEnd:
            GameEndMessage endMessage = DataParser.ReadJsonData <GameEndMessage>(args.BinaryUserData);
            SetGameRecord(endMessage.count, endMessage.sessionList);
            break;

        case Protocol.Type.Idle:
            PlayerIdleMessage idleMsg = DataParser.ReadJsonData <PlayerIdleMessage>(args.BinaryUserData);
            ProcessPlayerData(idleMsg);
            break;

        case Protocol.Type.WeakAttack:
            PlayerWeakAttackMessage weakattackMsg = DataParser.ReadJsonData <PlayerWeakAttackMessage>(args.BinaryUserData);
            ProcessPlayerData(weakattackMsg);
            break;

        case Protocol.Type.StrongAttack:
            PlayerStrongAttackMessage strongattackMsg = DataParser.ReadJsonData <PlayerStrongAttackMessage>(args.BinaryUserData);
            ProcessPlayerData(strongattackMsg);
            break;

        case Protocol.Type.Defense:
            PlayerDefenseMessage defenseMsg = DataParser.ReadJsonData <PlayerDefenseMessage>(args.BinaryUserData);
            ProcessPlayerData(defenseMsg);
            break;

        case Protocol.Type.Stun:
            PlayerStunMessage stunMsg = DataParser.ReadJsonData <PlayerStunMessage>(args.BinaryUserData);
            ProcessPlayerData(stunMsg);
            break;

        case Protocol.Type.AttackEnd:
            PlayerAttackEndMessage endMsg = DataParser.ReadJsonData <PlayerAttackEndMessage>(args.BinaryUserData);
            ProcessPlayerData(endMsg);
            break;

        case Protocol.Type.GameSync:
            GameSyncMessage syncMessage = DataParser.ReadJsonData <GameSyncMessage>(args.BinaryUserData);
            ProcessSyncData(syncMessage);
            break;

        case Protocol.Type.GameMySync:
            Debug.Log("싱크 맞추기");
            GameMySyncMessage mySyncMessage = DataParser.ReadJsonData <GameMySyncMessage>(args.BinaryUserData);
            ProcessSyncData(mySyncMessage);
            break;

        case Protocol.Type.Calculation:
            CalculationMessage calMessage = DataParser.ReadJsonData <CalculationMessage>(args.BinaryUserData);
            ProcessCalData(calMessage);
            break;

        case Protocol.Type.Damaged:
            PlayerDamagedMessage damMessage = DataParser.ReadJsonData <PlayerDamagedMessage>(args.BinaryUserData);
            ProcessPlayerData(damMessage);
            break;

        case Protocol.Type.Stamina:
            PlayerStaminaMessage staMessage = DataParser.ReadJsonData <PlayerStaminaMessage>(args.BinaryUserData);
            ProcessPlayerData(staMessage);
            break;

        default:
            Debug.Log("Unknown protocol type");
            return;
        }
    }