mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 02:50:32 +00:00
feat(HUD): Support for MultiplexTransport Port (#3662)
* Moved Multiplex to Core * Updated Available and ToString in Transports - Available now uses `#if UNITY_WEBGL` because `Application.platform != RuntimePlatform.WebGLPlayer;` doesn't work in Editor - ToString was shortened and includes port for presentation in HUD * NetworkManagerHUD: Added support for MultiplexTransport * Moved Multiplex back to Transports * Implemented PortTransport in Multiplex * NetworkManagerHUD: reverted width change * Revamped Port handler * Changed LogError to LogWarning in Port setter * Moved ToString change to separate PR * Use Utils.IsHeadless * Use Utils.IsDebug * Removed console logging
This commit is contained in:
parent
b2d2cae776
commit
5132fa8bfc
@ -7,7 +7,7 @@ namespace Mirror
|
|||||||
{
|
{
|
||||||
// a transport that can listen to multiple underlying transport at the same time
|
// a transport that can listen to multiple underlying transport at the same time
|
||||||
[DisallowMultipleComponent]
|
[DisallowMultipleComponent]
|
||||||
public class MultiplexTransport : Transport
|
public class MultiplexTransport : Transport, PortTransport
|
||||||
{
|
{
|
||||||
public Transport[] transports;
|
public Transport[] transports;
|
||||||
|
|
||||||
@ -42,6 +42,44 @@ public class MultiplexTransport : Transport
|
|||||||
// next multiplexed id counter. start at 1 because 0 is reserved for host.
|
// next multiplexed id counter. start at 1 because 0 is reserved for host.
|
||||||
int nextMultiplexedId = 1;
|
int nextMultiplexedId = 1;
|
||||||
|
|
||||||
|
// prevent log flood from OnGUI or similar per-frame updates
|
||||||
|
bool alreadyWarned;
|
||||||
|
|
||||||
|
public ushort Port
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
foreach (Transport transport in transports)
|
||||||
|
if (transport.Available() && transport is PortTransport portTransport)
|
||||||
|
return portTransport.Port;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (Utils.IsHeadless() && !alreadyWarned)
|
||||||
|
{
|
||||||
|
// prevent log flood from OnGUI or similar per-frame updates
|
||||||
|
alreadyWarned = true;
|
||||||
|
Debug.LogWarning($"MultiplexTransport: Server cannot set the same listen port for all transports! Set them directly instead.");
|
||||||
|
}
|
||||||
|
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// We can't set the same port for all transports because
|
||||||
|
// listen ports have to be different for each transport
|
||||||
|
// so we just set the first available one.
|
||||||
|
// This depends on the selected build platform.
|
||||||
|
foreach (Transport transport in transports)
|
||||||
|
if (transport.Available() && transport is PortTransport portTransport)
|
||||||
|
{
|
||||||
|
portTransport.Port = value;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// add to bidirection lookup. returns the multiplexed connectionId.
|
// add to bidirection lookup. returns the multiplexed connectionId.
|
||||||
public int AddToLookup(int originalConnectionId, int transportIndex)
|
public int AddToLookup(int originalConnectionId, int transportIndex)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user