Photon Fusion 2.0.3

Classes | Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | Properties | List of all members
NetworkArray< T > Struct Template Reference

Fusion type for networking arrays. Maximum capacity is fixed, and is set with the CapacityAttribute.

More...

Inherits IEnumerable< T >, and INetworkArray.

Classes

struct  Enumerator
 Enumerator for NetworkArray. More...
 

Public Member Functions

void Clear ()
 Clears the array, setting all values to default. More...
 
void CopyFrom (List< T > source, int sourceOffset, int sourceCount)
 Copies a range of values from a supplied source list into the NetworkArray. More...
 
void CopyFrom (T[] source, int sourceOffset, int sourceCount)
 Copies a range of elements from a source array into the NetworkArray. More...
 
void CopyTo (List< T > list)
 Adds each value to the supplied List. This does not clear the list, so values will be appended to the existing list. More...
 
void CopyTo (NetworkArray< T > array)
 Copies values to the supplied array. More...
 
void CopyTo (T[] array, bool throwIfOverflow=true)
 Copies values to the supplied array. More...
 
Get (int index)
 Returns the array value at supplied index. More...
 
Enumerator GetEnumerator ()
 Returns an enumerator that iterates through the collection. More...
 
IEnumerator< T > IEnumerable< T >. GetEnumerator ()
 
IEnumerator IEnumerable. GetEnumerator ()
 
 NetworkArray (byte *array, int length, IElementReaderWriter< T > readerWriter)
 NetworkArray constructor. More...
 
Set (int index, T value)
 Sets the array value at the supplied index. More...
 
T[] ToArray ()
 Allocates a new array and copies values from this array. For a non-alloc alternative use CopyTo(List<T>). More...
 
string ToListString ()
 Returns the elements of this array as a string, with value separated by
characters. Specifically for use in the Unity inspector. This is private and only is found by NetworkBehaviourEditor using reflection, so do not rename this method. More...
 
NetworkArrayReadOnly< T > ToReadOnly ()
 Returns a NetworkArrayReadOnly view of this array. More...
 
override string ToString ()
 Returns a string that represents the current object. More...
 

Static Public Member Functions

static implicit operator NetworkArrayReadOnly< T > (NetworkArray< T > value)
 Returns a NetworkArrayReadOnly view of this array. More...
 

Public Attributes

byte * _array
 
int _length
 
IElementReaderWriter< T > _readerWriter
 

Static Public Attributes

static StringBuilder _stringBuilderCached
 

Properties

int Length [get]
 The fixed size of the array. More...
 
this[int index] [get, set]
 Indexer of array elements. More...
 
object INetworkArray. this[int index] [get, set]
 
- Properties inherited from INetworkArray
object this[int index] [get, set]
 Gets or sets the element at the specified index. More...
 

Detailed Description

Fusion type for networking arrays. Maximum capacity is fixed, and is set with the CapacityAttribute.

Typical Usage: [Networked, Capacity(4)]
NetworkArray<float> syncedArray => default;

Optional usage (for NetworkBehaviours ONLY - this is not legal in INetworkStructs): [Networked, Capacity(4)]
NetworkArray<int> syncedArray { get; } = MakeInitializer(new int[] { 1, 2, 3, 4 });

Usage for modifying data: array.Set(123); array[0] = 456;

Template Parameters
TT can be a primitive, or an INetworkStruct.

Constructor & Destructor Documentation

◆ NetworkArray()

NetworkArray ( byte *  array,
int  length,
IElementReaderWriter< T >  readerWriter 
)

NetworkArray constructor.

Member Function Documentation

◆ Clear()

void Clear ( )

Clears the array, setting all values to default.

◆ CopyFrom() [1/2]

void CopyFrom ( List< T >  source,
int  sourceOffset,
int  sourceCount 
)

Copies a range of values from a supplied source list into the NetworkArray.

Parameters
sourceThe source list from which to copy elements.
sourceOffsetThe zero-based index in the source list at which copying begins.
sourceCountThe number of elements to copy from the source list.
Exceptions
ArgumentNullExceptionThrown when the provided source list is null.
ArgumentExceptionThrown when the number of elements to copy is greater than the length of the NetworkArray.
ArgumentOutOfRangeExceptionThrown when the sum of sourceOffset and sourceCount is greater than the length of the source list.

◆ CopyFrom() [2/2]

void CopyFrom ( T[]  source,
int  sourceOffset,
int  sourceCount 
)

Copies a range of elements from a source array into the NetworkArray.

Parameters
sourceThe source array from which to copy elements. Must not be null.
sourceOffsetThe zero-based index in the source array at which copying begins.
sourceCountThe number of elements to copy from the source array.
Exceptions
ArgumentNullExceptionThrown when the provided source array is null.
ArgumentExceptionThrown when the number of elements to copy is greater than the length of the NetworkArray.
ArgumentOutOfRangeExceptionThrown when the sum of sourceOffset and sourceCount is greater than the length of the source array.

◆ CopyTo() [1/3]

void CopyTo ( List< T >  list)

Adds each value to the supplied List. This does not clear the list, so values will be appended to the existing list.

◆ CopyTo() [2/3]

void CopyTo ( NetworkArray< T >  array)

Copies values to the supplied array.

Parameters
arrayNetworkArray to copy to.
Exceptions
ArgumentExceptionThrown if the supplied array is smaller than this NetworkArray<T>.

◆ CopyTo() [3/3]

void CopyTo ( T[]  array,
bool  throwIfOverflow = true 
)

Copies values to the supplied array.

Parameters
arrayArray to copy to.
throwIfOverflowIf true, this method will throw an error if the supplied array is smaller than this NetworkArray<T>. If false, will only copy as many elements as the target array can hold.

◆ Get()

T Get ( int  index)

Returns the array value at supplied index.

◆ GetEnumerator()

Enumerator GetEnumerator ( )

Returns an enumerator that iterates through the collection.

◆ operator NetworkArrayReadOnly< T >()

static implicit operator NetworkArrayReadOnly< T > ( NetworkArray< T >  value)
static

Returns a NetworkArrayReadOnly view of this array.

Parameters
valueNetworkArray to convert.
Returns
NetworkArrayReadOnly view of this array.

◆ Set()

T Set ( int  index,
value 
)

Sets the array value at the supplied index.

◆ ToArray()

T [] ToArray ( )

Allocates a new array and copies values from this array. For a non-alloc alternative use CopyTo(List<T>).

◆ ToListString()

string ToListString ( )

Returns the elements of this array as a string, with value separated by
characters. Specifically for use in the Unity inspector. This is private and only is found by NetworkBehaviourEditor using reflection, so do not rename this method.

◆ ToReadOnly()

NetworkArrayReadOnly<T> ToReadOnly ( )

Returns a NetworkArrayReadOnly view of this array.

◆ ToString()

override string ToString ( )

Returns a string that represents the current object.

Property Documentation

◆ Length

int Length
get

The fixed size of the array.

◆ this[int index]

T this[int index]
getset

Indexer of array elements.