Skip to content

Commit 69be216

Browse files
committed
Update NetworkList
1 parent 1e4006e commit 69be216

File tree

2 files changed

+81
-72
lines changed

2 files changed

+81
-72
lines changed

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

Lines changed: 81 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@ public class NetworkList<T> : NetworkVariableBase where T : unmanaged, IEquatabl
2626
public event OnListChangedDelegate OnListChanged;
2727

2828
/// <summary>
29-
/// Constructor method for <see cref="NetworkList"/>
29+
/// Creates a <see cref="NetworkList{T}"/>
3030
/// </summary>
3131
public NetworkList() { }
3232

33-
/// <inheritdoc/>
34-
/// <param name="values"></param>
35-
/// <param name="readPerm"></param>
36-
/// <param name="writePerm"></param>
33+
/// <inheritdoc cref="NetworkList{T}"/>
34+
/// <param name="values">An optional collection of initial values to populate the list. If null, the list will start empty.</param>
35+
/// <param name="readPerm">The read permission level for the network list. Determines who can read the list (e.g., server-only or everyone). Default is defined by DefaultReadPerm</param>
36+
/// <param name="writePerm">The write permission level for the network list. Determines who can modify the list (e.g., server-only or specific clients). Default is defined by DefaultWritePerm.</param>
3737
public NetworkList(IEnumerable<T> values = default,
3838
NetworkVariableReadPermission readPerm = DefaultReadPerm,
3939
NetworkVariableWritePermission writePerm = DefaultWritePerm)
@@ -54,7 +54,7 @@ public NetworkList(IEnumerable<T> values = default,
5454
Dispose();
5555
}
5656

57-
/// <inheritdoc />
57+
/// <inheritdoc cref="NetworkVariable{T}.ResetDirty"/>
5858
public override void ResetDirty()
5959
{
6060
base.ResetDirty();
@@ -64,7 +64,7 @@ public override void ResetDirty()
6464
}
6565
}
6666

67-
/// <inheritdoc />
67+
/// <inheritdoc cref="NetworkVariable{T}.IsDirty"/>
6868
public override bool IsDirty()
6969
{
7070
// we call the base class to allow the SetDirty() mechanism to work
@@ -76,7 +76,7 @@ internal void MarkNetworkObjectDirty()
7676
MarkNetworkBehaviourDirty();
7777
}
7878

79-
/// <inheritdoc />
79+
/// <inheritdoc cref="NetworkVariable{T}.WriteDelta"/>
8080
public override void WriteDelta(FastBufferWriter writer)
8181
{
8282

@@ -132,7 +132,7 @@ public override void WriteDelta(FastBufferWriter writer)
132132
}
133133
}
134134

135-
/// <inheritdoc />
135+
/// <inheritdoc cref="NetworkVariable{T}.WriteField"/>
136136
public override void WriteField(FastBufferWriter writer)
137137
{
138138
writer.WriteValueSafe((ushort)m_List.Length);
@@ -142,7 +142,7 @@ public override void WriteField(FastBufferWriter writer)
142142
}
143143
}
144144

145-
/// <inheritdoc />
145+
/// <inheritdoc cref="NetworkVariable{T}.ReadField"/>
146146
public override void ReadField(FastBufferReader reader)
147147
{
148148
m_List.Clear();
@@ -155,15 +155,15 @@ public override void ReadField(FastBufferReader reader)
155155
}
156156
}
157157

158-
/// <inheritdoc />
158+
/// <inheritdoc cref="NetworkVariable{T}.ReadDelta"/>
159159
public override void ReadDelta(FastBufferReader reader, bool keepDirtyDelta)
160160
{
161-
/// This is only invoked by <see cref="NetworkVariableDeltaMessage"/> and the only time
162-
/// keepDirtyDelta is set is when it is the server processing. To be able to handle previous
163-
/// versions, we use IsServer to keep the dirty states received and the keepDirtyDelta to
164-
/// actually mark this as dirty and add it to the list of <see cref="NetworkObject"/>s to
165-
/// be updated. With the forwarding of deltas being handled by <see cref="NetworkVariableDeltaMessage"/>,
166-
/// once all clients have been forwarded the dirty events, we clear them by invoking <see cref="PostDeltaRead"/>.
161+
// This is only invoked by <see cref="NetworkVariableDeltaMessage"/> and the only time
162+
// keepDirtyDelta is set is when it is the server processing. To be able to handle previous
163+
// versions, we use IsServer to keep the dirty states received and the keepDirtyDelta to
164+
// actually mark this as dirty and add it to the list of <see cref="NetworkObject"/>s to
165+
// be updated. With the forwarding of deltas being handled by <see cref="NetworkVariableDeltaMessage"/>,
166+
// once all clients have been forwarded the dirty events, we clear them by invoking <see cref="PostDeltaRead"/>.
167167
var isServer = m_NetworkManager.IsServer;
168168
reader.ReadValueSafe(out ushort deltaCount);
169169
for (int i = 0; i < deltaCount; i++)
@@ -394,7 +394,7 @@ public override void ReadDelta(FastBufferReader reader, bool keepDirtyDelta)
394394
}
395395
}
396396

397-
/// <inheritdoc />
397+
/// <inheritdoc cref="NetworkVariable{T}.PostDeltaRead"/>
398398
/// <remarks>
399399
/// For NetworkList, we just need to reset dirty if a server has read deltas
400400
/// </remarks>
@@ -406,13 +406,22 @@ internal override void PostDeltaRead()
406406
}
407407
}
408408

409-
/// <inheritdoc />
409+
/// <summary>
410+
/// Returns an enumerator that iterates through the <see cref="NetworkList{T}" />.
411+
/// </summary>
412+
/// <returns>An enumerator for the <see cref="NetworkList{T}"/>.</returns>
410413
public IEnumerator<T> GetEnumerator()
411414
{
412415
return m_List.GetEnumerator();
413416
}
414417

415-
/// <inheritdoc />
418+
/// <summary>
419+
/// Adds an item to the end of the <see cref="NetworkList{T}"/>.
420+
/// </summary>
421+
/// <param name="item">The item to be added to the list.</param>
422+
/// <remarks>
423+
/// This method checks for write permissions before adding the item.
424+
/// </remarks>
416425
public void Add(T item)
417426
{
418427
// check write permissions
@@ -434,7 +443,12 @@ public void Add(T item)
434443
HandleAddListEvent(listEvent);
435444
}
436445

437-
/// <inheritdoc />
446+
/// <summary>
447+
/// Removes all items from the <see cref="NetworkList{T}"/>.
448+
/// </summary>
449+
/// <remarks>
450+
/// This method checks for write permissions before clearing the list.
451+
/// </remarks>
438452
public void Clear()
439453
{
440454
// check write permissions
@@ -454,14 +468,25 @@ public void Clear()
454468
HandleAddListEvent(listEvent);
455469
}
456470

457-
/// <inheritdoc />
471+
/// <summary>
472+
/// Determines whether the <see cref="NetworkList{T}"/> contains a specific value.
473+
/// </summary>
474+
/// <param name="item">The object to locate in the <see cref="NetworkList{T}"/>.</param>
475+
/// <returns><see langword="true" /> if the <see cref="item"/> is found in the <see cref="NetworkList{T}"/>; otherwise, <see langword="false" />.</returns>
458476
public bool Contains(T item)
459477
{
460478
int index = m_List.IndexOf(item);
461479
return index != -1;
462480
}
463481

464-
/// <inheritdoc />
482+
/// <summary>
483+
/// Removes the first occurrence of a specific object from the <see cref="NetworkList{T}"/>.
484+
/// </summary>
485+
/// <remarks>
486+
/// This method checks for write permissions before removing the item.
487+
/// </remarks>
488+
/// <param name="item">The object to remove from the list.</param>
489+
/// <returns><see langword="true" /> if the item was successfully removed from the list; otherwise, <see langword="false" />.</returns>
465490
public bool Remove(T item)
466491
{
467492
// check write permissions
@@ -488,16 +513,29 @@ public bool Remove(T item)
488513
return true;
489514
}
490515

491-
/// <inheritdoc />
516+
/// <summary>
517+
/// Gets the number of elements contained in the <see cref="NetworkList{T}"/>.
518+
/// </summary>
492519
public int Count => m_List.Length;
493520

494-
/// <inheritdoc />
521+
/// <summary>
522+
/// Determines the index of a specific <see cref="item"/> in the <see cref="NetworkList{T}"/>.
523+
/// </summary>
524+
/// <param name="item">The object to remove from the list.</param>
525+
/// <returns>The index of the <see cref="item"/> if found in the list; otherwise, -1.</returns>
495526
public int IndexOf(T item)
496527
{
497528
return m_List.IndexOf(item);
498529
}
499530

500-
/// <inheritdoc />
531+
/// <summary>
532+
/// Inserts <see cref="item"/> to the <see cref="NetworkList{T}"/> at the specified <see cref="index"/>.
533+
/// </summary>
534+
/// <remarks>
535+
/// This method checks for write permissions before inserting the item.
536+
/// </remarks>
537+
/// <param name="index">The index at which the item should be inserted.</param>
538+
/// <param name="item">The item to insert.</param>
501539
public void Insert(int index, T item)
502540
{
503541
// check write permissions
@@ -527,7 +565,13 @@ public void Insert(int index, T item)
527565
HandleAddListEvent(listEvent);
528566
}
529567

530-
/// <inheritdoc />
568+
/// <summary>
569+
/// Removes the <see cref="NetworkList{T}"/> item at the specified index.
570+
/// </summary>
571+
/// <remarks>
572+
/// This method checks for write permissions before removing the item.
573+
/// </remarks>
574+
/// <param name="index">The index of the element to remove.</param>
531575
public void RemoveAt(int index)
532576
{
533577
// check write permissions
@@ -550,7 +594,14 @@ public void RemoveAt(int index)
550594
HandleAddListEvent(listEvent);
551595
}
552596

553-
/// <inheritdoc />
597+
/// <summary>
598+
/// Gets or sets the element at the specified index in the <see cref="NetworkList{T}"/>.
599+
/// </summary>
600+
/// <remarks>
601+
/// This method checks for write permissions before setting the value.
602+
/// </remarks>
603+
/// <param name="index">The zero-based index of the element to get or set.</param>
604+
/// <returns>The element at the specified index.</returns>
554605
public T this[int index]
555606
{
556607
get => m_List[index];
@@ -586,16 +637,9 @@ private void HandleAddListEvent(NetworkListEvent<T> listEvent)
586637
}
587638

588639
/// <summary>
589-
/// This is actually unused left-over from a previous interface
640+
/// This method should not be used. It is left over from a previous interface.
590641
/// </summary>
591-
public int LastModifiedTick
592-
{
593-
get
594-
{
595-
// todo: implement proper network tick for NetworkList
596-
return NetworkTickSystem.NoTick;
597-
}
598-
}
642+
public int LastModifiedTick => NetworkTickSystem.NoTick;
599643

600644
/// <summary>
601645
/// Overridden <see cref="IDisposable"/> implementation.

pvpExceptions.json

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,6 @@
77
},
88
"PVP-150-1": {
99
"errors": [
10-
"Unity.Netcode.NetworkList<T>: .ctor(IEnumerable<T>, NetworkVariableReadPermission, NetworkVariableWritePermission): cannot auto-inheritdoc (not an override or interface implementation); <inheritdoc> must specify 'cref'",
11-
"Unity.Netcode.NetworkList<T>: .ctor(IEnumerable<T>, NetworkVariableReadPermission, NetworkVariableWritePermission): empty <param> tag",
12-
"Unity.Netcode.NetworkList<T>: IEnumerator<T> GetEnumerator(): cannot auto-inheritdoc (not an override or interface implementation); <inheritdoc> must specify 'cref'",
13-
"Unity.Netcode.NetworkList<T>: void Add(T): cannot auto-inheritdoc (not an override or interface implementation); <inheritdoc> must specify 'cref'",
14-
"Unity.Netcode.NetworkList<T>: void Clear(): cannot auto-inheritdoc (not an override or interface implementation); <inheritdoc> must specify 'cref'",
15-
"Unity.Netcode.NetworkList<T>: bool Contains(T): cannot auto-inheritdoc (not an override or interface implementation); <inheritdoc> must specify 'cref'",
16-
"Unity.Netcode.NetworkList<T>: bool Remove(T): cannot auto-inheritdoc (not an override or interface implementation); <inheritdoc> must specify 'cref'",
17-
"Unity.Netcode.NetworkList<T>: Count: cannot auto-inheritdoc (not an override or interface implementation); <inheritdoc> must specify 'cref'",
18-
"Unity.Netcode.NetworkList<T>: int IndexOf(T): cannot auto-inheritdoc (not an override or interface implementation); <inheritdoc> must specify 'cref'",
19-
"Unity.Netcode.NetworkList<T>: void Insert(int, T): cannot auto-inheritdoc (not an override or interface implementation); <inheritdoc> must specify 'cref'",
20-
"Unity.Netcode.NetworkList<T>: void RemoveAt(int): cannot auto-inheritdoc (not an override or interface implementation); <inheritdoc> must specify 'cref'",
21-
"Unity.Netcode.NetworkList<T>: this[int]: cannot auto-inheritdoc (not an override or interface implementation); <inheritdoc> must specify 'cref'",
2210
"Unity.Netcode.UserNetworkVariableSerialization<T>: empty <typeparam> tag",
2311
"Unity.Netcode.UserNetworkVariableSerialization<T>.DuplicateValueDelegate: unexpected <param name=\"reader\">",
2412
"Unity.Netcode.NetworkVariableSerializationTypes: void InitializeSerializer_UnmanagedByMemcpy(): empty <typeparam> tag",
@@ -148,30 +136,7 @@
148136
"Unity.Netcode.AnticipatedNetworkVariable<T>.SmoothDelegate: missing <param name=\"anticipatedValue\">",
149137
"Unity.Netcode.AnticipatedNetworkVariable<T>.SmoothDelegate: missing <param name=\"amount\">",
150138
"Unity.Netcode.AnticipatedNetworkVariable<T>.SmoothDelegate: missing <returns>",
151-
"Unity.Netcode.NetworkList<T>: .ctor(IEnumerable<T>, NetworkVariableReadPermission, NetworkVariableWritePermission): missing <summary>",
152139
"Unity.Netcode.NetworkList<T>: void Finalize(): undocumented",
153-
"Unity.Netcode.NetworkList<T>: IEnumerator<T> GetEnumerator(): missing <summary>",
154-
"Unity.Netcode.NetworkList<T>: IEnumerator<T> GetEnumerator(): missing <returns>",
155-
"Unity.Netcode.NetworkList<T>: void Add(T): missing <summary>",
156-
"Unity.Netcode.NetworkList<T>: void Add(T): missing <param name=\"item\">",
157-
"Unity.Netcode.NetworkList<T>: void Clear(): missing <summary>",
158-
"Unity.Netcode.NetworkList<T>: bool Contains(T): missing <summary>",
159-
"Unity.Netcode.NetworkList<T>: bool Contains(T): missing <param name=\"item\">",
160-
"Unity.Netcode.NetworkList<T>: bool Contains(T): missing <returns>",
161-
"Unity.Netcode.NetworkList<T>: bool Remove(T): missing <summary>",
162-
"Unity.Netcode.NetworkList<T>: bool Remove(T): missing <param name=\"item\">",
163-
"Unity.Netcode.NetworkList<T>: bool Remove(T): missing <returns>",
164-
"Unity.Netcode.NetworkList<T>: Count: missing <summary>",
165-
"Unity.Netcode.NetworkList<T>: int IndexOf(T): missing <summary>",
166-
"Unity.Netcode.NetworkList<T>: int IndexOf(T): missing <param name=\"item\">",
167-
"Unity.Netcode.NetworkList<T>: int IndexOf(T): missing <returns>",
168-
"Unity.Netcode.NetworkList<T>: void Insert(int, T): missing <summary>",
169-
"Unity.Netcode.NetworkList<T>: void Insert(int, T): missing <param name=\"index\">",
170-
"Unity.Netcode.NetworkList<T>: void Insert(int, T): missing <param name=\"item\">",
171-
"Unity.Netcode.NetworkList<T>: void RemoveAt(int): missing <summary>",
172-
"Unity.Netcode.NetworkList<T>: void RemoveAt(int): missing <param name=\"index\">",
173-
"Unity.Netcode.NetworkList<T>: this[int]: missing <summary>",
174-
"Unity.Netcode.NetworkList<T>: this[int]: missing <param name=\"index\">",
175140
"Unity.Netcode.NetworkVariable<T>: CheckExceedsDirtinessThreshold: undocumented",
176141
"Unity.Netcode.NetworkVariable<T>: bool ExceedsDirtinessThreshold(): undocumented",
177142
"Unity.Netcode.NetworkVariable<T>: void OnInitialize(): undocumented",

0 commit comments

Comments
 (0)