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
Syntax
public struct NetworkDriverStore
Fields
Capacity
The fixed capacity of the driver container.
Declaration
public const int Capacity = 3
Field Value
Type | Description |
---|---|
Int32 |
FirstDriverId
The first assigned uniqued identifier to each driver.
Declaration
public const int FirstDriverId = 1
Field Value
Type | Description |
---|---|
Int32 |
Properties
DriversCount
The number of registed drivers. Must be always less then the total driver Capacity.
Declaration
public readonly int DriversCount { get; }
Property Value
Type | Description |
---|---|
Int32 |
FirstDriver
The first driver id present in the store. Can be used to iterate over all registered drivers in a for loop.
Declaration
public readonly int FirstDriver { get; }
Property Value
Type | Description |
---|---|
Int32 |
Examples
for(int i= driverStore.FirstDriver; i < driverStore.LastDriver; ++i)
{
ref var instance = ref driverStore.GetDriverInstance(i);
....
}
IsAnyUsingSimulator
Return true if the driver store contains a driver that has a simulator pipeline.
Declaration
public readonly bool IsAnyUsingSimulator { get; }
Property Value
Type | Description |
---|---|
Boolean |
LastDriver
The last driver id present in the store. Can be used to iterate over all registered drivers in a for loop.
Declaration
public readonly int LastDriver { get; }
Property Value
Type | Description |
---|---|
Int32 |
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 NetworkStreamConnection connection.
Declaration
public void Disconnect(NetworkStreamConnection connection)
Parameters
Type | Name | Description |
---|---|---|
NetworkStreamConnection | connection |
Exceptions
Type | Condition |
---|---|
InvalidOperationException |
Dispose()
Dispose all the registered drivers instances and their allocated resources.
Declaration
public void Dispose()
ForEachDriver(NetworkDriverStore.DriverVisitor)
Invoke the delegate on all registered drivers.
Declaration
public void ForEachDriver(NetworkDriverStore.DriverVisitor visitor)
Parameters
Type | Name | Description |
---|---|---|
NetworkDriverStore.DriverVisitor | visitor |
GetConnectionState(NetworkStreamConnection)
Return the state of the NetworkStreamConnection connection.
Declaration
public NetworkConnection.State GetConnectionState(NetworkStreamConnection connection)
Parameters
Type | Name | Description |
---|---|---|
NetworkStreamConnection | connection | A client or server connection |
Returns
Type | Description |
---|---|
NetworkConnection.State |
Exceptions
Type | Condition |
---|---|
InvalidOperationException | Throw an exception if the driver associated to the connection is not found |
GetDriverInstance(Int32)
Return the NetworkDriverStore.NetworkDriverInstance instance with the given driverId.
Declaration
public readonly NetworkDriverStore.NetworkDriverInstance GetDriverInstance(int driverId)
Parameters
Type | Name | Description |
---|---|---|
Int32 | driverId | the id of the driver. Should be always greater or equals than FirstDriverId |
Returns
Type | Description |
---|---|
NetworkDriverStore.NetworkDriverInstance | The NetworkDriverStore.NetworkDriverInstance at for the given id. |
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 |
---|---|
InvalidOperationException | Throw an exception if a driver is not found |
GetDriverType(Int32)
Return the transport type used by the registered driver.
Declaration
public TransportType GetDriverType(int driverId)
Parameters
Type | Name | Description |
---|---|---|
Int32 | driverId | the id of the driver. Should be always greater or equals than FirstDriverId |
Returns
Type | Description |
---|---|
TransportType | The TransportType of driver |
Exceptions
Type | Condition |
---|---|
InvalidOperationException | Throw an exception if a driver is not found |
GetNetworkDriver(Int32)
Return the NetworkDriver with the given driver id.
Declaration
public readonly NetworkDriver GetNetworkDriver(int driverId)
Parameters
Type | Name | Description |
---|---|---|
Int32 | driverId | the id of the driver. Should be always greater or equals than FirstDriverId |
Returns
Type | Description |
---|---|
NetworkDriver | The NetworkDriverStore.NetworkDriverInstance at for the given id. |
Exceptions
Type | Condition |
---|---|
InvalidOperationException | Throw an exception if a driver is not found |
RegisterDriver(TransportType, in NetworkDriverStore.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 |
---|---|---|
TransportType | driverType | |
NetworkDriverStore.NetworkDriverInstance | driverInstance |
Returns
Type | Description |
---|---|
Int32 | The assigned driver id |
Exceptions
Type | Condition |
---|---|
InvalidOperationException |
ScheduleFlushSendAllDrivers(JobHandle)
Invoke ScheduleFlushSend(JobHandle) on all registered drivers in the store
Declaration
public JobHandle ScheduleFlushSendAllDrivers(JobHandle dependency)
Parameters
Type | Name | Description |
---|---|---|
JobHandle | dependency | A job handle whom all flush jobs depend upon |
Returns
Type | Description |
---|---|
JobHandle | The combined handle of all the scheduled jobs. |