Interface INetworkStreamDriverConstructor
This interface allows one to override the creation of the Unity.Networking.Transport.NetworkDriver object that will be used under the hood by UnityTransport. This can be useful when implementing a custom Unity.Networking.Transport.INetworkInterface or to add custom pipeline stages to the default pipelines.
To use a custom driver constructor, set s_DriverConstructor to an instance of an implementation of this interface. This must be done before calling StartClient() or StartServer().
Namespace: Unity.Netcode.Transports.UTP
Assembly: Unity.Netcode.Runtime.dll
Syntax
public interface INetworkStreamDriverConstructor
Examples
This example implements a custom driver constructor that uses the IPC network interface from the Unity Transport package. This network interface is used for intra-process communications which can be useful for implementing a single-player version of a game. Since the example is also preserving all the default settings and pipelines, you'd also benefit from all the existing features of the transport, like integration with the Network Profiler.
public class IPCDriverConstructor : INetworkStreamDriverConstructor
{
public void CreateDriver(
UnityTransport transport,
out NetworkDriver driver,
out NetworkPipeline unreliableFragmentedPipeline,
out NetworkPipeline unreliableSequencedFragmentedPipeline,
out NetworkPipeline reliableSequencedPipeline)
{
var settings = transport.GetDefaultNetworkSettings();
driver = NetworkDriver.Create(new IPCNetworkInterface(), settings);
transport.GetDefaultPipelineConfigurations(
out var unreliableFragmentedPipelineStages,
out var unreliableSequencedFragmentedPipelineStages,
out var reliableSequencedPipelineStages);
unreliableFragmentedPipeline = driver.CreatePipeline(unreliableFragmentedPipelineStages);
unreliableSequencedFragmentedPipeline = driver.CreatePipeline(unreliableSequencedFragmentedPipelineStages);
reliableSequencedPipeline = driver.CreatePipeline(reliableSequencedPipelineStages);
}
}
Methods
CreateDriver(UnityTransport, out NetworkDriver, out NetworkPipeline, out NetworkPipeline, out NetworkPipeline)
Creates the Unity.Networking.Transport.NetworkDriver instance to be used by the transport.
Declaration
void CreateDriver(UnityTransport transport, out NetworkDriver driver, out NetworkPipeline unreliableFragmentedPipeline, out NetworkPipeline unreliableSequencedFragmentedPipeline, out NetworkPipeline reliableSequencedPipeline)
Parameters
Type | Name | Description |
---|---|---|
UnityTransport | transport | The transport for which the driver is created. |
NetworkDriver | driver | The newly-created Unity.Networking.Transport.NetworkDriver. |
NetworkPipeline | unreliableFragmentedPipeline | The driver's pipeline on which to send unreliable traffic. This pipeline must also support fragmentation (payloads larger than the MTU). |
NetworkPipeline | unreliableSequencedFragmentedPipeline | The driver's pipeline on which to send unreliable but sequenced traffic. Traffic sent on this pipeline must be delivered in the right order, although packet loss is okay. This pipeline must also support fragmentation (payloads larger than the MTU). |
NetworkPipeline | reliableSequencedPipeline | The driver's pipeline on which to send reliable traffic. This pipeline must ensure that all of its traffic is delivered, and in the correct order too. There is no need for that pipeline to support fragmentation (UnityTransport will handle that). |