Class NetworkList<T>
Event based NetworkVariable container for syncing Lists
Implements
Inherited Members
Namespace: Unity.Netcode
Assembly: Unity.Netcode.Runtime.dll
Syntax
[GenerateSerializationForGenericParameter(0)]
public class NetworkList<T> : NetworkVariableBase, IDisposable where T : unmanaged, IEquatable<T>
Type Parameters
Name | Description |
---|---|
T | The type for the list |
Constructors
NetworkList()
Constructor method for Network
Declaration
public NetworkList()
NetworkList(IEnumerable<T>, NetworkVariableReadPermission, NetworkVariableWritePermission)
Event based NetworkVariable container for syncing Lists
Declaration
public NetworkList(IEnumerable<T> values = null, NetworkVariableReadPermission readPerm = NetworkVariableReadPermission.Everyone, NetworkVariableWritePermission writePerm = NetworkVariableWritePermission.Server)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<T> | values | An optional collection of initial values to populate the list. If null, the list will start empty. |
Network |
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 |
Network |
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. |
Properties
Count
Gets the number of elements contained in the Network
Declaration
public int Count { get; }
Property Value
Type | Description |
---|---|
int |
this[int]
Gets or sets the element at the specified index in the Network
Declaration
public T this[int index] { get; set; }
Parameters
Type | Name | Description |
---|---|---|
int | index | The zero-based index of the element to get or set. |
Property Value
Type | Description |
---|---|
T | The element at the specified index. |
Remarks
This method checks for write permissions before setting the value.
LastModifiedTick
This method should not be used. It is left over from a previous interface
Declaration
public int LastModifiedTick { get; }
Property Value
Type | Description |
---|---|
int |
Methods
Add(T)
Adds an item to the end of the Network
Declaration
public void Add(T item)
Parameters
Type | Name | Description |
---|---|---|
T | item | The item to be added to the list. |
Remarks
This method checks for write permissions before adding the item.
Clear()
Removes all items from the Network
Declaration
public void Clear()
Remarks
This method checks for write permissions before clearing the list.
Contains(T)
Determines whether the Network
Declaration
public bool Contains(T item)
Parameters
Type | Name | Description |
---|---|---|
T | item | The object to locate in the Network |
Returns
Type | Description |
---|---|
bool | true if the item is found in the Network |
Dispose()
Overridden IDisposable implementation. CAUTION: If you derive from this class and override the Dispose() method, you must always invoke the base.Dispose() method!
Declaration
public override void Dispose()
Overrides
~NetworkList()
Finalizer that ensures proper cleanup of network list resources
Declaration
protected ~NetworkList()
GetEnumerator()
Returns an enumerator that iterates through the Network
Declaration
public IEnumerator<T> GetEnumerator()
Returns
Type | Description |
---|---|
IEnumerator<T> | An enumerator for the Network |
IndexOf(T)
Determines the index of a specific item in the Network
Declaration
public int IndexOf(T item)
Parameters
Type | Name | Description |
---|---|---|
T | item | The object to remove from the list. |
Returns
Type | Description |
---|---|
int | The index of the item if found in the list; otherwise, -1. |
Insert(int, T)
Inserts item to the Network
Declaration
public void Insert(int index, T item)
Parameters
Type | Name | Description |
---|---|---|
int | index | The index at which the item should be inserted. |
T | item | The item to insert. |
Remarks
This method checks for write permissions before inserting the item.
IsDirty()
Gets Whether or not the container is dirty
Declaration
public override bool IsDirty()
Returns
Type | Description |
---|---|
bool | Whether or not the container is dirty |
Overrides
ReadDelta(FastBufferReader, bool)
Reads value from the reader and applies it
Declaration
public override void ReadDelta(FastBufferReader reader, bool keepDirtyDelta)
Parameters
Type | Name | Description |
---|---|---|
Fast |
reader | The stream to read the value from |
bool | keepDirtyDelta | Whether or not the container should keep the dirty delta, or mark the delta as consumed |
Overrides
ReadField(FastBufferReader)
Reads the complete state from the reader and applies it
Declaration
public override void ReadField(FastBufferReader reader)
Parameters
Type | Name | Description |
---|---|---|
Fast |
reader | The stream to read the state from |
Overrides
Remove(T)
Removes the first occurrence of a specific object from the NetworkList.
Declaration
public bool Remove(T item)
Parameters
Type | Name | Description |
---|---|---|
T | item | The object to remove from the list. |
Returns
Remarks
This method checks for write permissions before removing the item.
RemoveAt(int)
Removes the Network
Declaration
public void RemoveAt(int index)
Parameters
Type | Name | Description |
---|---|---|
int | index | The index of the element to remove. |
Remarks
This method checks for write permissions before removing the item.
ResetDirty()
Resets the dirty state and marks the variable as synced / clean
Declaration
public override void ResetDirty()
Overrides
WriteDelta(FastBufferWriter)
Writes the variable to the writer
Declaration
public override void WriteDelta(FastBufferWriter writer)
Parameters
Type | Name | Description |
---|---|---|
Fast |
writer | The stream to write the value to |
Overrides
WriteField(FastBufferWriter)
Writes the complete state of the variable to the writer
Declaration
public override void WriteField(FastBufferWriter writer)
Parameters
Type | Name | Description |
---|---|---|
Fast |
writer | The stream to write the state to |
Overrides
Events
OnListChanged
Creates A NetworkList/>
Declaration
public event NetworkList<T>.OnListChangedDelegate OnListChanged
Event Type
Type | Description |
---|---|
Network |