void OnEvent(byte eventCode, object content, int senderId) { int i; BaseObjectMessage baseObjectMessage; PlayerObject playerObject = null; PlayerController playerController = null; //Debug.Log("RECEIVE EVENT[" + eventCode + "] from [" + senderId + "]"); switch (eventCode) { case 1: baseObjectMessage = new BaseObjectMessage(); baseObjectMessage.Unpack((byte[])content); remoteTimestamp = baseObjectMessage.timemark; gameNetwork.ClientInit(); gameNetwork.playerId = baseObjectMessage.id; Debug.Log("INITIALIZE PLAYER ID: " + gameNetwork.playerId); /* duplicate for GameNetwork RpcSpawnObject case PLAYER */ playerObject = (PlayerObject)gameNetwork.location.GetObject(gameNetwork.playerId); if (playerObject != null) { camera.transform.position = playerObject.position * 100.0f + Vector3.up * 20.0f; if (gameNetwork.playerId == 1) { camera.transform.eulerAngles = new Vector3(camera.transform.eulerAngles.x, 180.0f, camera.transform.eulerAngles.z); } } playerObject = (PlayerObject)gameNetwork.location.GetObject(gameNetwork.playerId == 1 ? 0 : 1); if (playerObject != null && playerObject.visualObject == null) { playerController = (Instantiate(gameNetwork.bodyPrefabs[0])).GetComponent <PlayerController>(); playerController.gameNetwork = gameNetwork; playerController.obj = playerObject; playerObject.visualObject = playerController; playerController.transform.position = playerObject.position * 100.0f; //playerController.transform.localScale *= 10.0f; if (playerObject.position.z < 0.0f) { playerObject.visualObject.transform.Rotate(0.0f, 180.0f, 0.0f); } } /* */ canvasPlay.enabled = true; InitializeMessage initializeMessage = new InitializeMessage(); for (i = 1; i < AbilityButtons.Length; i++) { if (AbilityButtons[i].image.color == Color.green) { if (initializeMessage.abilityFirstId <= -1) { initializeMessage.abilityFirstId = i; } else { initializeMessage.abilitySecondId = i; } } } gameNetwork.myMissileId = armedMissile.GetCurrentMissile(); initializeMessage.missileId = gameNetwork.myMissileId; for (i = 1; i < VenomButtons.Length; i++) { if (VenomButtons[i].image.color == Color.green) { initializeMessage.venomId = i; } } PhotonNetwork.networkingPeer.OpCustom((byte)1, new Dictionary <byte, object> { { 245, initializeMessage.Pack() } }, true); break; case 2: SpawnObjectMessage spawnObjectMessage = new SpawnObjectMessage(); spawnObjectMessage.Unpack((byte[])content); //Debug.Log(Time.fixedTime + " Spawn." + spawnObjectMessage.objectType + " [" + spawnObjectMessage.id + "]"); spawnObjectMessage.eventCode = eventCode; delayedMessages.AddLast(spawnObjectMessage); //gameNetwork.RpcSpawnObject(spawnObjectMessage.id, spawnObjectMessage.objectType, spawnObjectMessage.newPosition, spawnObjectMessage.newFloat, spawnObjectMessage.visualId); break; case 3: DestroyObjectMessage destroyObjectMessage = new DestroyObjectMessage(); destroyObjectMessage.Unpack((byte[])content); //Debug.Log(Time.fixedTime + " Destroy [" + destroyObjectMessage.id + "]: " + destroyObjectMessage.objectId); destroyObjectMessage.eventCode = eventCode; delayedMessages.AddLast(destroyObjectMessage); //gameNetwork.RpcDestroyObject(destroyObjectMessage.id); break; case 4: MoveObjectMessage moveObjectMessage = new MoveObjectMessage(); moveObjectMessage.Unpack((byte[])content); //Debug.Log(Time.fixedTime + " Move [" + moveObjectMessage.id + "]"); moveObjectMessage.eventCode = eventCode; delayedMessages.AddLast(moveObjectMessage); //gameNetwork.RpcMoveObject(moveObjectMessage.id, moveObjectMessage.newPosition, moveObjectMessage.newFloat, moveObjectMessage.timestamp); break; case 5: UpdatePlayerMessage updatePlayerMessage = new UpdatePlayerMessage(); updatePlayerMessage.Unpack((byte[])content); //Debug.Log("Player[" + updatePlayerMessage.id + "] health: " + updatePlayerMessage.newHealth + " ; stamina: " + updatePlayerMessage.newStamina); gameNetwork.RpcUpdatePlayer(updatePlayerMessage.id, updatePlayerMessage.newHealth, updatePlayerMessage.newStamina, updatePlayerMessage.newStaminaConsumption); break; case 6: gameNetwork.RpcRearmMissile(); break; case 7: baseObjectMessage = new BaseObjectMessage(); baseObjectMessage.Unpack((byte[])content); gameNetwork.RpcFlashPlayer(baseObjectMessage.id); break; case 8: GameOverMessage gameOverMessage = new GameOverMessage(); gameOverMessage.Unpack((byte[])content); gameNetwork.RpcGameOver(gameOverMessage.winner, gameOverMessage.time, gameOverMessage.damage, gameOverMessage.wound); gameNetwork = GameObject.Instantiate(gameNetworkPrefab).GetComponent <GameNetwork>(); gameNetwork.camera = camera; gameNetwork.gameMatchMaker = this; gameNetwork.isServer = false; gameNetwork.isLocal = false; break; case 9: SetAbilityMessage setAbilityMessage = new SetAbilityMessage(); setAbilityMessage.Unpack((byte[])content); gameNetwork.RpcSetAbility(setAbilityMessage.id, setAbilityMessage.value); break; case 10: NoticeMessage noticeMessage = new NoticeMessage(); noticeMessage.Unpack((byte[])content); //Debug.Log("GET NOTICE MESSAGE. timemark: " + noticeMessage.timemark + " ; numericValue: " + noticeMessage.numericValue); noticeMessage.eventCode = eventCode; delayedMessages.AddLast(noticeMessage); break; case 11: baseObjectMessage = new BaseObjectMessage(); baseObjectMessage.Unpack((byte[])content); Debug.Log("RECEIVE FLASH PASSIVE ABILITY. timemark: " + baseObjectMessage.timemark); baseObjectMessage.eventCode = eventCode; delayedMessages.AddLast(baseObjectMessage); break; case 12: baseObjectMessage = new BaseObjectMessage(); baseObjectMessage.Unpack((byte[])content); //Debug.Log("FLASH OBSTRUCTION[" + baseObjectMessage.id + "]. timemark: " + baseObjectMessage.timemark); gameNetwork.RpcFlashObstruction(baseObjectMessage.id); break; case 13: VisualEffectMessage visualEffectMessage = new VisualEffectMessage(); visualEffectMessage.Unpack((byte[])content); Debug.Log("VISUAL EFFECT [" + visualEffectMessage.id + "]. targetId: " + visualEffectMessage.targetId); visualEffectMessage.eventCode = eventCode; delayedMessages.AddLast(visualEffectMessage); break; case 14: PingMessage pingMessage = new PingMessage(); PingMessage newPingMessage; pingMessage.Unpack((byte[])content); if (pingMessage.time == 0.0f) { newPingMessage = new PingMessage(remoteTimestamp, pingMessage.timemark); PhotonNetwork.networkingPeer.OpCustom((byte)4, new Dictionary <byte, object> { { 245, newPingMessage.Pack() } }, true); } else { remoteTimestamp = pingMessage.timemark + pingMessage.time / 2.0f; } break; } }