public void uLink_OnSerializeNetworkView(uLink.BitStream stream, uLink.NetworkMessageInfo info) { uLink.NetworkViewID prevPossesedID = PossessedCharacterViewID; stream.Serialize(ref PossessedCharacterViewID); stream.Serialize(ref _IsDoingMenuStuff); stream.Serialize(ref _Score); stream.Serialize(ref _IsSpectating); stream.Serialize(ref _Ping); if (stream.isReading) { if (Possession == null) { // see if possession id from network is not null // see if new possession object from that id is not null // then assign PlayerScript character = TryGetPlayerScriptFromNetworkViewID(PossessedCharacterViewID); if (character != null) Possession = character; } else { // see if new possession id is different from current possession id // assign new possession, even if null if (prevPossesedID != PossessedCharacterViewID) { Possession = TryGetPlayerScriptFromNetworkViewID(PossessedCharacterViewID); } } } }
public void uLink_OnSerializeNetworkView(uLink.BitStream stream, uLink.NetworkMessageInfo info) { stream.Serialize(ref _IsGameActive); }
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; }