From 3cd4494983bfa62b3da19fea455c62e7519b0d6c Mon Sep 17 00:00:00 2001 From: "CTHULHU\\Ben" Date: Tue, 27 Aug 2024 00:49:09 -0400 Subject: [PATCH 1/2] 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); } From 572917af48d3179059e857630cb14ef717f97d49 Mon Sep 17 00:00:00 2001 From: "CTHULHU\\Ben" Date: Wed, 8 Jan 2025 16:52:17 -0500 Subject: [PATCH 2/2] fixed incorrect naming --- .../Runtime/Transports/UTP/UnityTransport.cs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/com.unity.netcode.gameobjects/Runtime/Transports/UTP/UnityTransport.cs b/com.unity.netcode.gameobjects/Runtime/Transports/UTP/UnityTransport.cs index b22f0ec369..c1fd131589 100644 --- a/com.unity.netcode.gameobjects/Runtime/Transports/UTP/UnityTransport.cs +++ b/com.unity.netcode.gameobjects/Runtime/Transports/UTP/UnityTransport.cs @@ -177,14 +177,14 @@ 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.")] + [Tooltip("Per default the client/server will communicate over UDP. Set to true to communicate locally using IPC.")] [SerializeField] - private bool m_UseRPC = false; + private bool m_UseIPC = false; - public bool UseRPC + public bool UseIPC { - get => m_UseRPC; - set => m_UseRPC = value; + get => m_UseIPC; + set => m_UseIPC = value; } /// @@ -1555,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 && m_UseRPC == false) + if (NetworkManager.IsServer && m_ProtocolType != ProtocolType.RelayUnityTransport && m_UseIPC == false) { - throw new Exception("WebGL as a server is not supported by Unity Transport, outside the Editor. Use RPC or Relay instead."); + throw new Exception("WebGL as a server is not supported by Unity Transport, outside the Editor. Use IPC or Relay instead."); } #endif @@ -1621,9 +1621,9 @@ public void CreateDriver(UnityTransport transport, out NetworkDriver driver, #endif #if UTP_TRANSPORT_2_0_ABOVE - if (m_UseRPC) + if (m_UseIPC) { - driver = NetworkDriver.Create(new RPCNetworkInterface(), m_NetworkSettings); + driver = NetworkDriver.Create(new IPCNetworkInterface(), m_NetworkSettings); } else if (m_UseWebSockets) {