public void uLink_OnSerializeNetworkView(uLink.BitStream stream, uLink.NetworkMessageInfo info)
{
Vector3 pPosition = stream.isWriting ? transform.position : Vector3.zero;
bool wasJumping = activelyJumping;
stream.Serialize(ref pPosition);
stream.Serialize(ref playDashSound);
stream.Serialize(ref playJumpSound);
stream.Serialize(ref lookRotationEuler);
// Health script (should be moved here probably)
stream.Serialize(ref HealthScript._Shield);
stream.Serialize(ref HealthScript._Health);
if (stream.isReading)
{
float elapsedTime = TimeSinceLastNetworkFrame;
//AverageTimeBetweenNetworkFrames = Mathf.Lerp(AverageTimeBetweenNetworkFrames, elapsedTime,
// 1f - Mathf.Pow(0.1f, elapsedTime));
//SlowAverageTimeBetweenNetworkFrames = Mathf.Lerp(AverageTimeBetweenNetworkFrames, elapsedTime,
// 1f - Mathf.Pow(0.8f, elapsedTime));
TimeSinceLastNetworkFrame = 0f;
LastNetworkFrameTakeTime = elapsedTime;
//RecentWorstNetworkTakeTime = Mathf.Max(RecentWorstNetworkTakeTime, LastNetworkFrameTakeTime);
PreviousNetworkPosition = NewestNetworkPosition;
NewestNetworkPosition = pPosition;
Vector3 positionDifference = pPosition - lastNetworkFramePosition;
ImpliedMovementVelocity = positionDifference / elapsedTime;
ImpliedInputVelocity = ImpliedMovementVelocity;
ImpliedInputVelocity.y = 0;
inputVelocity = ImpliedInputVelocity;
if (playDashSound && GlobalSoundsScript.soundEnabled)
{
dashSound.Play();
Vector3 implied = ImpliedMovementVelocity.normalized;
// In case dash is performed while jumping straight up
if (Vector3.Dot(implied, Vector3.down) > 0.8f)
RemoteDashVelocity = Vector3.up;
else
RemoteDashVelocity = ImpliedMovementVelocity.normalized;
if (currentAnim == "jump")
characterAnimation.Rewind("jump");
else characterAnimation.CrossFade(currentAnim = "jump", IdleTransitionFadeLength );
}
if (playJumpSound && GlobalSoundsScript.soundEnabled) jumpSound.Play();
lastNetworkFramePosition = pPosition;
// Play jump animation if it seems necessary
if (!wasJumping && activelyJumping && currentAnim != "jump")
characterAnimation.CrossFade(currentAnim = "jump", IdleTransitionFadeLength );
HealthScript.UpdateShield();
}
playJumpSound = playDashSound = false;
}