void SerializeDataContinuously() { if (m_Animator == null) { return; } for (int i = 0; i < m_SynchronizeLayers.Count; ++i) { if (m_SynchronizeLayers[i].SynchronizeType == SynchronizeType.Continuous) { m_StreamQueue.SendNext(m_Animator.GetLayerWeight(m_SynchronizeLayers[i].LayerIndex)); } } for (int i = 0; i < m_SynchronizeParameters.Count; ++i) { SynchronizedParameter parameter = m_SynchronizeParameters[i]; if (parameter.SynchronizeType == SynchronizeType.Continuous) { switch (parameter.Type) { case ParameterType.Bool: m_StreamQueue.SendNext(m_Animator.GetBool(parameter.Name)); break; case ParameterType.Float: m_StreamQueue.SendNext(m_Animator.GetFloat(parameter.Name)); break; case ParameterType.Int: m_StreamQueue.SendNext(m_Animator.GetInteger(parameter.Name)); break; case ParameterType.Trigger: break; } } } }
/// <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(); } }
/// <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); } } }