Skip to content

Commit d33a784

Browse files
committed
Update naming, add CanWrite method
1 parent 06bc67e commit d33a784

File tree

5 files changed

+20
-20
lines changed

5 files changed

+20
-20
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
@@ -217,7 +217,7 @@ public void Anticipate(T value)
217217
m_LastAnticipationCounter = m_NetworkBehaviour.NetworkManager.AnticipationSystem.AnticipationCounter;
218218
m_AnticipatedValue = value;
219219
NetworkVariableSerialization<T>.Duplicate(m_AnticipatedValue, ref m_PreviousAnticipatedValue);
220-
if (CanClientWrite(m_NetworkBehaviour.NetworkManager.LocalClientId))
220+
if (CanWrite())
221221
{
222222
AuthoritativeValue = value;
223223
}

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ public IEnumerator<T> GetEnumerator()
428428
public void Add(T item)
429429
{
430430
// check write permissions
431-
if (LocalClientCannotWrite())
431+
if (CannotWrite())
432432
{
433433
LogWritePermissionError();
434434
return;
@@ -455,7 +455,7 @@ public void Add(T item)
455455
public void Clear()
456456
{
457457
// check write permissions
458-
if (LocalClientCannotWrite())
458+
if (CannotWrite())
459459
{
460460
LogWritePermissionError();
461461
return;
@@ -493,7 +493,7 @@ public bool Contains(T item)
493493
public bool Remove(T item)
494494
{
495495
// check write permissions
496-
if (LocalClientCannotWrite())
496+
if (CannotWrite())
497497
{
498498
LogWritePermissionError();
499499
return false;
@@ -542,7 +542,7 @@ public int IndexOf(T item)
542542
public void Insert(int index, T item)
543543
{
544544
// check write permissions
545-
if (LocalClientCannotWrite())
545+
if (CannotWrite())
546546
{
547547
LogWritePermissionError();
548548
return;
@@ -578,7 +578,7 @@ public void Insert(int index, T item)
578578
public void RemoveAt(int index)
579579
{
580580
// check write permissions
581-
if (LocalClientCannotWrite())
581+
if (CannotWrite())
582582
{
583583
throw new InvalidOperationException("Client is not allowed to write to this NetworkList");
584584
}
@@ -610,7 +610,7 @@ public T this[int index]
610610
set
611611
{
612612
// check write permissions
613-
if (LocalClientCannotWrite())
613+
if (CannotWrite())
614614
{
615615
LogWritePermissionError();
616616
return;

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ public virtual T Value
128128
get => m_InternalValue;
129129
set
130130
{
131-
if (LocalClientCannotWrite())
131+
if (CannotWrite())
132132
{
133133
LogWritePermissionError();
134134
return;
@@ -162,7 +162,7 @@ public bool CheckDirtyState(bool forceCheck = false)
162162
var isDirty = base.IsDirty();
163163

164164
// A client without permissions invoking this method should only check to assure the current value is equal to the last known current value
165-
if (LocalClientCannotWrite())
165+
if (CannotWrite())
166166
{
167167
// If modifications are detected, then revert back to the last known current value
168168
if (!NetworkVariableSerialization<T>.AreEqual(ref m_InternalValue, ref m_InternalOriginalValue))
@@ -245,7 +245,7 @@ public override bool IsDirty()
245245
{
246246
// 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
247247
// to the original collection value prior to applying updates (primarily for collections).
248-
if (!NetworkUpdaterCheck && LocalClientCannotWrite() && !NetworkVariableSerialization<T>.AreEqual(ref m_InternalValue, ref m_InternalOriginalValue))
248+
if (!NetworkUpdaterCheck && CannotWrite() && !NetworkVariableSerialization<T>.AreEqual(ref m_InternalValue, ref m_InternalOriginalValue))
249249
{
250250
NetworkVariableSerialization<T>.Duplicate(m_InternalOriginalValue, ref m_InternalValue);
251251
return true;
@@ -307,7 +307,7 @@ public override void ReadDelta(FastBufferReader reader, bool keepDirtyDelta)
307307
{
308308
// 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
309309
// to the original collection value prior to applying updates (primarily for collections).
310-
if (LocalClientCannotWrite() && !NetworkVariableSerialization<T>.AreEqual(ref m_InternalOriginalValue, ref m_InternalValue))
310+
if (CannotWrite() && !NetworkVariableSerialization<T>.AreEqual(ref m_InternalOriginalValue, ref m_InternalValue))
311311
{
312312
NetworkVariableSerialization<T>.Duplicate(m_InternalOriginalValue, ref m_InternalValue);
313313
}
@@ -349,7 +349,7 @@ public override void ReadField(FastBufferReader reader)
349349
{
350350
// 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
351351
// to the original collection value prior to applying updates (primarily for collections).
352-
if (LocalClientCannotWrite() && !NetworkVariableSerialization<T>.AreEqual(ref m_InternalOriginalValue, ref m_InternalValue))
352+
if (CannotWrite() && !NetworkVariableSerialization<T>.AreEqual(ref m_InternalOriginalValue, ref m_InternalValue))
353353
{
354354
NetworkVariableSerialization<T>.Duplicate(m_InternalOriginalValue, ref m_InternalValue);
355355
}

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -383,14 +383,14 @@ public bool CanClientWrite(ulong clientId)
383383
}
384384

385385
/// <summary>
386-
/// Catches if the current <see cref="NetworkManager.LocalClientId"/> is not valid to write to this variable.
386+
/// Returns true if the current <see cref="NetworkManager.LocalClientId"/> can write to this variable; otherwise false.
387387
/// </summary>
388-
/// <returns>false if the current <see cref="NetworkManager.LocalClientId"/> can write to this variable, true otherwise</returns>
389-
[MethodImpl(MethodImplOptions.AggressiveInlining)]
390-
internal bool LocalClientCannotWrite()
391-
{
392-
return m_NetworkManager && !CanClientWrite(m_NetworkManager.LocalClientId);
393-
}
388+
internal bool CanWrite => m_NetworkManager && CanClientWrite(m_NetworkManager.LocalClientId);
389+
390+
/// <summary>
391+
/// Returns false if the current <see cref="NetworkManager.LocalClientId"/> can write to this variable; otherwise true.
392+
/// </summary>
393+
internal bool CannotWrite => m_NetworkManager && !CanClientWrite(m_NetworkManager.LocalClientId);
394394

395395
/// <summary>
396396
/// Returns the ClientId of the owning client

0 commit comments

Comments
 (0)