Skip to content
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

feat: Single player hosting in WebGL using RPC #3035

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/// <summary>
/// Per default the client/server communication will not be encrypted. Select true to enable DTLS for UDP and TLS for Websocket.
/// </summary>
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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);
}
Expand Down