Skip to content

Commit ce3787b

Browse files
committed
Update naming, add CanWrite method
1 parent 919302b commit ce3787b

File tree

4 files changed

+15
-14
lines changed

4 files changed

+15
-14
lines changed

com.unity.netcode.gameobjects/Runtime/Messaging/Messages/NetworkVariableDeltaMessage.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ public void Serialize(FastBufferWriter writer, int targetVersion)
145145
var networkVariable = NetworkBehaviour.NetworkVariableFields[i];
146146
var shouldWrite = networkVariable.IsDirty() &&
147147
networkVariable.CanClientRead(TargetClientId) &&
148-
(networkManager.IsServer || networkVariable.CanClientWrite(networkManager.LocalClientId)) &&
148+
(networkManager.IsServer || networkVariable.CanWrite()) &&
149149
networkVariable.CanSend();
150150

151151
// Prevent the server from writing to the client that owns a given NetworkVariable

com.unity.netcode.gameobjects/Runtime/NetworkVariable/AnticipatedNetworkVariable.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ public void Anticipate(T value)
189189
m_LastAnticipationCounter = m_NetworkBehaviour.NetworkManager.AnticipationSystem.AnticipationCounter;
190190
m_AnticipatedValue = value;
191191
NetworkVariableSerialization<T>.Duplicate(m_AnticipatedValue, ref m_PreviousAnticipatedValue);
192-
if (CanClientWrite(m_NetworkBehaviour.NetworkManager.LocalClientId))
192+
if (CanWrite())
193193
{
194194
AuthoritativeValue = value;
195195
}

com.unity.netcode.gameobjects/Runtime/NetworkVariable/NetworkVariable.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ public virtual T Value
112112
get => m_InternalValue;
113113
set
114114
{
115-
if (LocalClientCannotWrite())
115+
if (CannotWrite())
116116
{
117117
LogWritePermissionError();
118118
return;
@@ -145,7 +145,7 @@ public bool CheckDirtyState(bool forceCheck = false)
145145
var isDirty = base.IsDirty();
146146

147147
// A client without permissions invoking this method should only check to assure the current value is equal to the last known current value
148-
if (LocalClientCannotWrite())
148+
if (CannotWrite())
149149
{
150150
// If modifications are detected, then revert back to the last known current value
151151
if (!NetworkVariableSerialization<T>.AreEqual(ref m_InternalValue, ref m_InternalOriginalValue))
@@ -221,7 +221,7 @@ public override bool IsDirty()
221221
{
222222
// If the client does not have write permissions but the internal value is determined to be locally modified and we are applying updates, then we should revert
223223
// to the original collection value prior to applying updates (primarily for collections).
224-
if (!NetworkUpdaterCheck && LocalClientCannotWrite() && !NetworkVariableSerialization<T>.AreEqual(ref m_InternalValue, ref m_InternalOriginalValue))
224+
if (!NetworkUpdaterCheck && CannotWrite() && !NetworkVariableSerialization<T>.AreEqual(ref m_InternalValue, ref m_InternalOriginalValue))
225225
{
226226
NetworkVariableSerialization<T>.Duplicate(m_InternalOriginalValue, ref m_InternalValue);
227227
return true;
@@ -297,7 +297,7 @@ public override void ReadDelta(FastBufferReader reader, bool keepDirtyDelta)
297297
{
298298
// If the client does not have write permissions but the internal value is determined to be locally modified and we are applying updates, then we should revert
299299
// to the original collection value prior to applying updates (primarily for collections).
300-
if (LocalCLientCannotWrite() && !NetworkVariableSerialization<T>.AreEqual(ref m_InternalOriginalValue, ref m_InternalValue))
300+
if (CannotWrite() && !NetworkVariableSerialization<T>.AreEqual(ref m_InternalOriginalValue, ref m_InternalValue))
301301
{
302302
NetworkVariableSerialization<T>.Duplicate(m_InternalOriginalValue, ref m_InternalValue);
303303
}
@@ -338,7 +338,7 @@ public override void ReadField(FastBufferReader reader)
338338
{
339339
// If the client does not have write permissions but the internal value is determined to be locally modified and we are applying updates, then we should revert
340340
// to the original collection value prior to applying updates (primarily for collections).
341-
if (LocalClientCannotWrite() && !NetworkVariableSerialization<T>.AreEqual(ref m_InternalOriginalValue, ref m_InternalValue))
341+
if (CannotWrite() && !NetworkVariableSerialization<T>.AreEqual(ref m_InternalOriginalValue, ref m_InternalValue))
342342
{
343343
NetworkVariableSerialization<T>.Duplicate(m_InternalOriginalValue, ref m_InternalValue);
344344
}

com.unity.netcode.gameobjects/Runtime/NetworkVariable/NetworkVariableBase.cs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -337,15 +337,16 @@ public bool CanClientWrite(ulong clientId)
337337
return clientId == m_NetworkBehaviour.NetworkObject.OwnerClientId;
338338
}
339339
}
340+
340341
/// <summary>
341-
/// Catches if the current <see cref="NetworkManager.LocalClientId"/> is not valid to write to this variable.
342+
/// Returns true if the current <see cref="NetworkManager.LocalClientId"/> can write to this variable; otherwise false.
342343
/// </summary>
343-
/// <returns>false if the current <see cref="NetworkManager.LocalClientId"/> can write to this variable, true otherwise</returns>
344-
[MethodImpl(MethodImplOptions.AggressiveInlining)]
345-
internal bool LocalClientCannotWrite()
346-
{
347-
return m_NetworkManager && !CanClientWrite(m_NetworkManager.LocalClientId);
348-
}
344+
internal bool CanWrite => m_NetworkManager && CanClientWrite(m_NetworkManager.LocalClientId);
345+
346+
/// <summary>
347+
/// Returns false if the current <see cref="NetworkManager.LocalClientId"/> can write to this variable; otherwise true.
348+
/// </summary>
349+
internal bool CannotWrite => m_NetworkManager && !CanClientWrite(m_NetworkManager.LocalClientId);
349350

350351
/// <summary>
351352
/// Returns the ClientId of the owning client

0 commit comments

Comments
 (0)