void Update() { if (!receiveMsg) { return; } /* * // Deliver received messages * Dictionary<string, object> receiveMessage = networkManager.receive(); * while (receiveMessage != null) { * Debug.Log("Receive " + receiveMessage["type"] + " message!"); * messageDispatcher.Dispatch(receiveMessage); * receiveMessage = networkManager.receive(); * }*/ if (!paused) { //IncrementCurLogicTime(); // Detect keyboard event and decide if need sending UPDATE message float verticalDir = Input.GetAxisRaw("Vertical"); float horizontalDir = Input.GetAxisRaw("Horizontal"); if (verticalDir == 0.0f && horizontalDir == 0.0f) { return; } if (verticalDir == motorController.GetVerticalDir() && horizontalDir == motorController.GetHorizontalDir()) { return; } if (verticalDir == lastSentVerticalDir && horizontalDir == lastSentHonrizontalDir) { return; } // Send UPDATE message Dictionary <string, object> message = new Dictionary <string, object>(); message["type"] = (object)MessageDispatcher.UPDATE_USER; message["userID"] = (object)userID; message["horizontalDir"] = (object)horizontalDir; message["verticalDir"] = (object)verticalDir; message["time"] = (object)curLogicTime; networkManager.writeSocket(message); Debug.Log("Send local update message"); // Update last sent direction lastSentHonrizontalDir = horizontalDir; lastSentVerticalDir = verticalDir; } }