Skip to content

Commit a4fbcbb

Browse files
update
Applying suggested changes.
1 parent 748d01e commit a4fbcbb

File tree

1 file changed

+23
-24
lines changed

1 file changed

+23
-24
lines changed

com.unity.netcode.gameobjects/Components/NetworkTransform.cs

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,10 @@ internal NetworkVariable<NetworkTransformState> ReplicatedNetworkState
434434
}
435435
}
436436

437+
// Used by both authoritative and non-authoritative instances.
438+
// This represents the most recent local authoritative state.
439+
private NetworkTransformState m_LocalAuthoritativeNetworkState;
440+
437441
private ClientRpcParams m_ClientRpcParams = new ClientRpcParams() { Send = new ClientRpcSendParams() };
438442
private List<ulong> m_ClientIds = new List<ulong>() { 0 };
439443

@@ -446,16 +450,17 @@ internal NetworkVariable<NetworkTransformState> ReplicatedNetworkState
446450
private BufferedLinearInterpolator<float> m_ScaleZInterpolator;
447451
private readonly List<BufferedLinearInterpolator<float>> m_AllFloatInterpolators = new List<BufferedLinearInterpolator<float>>(6);
448452

449-
// Used by both authoritative and non-authoritative instances.
450-
// This represents the most recent local authoritative state.
451-
private NetworkTransformState m_LocalAuthoritativeNetworkState;
452-
453453
// Used by integration test
454454
private NetworkTransformState m_LastSentState;
455455

456456
// Used by the non-authoritative side to handle ending extrapolation
457457
private NetworkTransformState m_LastReceivedState;
458458

459+
internal NetworkTransformState GetLastSentState()
460+
{
461+
return m_LastSentState;
462+
}
463+
459464
/// Calculated when spawned, this is used to offset a newly received non-authority side state by 1 tick duration
460465
/// in order to end the extrapolation for that state's values.
461466
/// Example:
@@ -465,11 +470,6 @@ internal NetworkVariable<NetworkTransformState> ReplicatedNetworkState
465470
/// <see cref="OnNetworkStateChanged"/> to see how NetworkState-A-Post doesn't get excluded/missed
466471
private double m_TickFrequency;
467472

468-
internal NetworkTransformState GetLastSentState()
469-
{
470-
return m_LastSentState;
471-
}
472-
473473
/// <summary>
474474
/// This will try to send/commit the current transform delta states (if any)
475475
/// </summary>
@@ -487,8 +487,12 @@ protected void TryCommitTransformToServer(Transform transformToCommit, double di
487487
return;
488488
}
489489

490-
// Either updates the authority or sends and RPC to the authoritative instance
491-
if (!TryUpdateAuthority(transformToCommit))
490+
// If we are authority, update the authoritative state
491+
if (CanCommitToTransform)
492+
{
493+
UpdateAuthoritativeState(transform);
494+
}
495+
else // Non-Authority
492496
{
493497
// We are an owner requesting to update our state
494498
if (!m_CachedIsServer)
@@ -1017,7 +1021,7 @@ private void OnNetworkStateChanged(NetworkTransformState oldState, NetworkTransf
10171021

10181022
// Set the current local tick and wait until the next tick before we end
10191023
// this state's extrapolation.
1020-
m_LastReceivedState.EndExtrapolationTick = NetworkManager.LocalTime.Tick;
1024+
m_LastReceivedState.EndExtrapolationTick = NetworkManager.LocalTime.Tick + 2;
10211025
}
10221026
}
10231027

@@ -1262,13 +1266,8 @@ private void SetStateServerRpc(Vector3 pos, Quaternion rot, Vector3 scale, bool
12621266
/// If it is not authority it exits early returning false.
12631267
/// </summary>
12641268
/// <param name="transformSource">transform to be updated</param>
1265-
private bool TryUpdateAuthority(Transform transformSource)
1269+
private void UpdateAuthoritativeState(Transform transformSource)
12661270
{
1267-
if (!CanCommitToTransform)
1268-
{
1269-
return false;
1270-
}
1271-
12721271
// If our replicated state is not dirty and our local authority state is dirty, clear it.
12731272
if (!ReplicatedNetworkState.IsDirty() && m_LocalAuthoritativeNetworkState.IsDirty)
12741273
{
@@ -1278,7 +1277,6 @@ private bool TryUpdateAuthority(Transform transformSource)
12781277
}
12791278

12801279
TryCommitTransform(transformSource, m_CachedNetworkManager.LocalTime.Time);
1281-
return true;
12821280
}
12831281

12841282
/// <inheritdoc/>
@@ -1295,11 +1293,12 @@ protected virtual void Update()
12951293
return;
12961294
}
12971295

1298-
// Either updates the authority or handle:
1299-
// - Non-authoritative side interpolation
1300-
// - Applying the current authoritative state
1301-
// - Stop extrapolating the current state (if it is 1 tick after it was received)
1302-
if (!TryUpdateAuthority(transform))
1296+
// If we are authority, update the authoritative state
1297+
if (CanCommitToTransform)
1298+
{
1299+
UpdateAuthoritativeState(transform);
1300+
}
1301+
else // Non-Authority
13031302
{
13041303
if (Interpolate)
13051304
{

0 commit comments

Comments
 (0)