private void ProcessKeyEvent(SessionId index, KeyMessage keyMsg) { Debug.Log("2-1"); if (!BackEndMatchManager.instance.isHost) { return; } int keyData = keyMsg.keyData; if ((keyData & KeyEventCode.IDLE) == KeyEventCode.IDLE) { PlayerIdleMessage msg = new PlayerIdleMessage(index); BackEndMatchManager.instance.SendDataToInGame(msg); } if ((keyData & KeyEventCode.WEAK_ATTACK) == KeyEventCode.WEAK_ATTACK) { PlayerWeakAttackMessage msg = new PlayerWeakAttackMessage(index, keyMsg.direction); BackEndMatchManager.instance.SendDataToInGame(msg); } if ((keyData & KeyEventCode.STRONG_ATTACK) == KeyEventCode.STRONG_ATTACK) { PlayerStrongAttackMessage msg = new PlayerStrongAttackMessage(index, keyMsg.direction); BackEndMatchManager.instance.SendDataToInGame(msg); } if ((keyData & KeyEventCode.DEFENSE) == KeyEventCode.DEFENSE) { PlayerDefenseMessage msg = new PlayerDefenseMessage(index, keyMsg.direction); BackEndMatchManager.instance.SendDataToInGame(msg); } if ((keyData & KeyEventCode.STUN) == KeyEventCode.STUN) { PlayerStunMessage msg = new PlayerStunMessage(index); BackEndMatchManager.instance.SendDataToInGame(msg); } if ((keyData & KeyEventCode.ATTACK_END) == KeyEventCode.ATTACK_END) { PlayerAttackEndMessage msg = new PlayerAttackEndMessage(index); BackEndMatchManager.instance.SendDataToInGame(msg); } Debug.Log("2-2 상태 : " + keyData); }
// 방어 상태 private void ProcessPlayerData(PlayerDefenseMessage data) { //players[data.playerSession] <- 이걸 통해서 그 플레이어 세션에 맞는 플레이어의 함수를 실행시키게함 players[data.playerSession].HitStop(0.2f, 0.2f); players[data.playerSession].AnimationReset(); if (players[data.playerSession].Direction == Direction.Left) { players[data.playerSession].Anim.SetInteger("AttackDir", 0); } if (players[data.playerSession].Direction == Direction.Right) { players[data.playerSession].Anim.SetInteger("AttackDir", 1); } players[data.playerSession].State = PlayerCurState.DEFENSE; players[data.playerSession].Anim.SetInteger("AttackKind", 3); players[data.playerSession].Anim.SetBool("isAttack", true); }
} // 스와이프 public void PlayerLongTouch() { if ((!Anim.GetBool("isAttack") || Cancel)) { State = PlayerCurState.DEFENSE; Debug.Log("긴 터치 : " + (SessionId)index + (int)Direction); if (BackEndMatchManager.instance.isHost) { int keyCode = (int)State; KeyMessage msg = new KeyMessage(keyCode, transform.position, Direction); BackEndMatchManager.instance.AddMsgToLocalQueue(msg); StartCoroutine(cameraFuncs.ZoomCamera(0.5f, 2.0f)); } else { PlayerDefenseMessage defenceMsg = new PlayerDefenseMessage(index, Direction); BackEndMatchManager.instance.SendDataToInGame(defenceMsg); } } } // 긴 터치
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; } }