mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 02:50:32 +00:00
Merge 703a998790
into 451c297a43
This commit is contained in:
commit
30e1d4d53a
@ -23,6 +23,7 @@
|
|||||||
namespace Mirror
|
namespace Mirror
|
||||||
{
|
{
|
||||||
public enum CoordinateSpace { Local, World }
|
public enum CoordinateSpace { Local, World }
|
||||||
|
public enum UpdateMethod { Update, LateUpdate, FixedUpdate }
|
||||||
|
|
||||||
public abstract class NetworkTransformBase : NetworkBehaviour
|
public abstract class NetworkTransformBase : NetworkBehaviour
|
||||||
{
|
{
|
||||||
@ -119,6 +120,11 @@ public uint sendIntervalMultiplier
|
|||||||
protected double timeStampAdjustment => NetworkServer.sendInterval * (sendIntervalMultiplier - 1);
|
protected double timeStampAdjustment => NetworkServer.sendInterval * (sendIntervalMultiplier - 1);
|
||||||
protected double offset => timelineOffset ? NetworkServer.sendInterval * sendIntervalMultiplier : 0;
|
protected double offset => timelineOffset ? NetworkServer.sendInterval * sendIntervalMultiplier : 0;
|
||||||
|
|
||||||
|
// Update Method ///////////////////////////////////////////////////////////
|
||||||
|
[Header("Update Method")]
|
||||||
|
[Tooltip("Update by default. Try a different method when having problems with Physics or Animations.")]
|
||||||
|
public UpdateMethod updateMethod = UpdateMethod.Update;
|
||||||
|
|
||||||
// debugging ///////////////////////////////////////////////////////////
|
// debugging ///////////////////////////////////////////////////////////
|
||||||
[Header("Debug")]
|
[Header("Debug")]
|
||||||
public bool showGizmos;
|
public bool showGizmos;
|
||||||
|
@ -45,15 +45,15 @@ public class NetworkTransformReliable : NetworkTransformBase
|
|||||||
// update //////////////////////////////////////////////////////////////
|
// update //////////////////////////////////////////////////////////////
|
||||||
void Update()
|
void Update()
|
||||||
{
|
{
|
||||||
// if server then always sync to others.
|
if (updateMethod == UpdateMethod.Update)
|
||||||
if (isServer) UpdateServer();
|
UpdateCall();
|
||||||
// 'else if' because host mode shouldn't send anything to server.
|
|
||||||
// it is the server. don't overwrite anything there.
|
|
||||||
else if (isClient) UpdateClient();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void LateUpdate()
|
void LateUpdate()
|
||||||
{
|
{
|
||||||
|
if (updateMethod == UpdateMethod.LateUpdate)
|
||||||
|
UpdateCall();
|
||||||
|
|
||||||
// set dirty to trigger OnSerialize. either always, or only if changed.
|
// set dirty to trigger OnSerialize. either always, or only if changed.
|
||||||
// It has to be checked in LateUpdate() for onlySyncOnChange to avoid
|
// It has to be checked in LateUpdate() for onlySyncOnChange to avoid
|
||||||
// the possibility of Update() running first before the object's movement
|
// the possibility of Update() running first before the object's movement
|
||||||
@ -68,6 +68,21 @@ void LateUpdate()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FixedUpdate()
|
||||||
|
{
|
||||||
|
if (updateMethod == UpdateMethod.FixedUpdate)
|
||||||
|
UpdateCall();
|
||||||
|
}
|
||||||
|
|
||||||
|
void UpdateCall()
|
||||||
|
{
|
||||||
|
// if server then always sync to others.
|
||||||
|
if (isServer) UpdateServer();
|
||||||
|
// 'else if' because host mode shouldn't send anything to server.
|
||||||
|
// it is the server. don't overwrite anything there.
|
||||||
|
else if (isClient) UpdateClient();
|
||||||
|
}
|
||||||
|
|
||||||
protected virtual void UpdateServer()
|
protected virtual void UpdateServer()
|
||||||
{
|
{
|
||||||
// apply buffered snapshots IF client authority
|
// apply buffered snapshots IF client authority
|
||||||
|
@ -29,11 +29,8 @@ public class NetworkTransformUnreliable : NetworkTransformBase
|
|||||||
// Update applies interpolation
|
// Update applies interpolation
|
||||||
void Update()
|
void Update()
|
||||||
{
|
{
|
||||||
if (isServer) UpdateServerInterpolation();
|
if (updateMethod == UpdateMethod.Update)
|
||||||
// for all other clients (and for local player if !authority),
|
UpdateCall();
|
||||||
// we need to apply snapshots from the buffer.
|
|
||||||
// 'else if' because host mode shouldn't interpolate client
|
|
||||||
else if (isClient && !IsClientWithAuthority) UpdateClientInterpolation();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// LateUpdate broadcasts.
|
// LateUpdate broadcasts.
|
||||||
@ -43,6 +40,9 @@ void Update()
|
|||||||
// this could cause visible jitter.
|
// this could cause visible jitter.
|
||||||
void LateUpdate()
|
void LateUpdate()
|
||||||
{
|
{
|
||||||
|
if (updateMethod == UpdateMethod.LateUpdate)
|
||||||
|
UpdateCall();
|
||||||
|
|
||||||
// if server then always sync to others.
|
// if server then always sync to others.
|
||||||
if (isServer) UpdateServerBroadcast();
|
if (isServer) UpdateServerBroadcast();
|
||||||
// client authority, and local player (= allowed to move myself)?
|
// client authority, and local player (= allowed to move myself)?
|
||||||
@ -51,6 +51,21 @@ void LateUpdate()
|
|||||||
else if (isClient && IsClientWithAuthority) UpdateClientBroadcast();
|
else if (isClient && IsClientWithAuthority) UpdateClientBroadcast();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FixedUpdate()
|
||||||
|
{
|
||||||
|
if (updateMethod == UpdateMethod.FixedUpdate)
|
||||||
|
UpdateCall();
|
||||||
|
}
|
||||||
|
|
||||||
|
void UpdateCall()
|
||||||
|
{
|
||||||
|
if (isServer) UpdateServerInterpolation();
|
||||||
|
// for all other clients (and for local player if !authority),
|
||||||
|
// we need to apply snapshots from the buffer.
|
||||||
|
// 'else if' because host mode shouldn't interpolate client
|
||||||
|
else if (isClient && !IsClientWithAuthority) UpdateClientInterpolation();
|
||||||
|
}
|
||||||
|
|
||||||
protected virtual void CheckLastSendTime()
|
protected virtual void CheckLastSendTime()
|
||||||
{
|
{
|
||||||
// We check interval every frame, and then send if interval is reached.
|
// We check interval every frame, and then send if interval is reached.
|
||||||
|
Loading…
Reference in New Issue
Block a user