-
Notifications
You must be signed in to change notification settings - Fork 459
Expand file tree
/
Copy pathINetworkStreamDriverConstructor.cs
More file actions
81 lines (80 loc) · 4.32 KB
/
INetworkStreamDriverConstructor.cs
File metadata and controls
81 lines (80 loc) · 4.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
using Unity.Networking.Transport;
namespace Unity.Netcode.Transports.UTP
{
/// <summary>
/// <para>
/// This interface allows one to override the creation of the <see cref="NetworkDriver"/> object
/// that will be used under the hood by <see cref="UnityTransport"/>. This can be useful when
/// implementing a custom <see cref="INetworkInterface"/> or to add custom pipeline stages to
/// the default pipelines.
/// </para>
/// <para>
/// To use a custom driver constructor, set <see cref="UnityTransport.s_DriverConstructor"/> to
/// an instance of an implementation of this interface. This must be done before calling
/// <see cref="UnityTransport.StartClient"/> or <see cref="UnityTransport.StartServer"/>.
/// </para>
/// </summary>
/// <example>
/// <para>
/// 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.
/// </para>
/// <code>
/// 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);
///
/// driver.RegisterPipelineStage(new NetworkMetricsPipelineStage());
///
/// transport.GetDefaultPipelineConfigurations(
/// out var unreliableFragmentedPipelineStages,
/// out var unreliableSequencedFragmentedPipelineStages,
/// out var reliableSequencedPipelineStages);
///
/// unreliableFragmentedPipeline = driver.CreatePipeline(unreliableFragmentedPipelineStages);
/// unreliableSequencedFragmentedPipeline = driver.CreatePipeline(unreliableSequencedFragmentedPipelineStages);
/// reliableSequencedPipeline = driver.CreatePipeline(reliableSequencedPipelineStages);
/// }
/// }
/// </code>
/// </example>
public interface INetworkStreamDriverConstructor
{
/// <summary>
/// Creates the <see cref="NetworkDriver"/> instance to be used by the transport.
/// </summary>
/// <param name="transport">The transport for which the driver is created.</param>
/// <param name="driver">The newly-created <see cref="NetworkDriver"/>.</param>
/// <param name="unreliableFragmentedPipeline">
/// The driver's pipeline on which to send unreliable traffic. This pipeline must also
/// support fragmentation (payloads larger than the MTU).
/// </param>
/// <param name="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).
/// </param>
/// <param name="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 (<see cref="UnityTransport"/> will handle that).
/// </param>
public void CreateDriver(
UnityTransport transport,
out NetworkDriver driver,
out NetworkPipeline unreliableFragmentedPipeline,
out NetworkPipeline unreliableSequencedFragmentedPipeline,
out NetworkPipeline reliableSequencedPipeline);
}
}