Photon Fusion 2.0.4

Classes | Static Public Member Functions | Static Public Attributes | List of all members
NetworkBehaviourUtils Class Reference

This static class provides utility methods for working with NetworkBehaviour objects. More...

Classes

struct  ArrayInitializer
 A utility structure for initializing NetworkArray and NetworkLinkedList with inline initialization. More...
 
struct  DictionaryInitializer
 A utility structure for initializing NetworkDictionary with inline initialization. More...
 
struct  MetaData
 This structure holds metadata for a NetworkBehaviour object. More...
 

Static Public Member Functions

static T[] CloneArray< T > (T[] array)
 Creates a new array that is a clone of the specified array. More...
 
static void CopyFromNetworkArray< T > (NetworkArray< T > networkArray, ref T[] dstArray)
 Copies the values from a NetworkArray to a destination array. More...
 
static void CopyFromNetworkDictionary< D, K, V > (NetworkDictionary< K, V > networkDictionary, ref D dictionary)
 Copies the values from a NetworkDictionary to a destination dictionary. More...
 
static void CopyFromNetworkList< T > (NetworkLinkedList< T > networkList, ref T[] dstArray)
 Copies the values from a NetworkLinkedList to a destination array. More...
 
static MetaData GetMetaData (Type type)
 Retrieves the metadata for a given type. More...
 
static int GetRpcStaticIndexOrThrow (string key)
 Retrieves the index of a static RPC (Remote Procedure Call) based on its key. More...
 
static int GetStaticWordCount (Type type)
 Retrieves the static word count for a given type. If the word count for the type has not been computed yet, it is computed and stored. More...
 
static int GetWordCount (NetworkBehaviour behaviour)
 Retrieves the word count for a given NetworkBehaviour. If the NetworkBehaviour has a dynamic word count, it is returned. Otherwise, the static word count for the type of the NetworkBehaviour is returned. More...
 
static bool HasStaticWordCount (Type type)
 Checks if a given type has a static word count. A type has a static word count if it is a subclass of NetworkBehaviour and its word count is non-negative. More...
 
static void InitializeNetworkArray< T > (NetworkArray< T > networkArray, T[] sourceArray, string name)
 Initializes a NetworkArray with the values from a source array. More...
 
static void InitializeNetworkDictionary< D, K, V > (NetworkDictionary< K, V > networkDictionary, D dictionary, string name)
 Initializes a NetworkDictionary with the values from a source dictionary. More...
 
static void InitializeNetworkList< T > (NetworkLinkedList< T > networkList, T[] sourceArray, string name)
 Initializes a NetworkLinkedList with the values from a source array. More...
 
static void InternalOnDestroy (SimulationBehaviour obj)
 This method is not meant to be called directly. Calls are injected by the Weaver. More...
 
static void InternalOnDisable (SimulationBehaviour obj)
 This method is not meant to be called directly. Calls are injected by the Weaver. More...
 
static void InternalOnEnable (SimulationBehaviour obj)
 This method is not meant to be called directly. Calls are injected by the Weaver. More...
 
static SerializableDictionary< K, V > MakeSerializableDictionary< K, V > (Dictionary< K, V > dictionary)
 Wraps a Dictionary in a SerializableDictionary. More...
 
static void NotifyLocalSimulationNotAllowedToSendRpc (string rpc, NetworkObject obj, int sources)
 Logs an error message indicating that a local simulation is not allowed to send a specific RPC. More...
 
static void NotifyLocalTargetedRpcCulled (PlayerRef player, string methodName)
 Logs a warning message indicating that a local targeted RPC was culled. More...
 
static void NotifyNetworkUnwrapFailed< T > (T wrapper, Type valueType)
 Logs a warning message indicating that a network unwrap operation failed. More...
 
static void NotifyNetworkWrapFailed< T > (T value)
 Logs a warning message indicating that a network wrap operation failed. More...
 
static void NotifyNetworkWrapFailed< T > (T value, Type wrapperType)
 Logs a warning message indicating that a network wrap operation failed for a specific wrapper type. More...
 
static void NotifyRpcPayloadSizeExceeded (string rpc, int size)
 Logs an error message indicating that the target of a Remote Procedure Call (RPC) payload is too large. More...
 
static void NotifyRpcTargetUnreachable (PlayerRef player, string rpc)
 Logs an error message indicating that the target of a Remote Procedure Call (RPC) is not reachable. More...
 
static void RegisterMetaData (Type type)
 Registers the metadata for a given type. This method checks if the type has an override for the "ReplicateTo" method and stores this information in the metadata. If the metadata for the type already exists, this method does nothing. More...
 
static void RegisterRpcInvokeDelegates (Type type)
 Registers the RPC (Remote Procedure Call) invoke delegates for a given type. This method is only available when the FUSION_UNITY compilation symbol is defined. More...
 
static bool ShouldRegisterRpcInvokeDelegates (Type type)
 Determines whether the RPC (Remote Procedure Call) invoke delegates should be registered for a given type. More...
 
static void ThrowIfBehaviourNotInitialized (NetworkBehaviour behaviour)
 Checks if the NetworkBehaviour object is initialized and throws an exception if it is not. More...
 
static bool TryGetRpcInvokeDelegateArray (Type type, out RpcInvokeData[] delegates)
 Tries to get the RPC (Remote Procedure Call) invoke delegate array for a given type. More...
 
static bool TryGetRpcStaticInvokeDelegate (int index, out RpcStaticInvokeDelegate del)
 Tries to get the static RPC (Remote Procedure Call) invoke delegate based on its index. More...
 

Static Public Attributes

static bool InvokeRpc = false
 A static field that determines whether to invoke RPC (Remote Procedure Call). When set to true, RPCs are invoked. When set to false, RPCs are not invoked. Default value is false. More...
 

Detailed Description

This static class provides utility methods for working with NetworkBehaviour objects.

Member Function Documentation

◆ CloneArray< T >()

static T [] CloneArray< T > ( T[]  array)
static

Creates a new array that is a clone of the specified array.

Template Parameters
TThe type of the elements in the array.
Parameters
arrayThe array to clone.
Returns
A new array that is a clone of the specified array. If the specified array is null, an empty array is returned.

◆ CopyFromNetworkArray< T >()

static void CopyFromNetworkArray< T > ( NetworkArray< T >  networkArray,
ref T[]  dstArray 
)
static

Copies the values from a NetworkArray to a destination array.

Template Parameters
TThe type of the elements in the NetworkArray and destination array.
Parameters
networkArrayThe NetworkArray from which to copy the values.
dstArrayThe destination array to which to copy the values.

If the length of the destination array is not equal to the length of the NetworkArray, a new array of the correct length is created and assigned to the destination array.

Type Constraints
T :unmanaged 

◆ CopyFromNetworkDictionary< D, K, V >()

static void CopyFromNetworkDictionary< D, K, V > ( NetworkDictionary< K, V >  networkDictionary,
ref D  dictionary 
)
static

Copies the values from a NetworkDictionary to a destination dictionary.

Template Parameters
DThe type of the destination dictionary. Must implement IDictionary{K, V} and have a parameterless constructor.
KThe type of the keys in the NetworkDictionary and destination dictionary. Must be unmanaged.
VThe type of the values in the NetworkDictionary and destination dictionary. Must be unmanaged.
Parameters
networkDictionaryThe NetworkDictionary from which to copy the values.
dictionaryThe destination dictionary to which to copy the values. If the destination dictionary is null, a new dictionary of type D is created.
Type Constraints
D :IDictionary 
D :K 
D :V 
D :new() 
K :unmanaged 
V :unmanaged 

◆ CopyFromNetworkList< T >()

static void CopyFromNetworkList< T > ( NetworkLinkedList< T >  networkList,
ref T[]  dstArray 
)
static

Copies the values from a NetworkLinkedList to a destination array.

Template Parameters
TThe type of the elements in the NetworkLinkedList and destination array.
Parameters
networkListThe NetworkLinkedList from which to copy the values.
dstArrayThe destination array to which to copy the values. If the length of the destination array is not equal to the count of the NetworkLinkedList, a new array of the correct length is created and assigned to the destination array.
Type Constraints
T :unmanaged 

◆ GetMetaData()

static MetaData GetMetaData ( Type  type)
static

Retrieves the metadata for a given type.

Parameters
typeThe type for which to retrieve the metadata.
Returns
The metadata for the given type if it exists; otherwise, the default value.

◆ GetRpcStaticIndexOrThrow()

static int GetRpcStaticIndexOrThrow ( string  key)
static

Retrieves the index of a static RPC (Remote Procedure Call) based on its key.

Parameters
keyThe key of the static RPC.
Returns
The index of the static RPC if it exists.
Exceptions
System.ArgumentOutOfRangeExceptionThrown when the static RPC does not exist.

◆ GetStaticWordCount()

static int GetStaticWordCount ( Type  type)
static

Retrieves the static word count for a given type. If the word count for the type has not been computed yet, it is computed and stored.

Parameters
typeThe type for which to retrieve the static word count.
Returns
The static word count for the given type.
Exceptions
System.ArgumentExceptionThrown when the provided type is not a subclass of NetworkBehaviour.
System.InvalidOperationExceptionThrown when the provided type does not have a weaved attribute or its word count is negative.

◆ GetWordCount()

static int GetWordCount ( NetworkBehaviour  behaviour)
static

Retrieves the word count for a given NetworkBehaviour. If the NetworkBehaviour has a dynamic word count, it is returned. Otherwise, the static word count for the type of the NetworkBehaviour is returned.

Parameters
behaviourThe NetworkBehaviour for which to retrieve the word count.
Returns
The word count for the given NetworkBehaviour.
Exceptions
System.InvalidOperationExceptionThrown when the dynamic word count or the static word count is negative.

◆ HasStaticWordCount()

static bool HasStaticWordCount ( Type  type)
static

Checks if a given type has a static word count. A type has a static word count if it is a subclass of NetworkBehaviour and its word count is non-negative.

Parameters
typeThe type to check.
Returns
True if the type has a static word count, false otherwise.
Exceptions
System.ArgumentExceptionThrown when the provided type is not a subclass of NetworkBehaviour.
System.InvalidOperationExceptionThrown when the provided type does not have a weaved attribute.

◆ InitializeNetworkArray< T >()

static void InitializeNetworkArray< T > ( NetworkArray< T >  networkArray,
T[]  sourceArray,
string  name 
)
static

Initializes a NetworkArray with the values from a source array.

Template Parameters
TThe type of the elements in the NetworkArray and source array.
Parameters
networkArrayThe NetworkArray to initialize.
sourceArrayThe source array from which to copy the values.
nameThe name of the NetworkArray for logging purposes.

If the length of the source array is greater than the length of the NetworkArray, a warning is logged and only the first elements up to the length of the NetworkArray are copied.

Type Constraints
T :unmanaged 

◆ InitializeNetworkDictionary< D, K, V >()

static void InitializeNetworkDictionary< D, K, V > ( NetworkDictionary< K, V >  networkDictionary,
dictionary,
string  name 
)
static

Initializes a NetworkDictionary with the values from a source dictionary.

Template Parameters
DThe type of the source dictionary. Must implement IDictionary{K, V}.
KThe type of the keys in the NetworkDictionary and source dictionary. Must be unmanaged.
VThe type of the values in the NetworkDictionary and source dictionary. Must be unmanaged.
Parameters
networkDictionaryThe NetworkDictionary to initialize.
dictionaryThe source dictionary from which to copy the values.
nameThe name of the NetworkDictionary for logging purposes.

If the count of the source dictionary is greater than the capacity of the NetworkDictionary, a warning is logged and only the first elements up to the capacity of the NetworkDictionary are copied.

Type Constraints
D :IDictionary 
D :K 
D :V 
K :unmanaged 
V :unmanaged 

◆ InitializeNetworkList< T >()

static void InitializeNetworkList< T > ( NetworkLinkedList< T >  networkList,
T[]  sourceArray,
string  name 
)
static

Initializes a NetworkLinkedList with the values from a source array.

Template Parameters
TThe type of the elements in the NetworkLinkedList and source array. Must be unmanaged.
Parameters
networkListThe NetworkLinkedList to initialize.
sourceArrayThe source array from which to copy the values.
nameThe name of the NetworkLinkedList for logging purposes.

If the length of the source array is greater than the capacity of the NetworkLinkedList, a warning is logged and only the first elements up to the capacity of the NetworkLinkedList are copied.

Type Constraints
T :unmanaged 

◆ InternalOnDestroy()

static void InternalOnDestroy ( SimulationBehaviour  obj)
static

This method is not meant to be called directly. Calls are injected by the Weaver.

Parameters
objSimulationBehaviour object.

◆ InternalOnDisable()

static void InternalOnDisable ( SimulationBehaviour  obj)
static

This method is not meant to be called directly. Calls are injected by the Weaver.

Parameters
objSimulationBehaviour object.

◆ InternalOnEnable()

static void InternalOnEnable ( SimulationBehaviour  obj)
static

This method is not meant to be called directly. Calls are injected by the Weaver.

Parameters
objSimulationBehaviour object.

◆ MakeSerializableDictionary< K, V >()

static SerializableDictionary<K, V> MakeSerializableDictionary< K, V > ( Dictionary< K, V >  dictionary)
static

Wraps a Dictionary in a SerializableDictionary.

Template Parameters
KThe type of the keys in the dictionary. Must be unmanaged.
VThe type of the values in the dictionary. Must be unmanaged.
Parameters
dictionaryThe dictionary to wrap.
Returns
A SerializableDictionary that wraps the specified dictionary.
Type Constraints
K :unmanaged 
V :unmanaged 

◆ NotifyLocalSimulationNotAllowedToSendRpc()

static void NotifyLocalSimulationNotAllowedToSendRpc ( string  rpc,
NetworkObject  obj,
int  sources 
)
static

Logs an error message indicating that a local simulation is not allowed to send a specific RPC.

Parameters
rpcThe name of the RPC that was attempted.
objThe network object on which the RPC was attempted.
sourcesThe sources from which the RPC was attempted.

◆ NotifyLocalTargetedRpcCulled()

static void NotifyLocalTargetedRpcCulled ( PlayerRef  player,
string  methodName 
)
static

Logs a warning message indicating that a local targeted RPC was culled.

Parameters
playerThe player reference for which the RPC was culled.
methodNameThe name of the method that was culled.

◆ NotifyNetworkUnwrapFailed< T >()

static void NotifyNetworkUnwrapFailed< T > ( wrapper,
Type  valueType 
)
static

Logs a warning message indicating that a network unwrap operation failed.

Template Parameters
TThe type of the wrapper that failed to be unwrapped.
Parameters
wrapperThe wrapper that failed to be unwrapped.
valueTypeThe type that was attempted to be obtained from the unwrap operation.

◆ NotifyNetworkWrapFailed< T >() [1/2]

static void NotifyNetworkWrapFailed< T > ( value)
static

Logs a warning message indicating that a network wrap operation failed.

Template Parameters
TThe type of the value that failed to be wrapped.
Parameters
valueThe value that failed to be wrapped.

◆ NotifyNetworkWrapFailed< T >() [2/2]

static void NotifyNetworkWrapFailed< T > ( value,
Type  wrapperType 
)
static

Logs a warning message indicating that a network wrap operation failed for a specific wrapper type.

Template Parameters
TThe type of the value that failed to be wrapped.
Parameters
valueThe value that failed to be wrapped.
wrapperTypeThe type that was attempted to be used as a wrapper.

◆ NotifyRpcPayloadSizeExceeded()

static void NotifyRpcPayloadSizeExceeded ( string  rpc,
int  size 
)
static

Logs an error message indicating that the target of a Remote Procedure Call (RPC) payload is too large.

Parameters
sizeSize of the payload.
rpcThe name of the RPC that was attempted.

◆ NotifyRpcTargetUnreachable()

static void NotifyRpcTargetUnreachable ( PlayerRef  player,
string  rpc 
)
static

Logs an error message indicating that the target of a Remote Procedure Call (RPC) is not reachable.

Parameters
playerThe player reference that is not reachable.
rpcThe name of the RPC that was attempted.

◆ RegisterMetaData()

static void RegisterMetaData ( Type  type)
static

Registers the metadata for a given type. This method checks if the type has an override for the "ReplicateTo" method and stores this information in the metadata. If the metadata for the type already exists, this method does nothing.

Parameters
typeThe type for which to register the metadata.

◆ RegisterRpcInvokeDelegates()

static void RegisterRpcInvokeDelegates ( Type  type)
static

Registers the RPC (Remote Procedure Call) invoke delegates for a given type. This method is only available when the FUSION_UNITY compilation symbol is defined.

Parameters
typeThe type for which to register the RPC invoke delegates.
Exceptions
System.ArgumentExceptionThrown when the provided type is not a subclass of NetworkBehaviour.
System.InvalidOperationExceptionThrown when the provided type does not have a weaved attribute or its word count is negative.

◆ ShouldRegisterRpcInvokeDelegates()

static bool ShouldRegisterRpcInvokeDelegates ( Type  type)
static

Determines whether the RPC (Remote Procedure Call) invoke delegates should be registered for a given type.

Parameters
typeThe type for which to check the registration of RPC invoke delegates.
Returns
True if the RPC invoke delegates should be registered for the type, false otherwise.

◆ ThrowIfBehaviourNotInitialized()

static void ThrowIfBehaviourNotInitialized ( NetworkBehaviour  behaviour)
static

Checks if the NetworkBehaviour object is initialized and throws an exception if it is not.

Parameters
behaviourThe NetworkBehaviour object to check.
Exceptions
System.InvalidOperationExceptionThrown when the NetworkBehaviour object is not initialized.

◆ TryGetRpcInvokeDelegateArray()

static bool TryGetRpcInvokeDelegateArray ( Type  type,
out RpcInvokeData[]  delegates 
)
static

Tries to get the RPC (Remote Procedure Call) invoke delegate array for a given type.

Parameters
typeThe type for which to get the RPC invoke delegate array.
delegatesWhen this method returns, contains the RPC invoke delegate array if the type has one; otherwise, null.
Returns
true if the type has an RPC invoke delegate array; otherwise, false.

◆ TryGetRpcStaticInvokeDelegate()

static bool TryGetRpcStaticInvokeDelegate ( int  index,
out RpcStaticInvokeDelegate  del 
)
static

Tries to get the static RPC (Remote Procedure Call) invoke delegate based on its index.

Parameters
indexThe index of the static RPC.
delWhen this method returns, contains the static RPC invoke delegate if it exists; otherwise, default.
Returns
True if the static RPC invoke delegate exists; otherwise, false.

Member Data Documentation

◆ InvokeRpc

bool InvokeRpc = false
static

A static field that determines whether to invoke RPC (Remote Procedure Call). When set to true, RPCs are invoked. When set to false, RPCs are not invoked. Default value is false.