public void SendUseSkill(int type, Vector3 position, Quaternion rotation) { CM_UseSkill myMsg = new CM_UseSkill(); myMsg.skillType = type; myMsg.position = position; myMsg.rotation = rotation; byte[] newMsg = MyTool.StructToBytes <CM_UseSkill>(myMsg); byte[] newBuf = new byte[newMsg.Length + 1]; newBuf[0] = (byte)CTCType.UseSkill; for (int i = 0; i < newMsg.Length; ++i) { newBuf[i + 1] = newMsg[i]; } networkSendList.Add(newBuf); }
private void Update() { if (listnerThread != null) { print(listnerThread.ThreadState + "상태"); } switch (currentState) { case ClientNetworkState.Matching: if (targetIp.Length != 0) { string newTartget; lock (listenerLocker) { newTartget = targetIp; } if (newTartget == "0") { BindPlayerServer(); } else { ConnectToPlayerServer(); } } break; case ClientNetworkState.InGame: // 메세지큐 수신 처리 { while (networkReceivedList.Count > 0) { byte[] recievedBuf; lock (listenerLocker) { recievedBuf = networkReceivedList.Dequeue(); } switch ((CTCType)recievedBuf[0]) { case CTCType.AttackSuccess: { byte[] realBuf = new byte[recievedBuf.Length - 1]; for (int i = 0; i < recievedBuf.Length - 1; ++i) { realBuf[i] = recievedBuf[i + 1]; } CM_AttackSuccess msg = MyTool.BytesToStruct <CM_AttackSuccess>(realBuf); GameMain.GetInstance().Attack((msg.type == CharacterType.Local ? CharacterType.Enemy : CharacterType.Local), msg.damage, true); } break; case CTCType.SendTime: { byte[] realBuf = new byte[recievedBuf.Length - 1]; for (int i = 0; i < recievedBuf.Length - 1; ++i) { realBuf[i] = recievedBuf[i + 1]; } CM_SendTime msg = MyTool.BytesToStruct <CM_SendTime>(realBuf); GameMain.GetInstance().timer = msg.timer - (float)(DateTime.Now - DateTime.Parse(msg.dateTime)).TotalSeconds; } break; case CTCType.Disconnect: { ChangeState(ClientNetworkState.Matching); return; } break; case CTCType.NoticeDeath: { byte[] realBuf = new byte[recievedBuf.Length - 1]; for (int i = 0; i < recievedBuf.Length - 1; ++i) { realBuf[i] = recievedBuf[i + 1]; } CM_NoticeDeath msg = MyTool.BytesToStruct <CM_NoticeDeath>(realBuf); GameMain.GetInstance().Death((msg.characterType == CharacterType.Local ? CharacterType.Enemy : CharacterType.Local), msg.position, true); } break; case CTCType.UpdatePosition: { byte[] realBuf = new byte[recievedBuf.Length - 1]; for (int i = 0; i < recievedBuf.Length - 1; ++i) { realBuf[i] = recievedBuf[i + 1]; } CM_UpdatePosition msg = MyTool.BytesToStruct <CM_UpdatePosition>(realBuf); Enemy.GetInstance().UpdatePosition(msg.position, msg.velocity); } break; case CTCType.UseSkill: { byte[] realBuf = new byte[recievedBuf.Length - 1]; for (int i = 0; i < recievedBuf.Length - 1; ++i) { realBuf[i] = recievedBuf[i + 1]; } CM_UseSkill msg = MyTool.BytesToStruct <CM_UseSkill>(realBuf); LocalCharacter.GetInstance().InstantiateMissle(msg.skillType, msg.position, msg.rotation, true); } break; } } } // 메세지 전송 처리 { for (int i = 0; i < networkSendList.Count; ++i) { SendToServer(networkSendList[i]); } networkSendList.Clear(); } break; } if (matchingFlag) { if (currentState != ClientNetworkState.Ready) { ChangeState(ClientNetworkState.Matching); } matchingFlag = false; } if (refreshThread && listnerThread.ThreadState == ThreadState.Stopped) { listnerThread.Start(); refreshThread = true; } }