public void OnSendMsg(eNetworkMsg networkEvent) { JsonData data = new JsonData(); #if UNITY_EDITOR Debug.Log("NetworkManager OnSendMsg"); #endif switch (networkEvent) { case eNetworkMsg.NetworkLogin: { Debug.Log("Send Login"); data["msgType"] = (int)eNetworkMsg.NetworkLogin; } break; case eNetworkMsg.NetworkLogout: { Debug.Log("Send Logout"); data["msgType"] = (int)eNetworkMsg.NetworkLogout; } break; case eNetworkMsg.NetworkPlaying: { Debug.Log("Send Playing"); data["msgType"] = (int)eNetworkMsg.NetworkPlaying; data["x"] = (int)(owner.transform.position.x * 100) * 0.01; data["z"] = (int)(owner.transform.position.z * 100) * 0.01; data["yAngle"] = owner.ModelTransform.eulerAngles.y; } break; case eNetworkMsg.NetworkInitInfoReq: { Debug.Log("Send InitInfoReq"); data["msgType"] = (int)eNetworkMsg.NetworkInitInfoReq; } break; case eNetworkMsg.NetworkInitInfoRes: { Debug.Log("Send InitInfoRes"); data["msgType"] = (int)eNetworkMsg.NetworkInitInfoRes; //보내야될 데이터 } break; default: break; } network.OnSendMsg(data); }
public void ProcessUserMsg() { if (msgMap.Keys.Count <= 0) { return; } var it = msgMap.Keys.GetEnumerator(); while (it.MoveNext()) { Queue <JsonData> queue = msgMap[it.Current]; for (int j = 0; j < queue.Count; j++) { JsonData msg = queue.Dequeue(); eNetworkMsg msgType = (eNetworkMsg)int.Parse(msg["msgType"].ToString()); switch (msgType) { case eNetworkMsg.NetworkLogin: { #if UNITY_EDITOR Debug.Log("Receive Login"); #endif EnemyCtrl enemy = Instantiate(enemyPrefab, new Vector3(-200f, 0f, 0f), Quaternion.identity).GetComponent <EnemyCtrl>(); enemyList.Add(enemy); enemy.MacAddress = it.Current; if (network.mlistUserMacAddress.Count == 1) { break; } OnSendMsg(eNetworkMsg.NetworkInitInfoReq); } break; case eNetworkMsg.NetworkLogout: { #if UNITY_EDITOR Debug.Log("Receive Logout"); #endif for (int i = 0; i < enemyList.Count; i++) { if (it.Current == enemyList[i].MacAddress) { EnemyCtrl enemy = enemyList[i]; enemyList.RemoveAt(i); Destroy(enemy.gameObject); break; } } msgMap[it.Current].Clear(); msgMap[it.Current] = null; msgMap.Remove(it.Current); it = msgMap.Keys.GetEnumerator(); } break; case eNetworkMsg.NetworkPlaying: { EnemyCtrl enemy = null; #if UNITY_EDITOR Debug.Log("Receive Playing"); #endif for (int i = 0; i < enemyList.Count; i++) { if (it.Current == enemyList[i].MacAddress) { enemy = enemyList[i]; //enemy.transform.position = new Vector3(float.Parse(msg["x"].ToString()), 0f, float.Parse(msg["z"].ToString())); float x = float.Parse(msg["x"].ToString()); float z = float.Parse(msg["z"].ToString()); float yAngle = float.Parse(msg["yAngle"].ToString()); enemy.EnqueuePosAndRot(x, z, yAngle); break; } } } break; case eNetworkMsg.NetworkInitInfoReq: { #if UNITY_EDITOR Debug.Log("Receive InitInfoReq"); #endif OnSendMsg(eNetworkMsg.NetworkInitInfoRes); } break; case eNetworkMsg.NetworkInitInfoRes: { if (isReceiveInitData == true) { break; } isReceiveInitData = true; #if UNITY_EDITOR Debug.Log("Receive InitInfoRes"); #endif } break; default: break; } } } }