From 3cd4494983bfa62b3da19fea455c62e7519b0d6c Mon Sep 17 00:00:00 2001 From: "CTHULHU\\Ben" Date: Tue, 27 Aug 2024 00:49:09 -0400 Subject: [PATCH] Expose the ability to use RPC especially on WebGL to allow us to easily make a single player mode while still using netcode usually as a host. --- .../Runtime/Transports/UTP/UnityTransport.cs | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/com.unity.netcode.gameobjects/Runtime/Transports/UTP/UnityTransport.cs b/com.unity.netcode.gameobjects/Runtime/Transports/UTP/UnityTransport.cs index 984da63ee8..b22f0ec369 100644 --- a/com.unity.netcode.gameobjects/Runtime/Transports/UTP/UnityTransport.cs +++ b/com.unity.netcode.gameobjects/Runtime/Transports/UTP/UnityTransport.cs @@ -177,6 +177,16 @@ public bool UseWebSockets set => m_UseWebSockets = value; } + [Tooltip("Per default the client/server will communicate over UDP. Set to true to communicate locally using RPC.")] + [SerializeField] + private bool m_UseRPC = false; + + public bool UseRPC + { + get => m_UseRPC; + set => m_UseRPC = value; + } + /// /// Per default the client/server communication will not be encrypted. Select true to enable DTLS for UDP and TLS for Websocket. /// @@ -1545,9 +1555,9 @@ public void CreateDriver(UnityTransport transport, out NetworkDriver driver, heartbeatTimeoutMS: transport.m_HeartbeatTimeoutMS); #if UNITY_WEBGL && !UNITY_EDITOR - if (NetworkManager.IsServer && m_ProtocolType != ProtocolType.RelayUnityTransport) + if (NetworkManager.IsServer && m_ProtocolType != ProtocolType.RelayUnityTransport && m_UseRPC == false) { - throw new Exception("WebGL as a server is not supported by Unity Transport, outside the Editor."); + throw new Exception("WebGL as a server is not supported by Unity Transport, outside the Editor. Use RPC or Relay instead."); } #endif @@ -1611,7 +1621,11 @@ public void CreateDriver(UnityTransport transport, out NetworkDriver driver, #endif #if UTP_TRANSPORT_2_0_ABOVE - if (m_UseWebSockets) + if (m_UseRPC) + { + driver = NetworkDriver.Create(new RPCNetworkInterface(), m_NetworkSettings); + } + else if (m_UseWebSockets) { driver = NetworkDriver.Create(new WebSocketNetworkInterface(), m_NetworkSettings); }