From 38a4ca27f48d496c3592d1f8a25d071d4a36c9d5 Mon Sep 17 00:00:00 2001 From: Paul Pacheco Date: Fri, 28 Sep 2018 08:19:37 -0500 Subject: [PATCH] Initialize transport in network manager (#48) --- Mirror/Runtime/NetworkManager.cs | 8 ++++++++ Mirror/Runtime/Transport/Transport.cs | 6 ++++-- Mirror/Tests/NetworkWriterTest.cs | 1 + 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/Mirror/Runtime/NetworkManager.cs b/Mirror/Runtime/NetworkManager.cs index 36bd6797c..f9e8bf9b7 100644 --- a/Mirror/Runtime/NetworkManager.cs +++ b/Mirror/Runtime/NetworkManager.cs @@ -96,6 +96,7 @@ void Awake() { Debug.Log("Thank you for using Mirror! https://forum.unity.com/threads/unet-hlapi-community-edition.425437/"); InitializeSingleton(); + InitializeTransport(); } void InitializeSingleton() @@ -140,6 +141,13 @@ void InitializeSingleton() } } + // Initializes the transport, by default it is Telepathy + // override method if you want to use a different transport + public virtual void InitializeTransport() + { + Transport.layer = new TelepathyWebsocketsMultiplexTransport(); + } + // NetworkIdentity.UNetStaticUpdate is called from UnityEngine while LLAPI network is active. // if we want TCP then we need to call it manually. probably best from NetworkManager, although this means // that we can't use NetworkServer/NetworkClient without a NetworkManager invoking Update anymore. diff --git a/Mirror/Runtime/Transport/Transport.cs b/Mirror/Runtime/Transport/Transport.cs index 5f3fae8e3..82eeb3850 100644 --- a/Mirror/Runtime/Transport/Transport.cs +++ b/Mirror/Runtime/Transport/Transport.cs @@ -9,8 +9,10 @@ public static class Transport // hlapi needs to know max packet size to show warnings public static int MaxPacketSize = ushort.MaxValue; - // selected transport layer: Telepathy by default - public static TransportLayer layer = new TelepathyWebsocketsMultiplexTransport(); + // selected transport layer + // the transport is normally initialized in NetworkManager InitializeTransport + // initialize it yourself if you are not using NetworkManager + public static TransportLayer layer; } // abstract transport layer class ////////////////////////////////////////// diff --git a/Mirror/Tests/NetworkWriterTest.cs b/Mirror/Tests/NetworkWriterTest.cs index 572271935..4ee9ba2c1 100644 --- a/Mirror/Tests/NetworkWriterTest.cs +++ b/Mirror/Tests/NetworkWriterTest.cs @@ -31,6 +31,7 @@ public void TestWritingLargeMessage() [Test] public void TestWritingHugeArray() { + Transport.MaxPacketSize = 1000000; // try serializing array > 64KB and see what happens NetworkWriter writer = new NetworkWriter(); writer.WriteBytesAndSize(new byte[100000]);