void Update() { if (m_PhotonView.isMine == false && PhotonNetwork.connected == true) { m_Animator.applyRootMotion = false; } if (PhotonNetwork.inRoom == false || PhotonNetwork.room.playerCount <= 1) { m_StreamQueue.Reset(); return; } if (m_PhotonView.isMine == true) { SerializeDataContinuously(); } else { DeserializeDataContinuously(); } }
void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info) { if (m_Animator == null) { return; } if (stream.isWriting == true) { if (m_WasSynchronizeTypeChanged == true) { m_StreamQueue.Reset(); SerializeSynchronizationTypeState(stream); m_WasSynchronizeTypeChanged = false; } m_StreamQueue.Serialize(stream); SerializeDataDiscretly(stream); } else { #if PHOTON_DEVELOP if (ReceivingSender != null) { ReceivingSender.OnPhotonSerializeView(stream, info); } else #endif { if (stream.PeekNext() is byte[]) { DeserializeSynchronizationTypeState(stream); } m_StreamQueue.Deserialize(stream); DeserializeDataDiscretly(stream); } } }
/// <summary> /// Reads/writes the continuous animator parameters. /// </summary> private void Update() { if (PhotonNetwork.InRoom == false || PhotonNetwork.CurrentRoom.PlayerCount <= 1) { m_StreamQueue.Reset(); return; } // OnPhotonSerializeView is called within FixedUpdate while certain parameters need to be updated more often for a smooth movement. // Update those parameters here. if (m_PhotonView.IsMine) { m_StreamQueue.SendNext(HorizontalMovement); m_StreamQueue.SendNext(ForwardMovement); m_StreamQueue.SendNext(Pitch); m_StreamQueue.SendNext(Yaw); m_StreamQueue.SendNext(AbilityIndex); m_StreamQueue.SendNext(AbilityFloatData); } else { if (m_StreamQueue.HasQueuedObjects()) { SetHorizontalMovementParameter((float)m_StreamQueue.ReceiveNext(), 1); SetForwardMovementParameter((float)m_StreamQueue.ReceiveNext(), 1); SetPitchParameter((float)m_StreamQueue.ReceiveNext(), 1); SetYawParameter((float)m_StreamQueue.ReceiveNext(), 1); var abilityIndex = (int)m_StreamQueue.ReceiveNext(); // When the animator is snapped the ability index will be reset. It may take some time for that value to propagate across the network. // Wait to set the ability index until it is the correct reset value. if (m_SnappedAbilityIndex == -1 || abilityIndex == m_SnappedAbilityIndex) { SetAbilityIndexParameter(abilityIndex); m_SnappedAbilityIndex = -1; } SetAbilityFloatDataParameter((float)m_StreamQueue.ReceiveNext(), 1); } } }
/// <summary> /// Updates the LookSource values. /// </summary> public void Update() { if (PhotonNetwork.InRoom == false || PhotonNetwork.CurrentRoom.PlayerCount <= 1) { m_StreamQueue.Reset(); return; } // The look source variables are continuous and should be updated every frame. if (m_PhotonView.IsMine) { m_StreamQueue.SendNext(m_LookSource.LookDirectionDistance); m_StreamQueue.SendNext(m_LookSource.Pitch); m_StreamQueue.SendNext(m_LookSource.LookPosition()); m_StreamQueue.SendNext(m_LookSource.LookDirection(false)); } else if (m_StreamQueue.HasQueuedObjects()) { m_LookDirectionDistance = (float)m_StreamQueue.ReceiveNext(); m_Pitch = (float)m_StreamQueue.ReceiveNext(); m_LookPosition = (Vector3)m_StreamQueue.ReceiveNext(); m_LookDirection = (Vector3)m_StreamQueue.ReceiveNext(); } }