Struct NetworkDriverStore
Store and manage an array of NetworkDriver. The capacity is fixed to Capacity. The driver registration should start by calling BeginDriverRegistration() and terminate with EndDriverRegistration(). The store also provide some accessor and utlilty methods.
Inherited Members
Namespace: Unity.NetCode
Assembly: Unity.NetCode.dll
Syntax
public struct NetworkDriverStore
Fields
Capacity
The fixed capacity of the driver container.
Declaration
public const int Capacity = 3
Field Value
Type | Description |
---|---|
int |
FirstDriverId
The first assigned uniqued identifier to each driver.
Declaration
public const int FirstDriverId = 1
Field Value
Type | Description |
---|---|
int |
Properties
DriversCount
The number of registered drivers. Must be always less then the total driver Capacity.
Declaration
public int DriversCount { get; }
Property Value
Type | Description |
---|---|
int |
FirstDriver
The first driver id present in the store. Can be used to iterate over all registered drivers in a for loop.
Declaration
public int FirstDriver { get; }
Property Value
Type | Description |
---|---|
int |
Examples
for(int i= driverStore.FirstDriver; i < driverStore.LastDriver; ++i)
{
ref var instance = ref driverStore.GetDriverInstance(i);
....
}
HasListeningInterfaces
Return true if there is at least one driver listening for incoming connections.
Declaration
public bool HasListeningInterfaces { get; }
Property Value
Type | Description |
---|---|
bool |
IsAnyUsingSimulator
Return true if the driver store contains a driver that has a simulator pipeline.
Declaration
public bool IsAnyUsingSimulator { get; }
Property Value
Type | Description |
---|---|
bool |
IsCreated
Denote if the store has at least one driver registered
Declaration
public bool IsCreated { get; }
Property Value
Type | Description |
---|---|
bool |
LastDriver
The last driver id present in the store. Can be used to iterate over all registered drivers in a for loop.
Declaration
public int LastDriver { get; }
Property Value
Type | Description |
---|---|
int |
Examples
for(int i= driverStore.FirstDriver; i < driverStore.LastDriver; ++i)
{
ref var instance = ref driverStore.GetDriverInstance(i).
....
}
Methods
Disconnect(NetworkStreamConnection)
Utility method to disconnect the Network
Declaration
public void Disconnect(NetworkStreamConnection connection)
Parameters
Type | Name | Description |
---|---|---|
Network |
connection |
Exceptions
Type | Condition |
---|---|
Invalid |
Throws if driverId is out of range. |
Dispose()
Dispose all the registered drivers instances and their allocated resources.
Declaration
public void Dispose()
ForEachDriver(DriverVisitor)
Invoke the delegate on all registered drivers.
Declaration
[Obsolete("The ForEachDriver has been deprecated. Please always iterate over the driver using a for loop, using the FirstDriver and LastDriver ids instead.")]
public void ForEachDriver(NetworkDriverStore.DriverVisitor visitor)
Parameters
Type | Name | Description |
---|---|---|
Network |
visitor | Visitor to invoke with the driver instance and ID |
GetConnectionState(NetworkStreamConnection)
Return the state of the Network
Declaration
public NetworkConnection.State GetConnectionState(NetworkStreamConnection connection)
Parameters
Type | Name | Description |
---|---|---|
Network |
connection | A client or server connection |
Returns
Type | Description |
---|---|
Network |
The state of the Network |
Exceptions
Type | Condition |
---|---|
Invalid |
Throw an exception if the driver associated to the connection is not found |
GetDriverInstance(int)
Return the Network
Declaration
[Obsolete("Prefer GetDriverInstanceRW or GetDriverInstanceRO to avoid copying.", false)]
public readonly ref NetworkDriverStore.NetworkDriverInstance GetDriverInstance(int driverId)
Parameters
Type | Name | Description |
---|---|---|
int | driverId | The index of the target driver. See First |
Returns
Type | Description |
---|---|
Network |
The Network |
Remarks
The method return a copy of the driver instance not a reference. While this is suitable for almost all the use cases, since the driver is trivially copyable, be aware that calling some of the Driver class methods, like ScheduleUpdate, that update internal driver data (that aren't suited to be copied around) may not work as expected.
Exceptions
Type | Condition |
---|---|
Invalid |
Throws if driverId is out of range. |
GetDriverInstanceRO(int)
Return a reference to the Network
Declaration
public ref readonly NetworkDriverStore.NetworkDriverInstance GetDriverInstanceRO(int driverId)
Parameters
Type | Name | Description |
---|---|---|
int | driverId | The index of the target driver. See First |
Returns
Type | Description |
---|---|
Network |
The Network |
Exceptions
Type | Condition |
---|---|
Invalid |
Throws if driverId is out of range. |
GetDriverInstanceRW(int)
Return a reference to the Network
Declaration
public ref NetworkDriverStore.NetworkDriverInstance GetDriverInstanceRW(int driverId)
Parameters
Type | Name | Description |
---|---|---|
int | driverId | The index of the target driver. See First |
Returns
Type | Description |
---|---|
Network |
The Network |
Exceptions
Type | Condition |
---|---|
Invalid |
Throws if driverId is out of range. |
GetDriverRO(int)
Retrieve a Read-Only reference to the Unity.
Declaration
public ref readonly NetworkDriver GetDriverRO(int driverId)
Parameters
Type | Name | Description |
---|---|---|
int | driverId | The index of the target driver. See First |
Returns
Type | Description |
---|---|
Network |
The Network |
Exceptions
Type | Condition |
---|---|
Invalid |
Throws if driverId is out of range. |
GetDriverRW(int)
Retrieve a ReadWrite reference to the Unity.
Declaration
public ref NetworkDriver GetDriverRW(int driverId)
Parameters
Type | Name | Description |
---|---|---|
int | driverId | The index of the target driver. See First |
Returns
Type | Description |
---|---|
Network |
The Network |
Exceptions
Type | Condition |
---|---|
Invalid |
Throws if driverId is out of range. |
GetDriverType(int)
Return the transport type used by the registered driver.
Declaration
public TransportType GetDriverType(int driverId)
Parameters
Type | Name | Description |
---|---|---|
int | driverId | The index of the target driver. See First |
Returns
Type | Description |
---|---|
Transport |
The Network |
Exceptions
Type | Condition |
---|---|
Invalid |
Throws if driverId is out of range. |
GetNetworkDriver(int)
Return the Unity.
Declaration
[Obsolete("Prefer GetDriverRW or GetDriverRO to avoid copying.", false)]
public readonly NetworkDriver GetNetworkDriver(int driverId)
Parameters
Type | Name | Description |
---|---|---|
int | driverId | The index of the target driver. See First |
Returns
Type | Description |
---|---|
Network |
The Network |
Exceptions
Type | Condition |
---|---|
Invalid |
Throws if driverId is out of range. |
RegisterDriver(TransportType, in NetworkDriverInstance)
Add a new driver to the store. Throw exception if all drivers slot are already occupied or the driver is not created/valid
Declaration
public int RegisterDriver(TransportType driverType, in NetworkDriverStore.NetworkDriverInstance driverInstance)
Parameters
Type | Name | Description |
---|---|---|
Transport |
driverType | Driver type |
Network |
driverInstance | Instance of driver |
Returns
Type | Description |
---|---|
int | The assigned driver id |
Exceptions
Type | Condition |
---|---|
Invalid |
Thrown if cannot register or the NetworkDriverStore is finalized. |
ScheduleFlushSendAllDrivers(JobHandle)
Invoke Schedule
Declaration
public JobHandle ScheduleFlushSendAllDrivers(JobHandle dependency)
Parameters
Type | Name | Description |
---|---|---|
Job |
dependency | A job handle whom all flush jobs depend upon |
Returns
Type | Description |
---|---|
Job |
The combined handle of all the scheduled jobs. |