Skip to content

feat: Make INetworkStreamDriverConstructor useful #3501

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: develop-2.0.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions com.unity.netcode.gameobjects/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Additional documentation and release notes are available at [Multiplayer Documen

### Added

- Added methods `GetDefaultNetworkSettings` and `GetDefaultPipelineConfigurations` to `UnityTransport`. These can be used to retrieve the default settings and pipeline stages that are used by `UnityTransport`. This is useful when providing a custom driver constructor through `UnityTransport.s_DriverConstructor`, since it allows reusing or tuning the existing configuration instead of trying to recreate it. This means a transport with a custom driver can now easily benefit from most of the features of `UnityTransport`, like integration with the Network Simulator and Network Profiler from the multiplayer tools package. (#3501)

### Fixed

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
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);
///
/// 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>
void CreateDriver(
UnityTransport transport,
out NetworkDriver driver,
out NetworkPipeline unreliableFragmentedPipeline,
out NetworkPipeline unreliableSequencedFragmentedPipeline,
out NetworkPipeline reliableSequencedPipeline);
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading