Skip to content

feat: networked message channel #605

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

Merged
merged 12 commits into from
Apr 26, 2022
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
only register to the custom networked messages on clients
  • Loading branch information
LPLafontaineB committed Apr 14, 2022
commit 30cbf179bab07e310af8bc6ed4ba9dd96b51fe2e
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ namespace Unity.Multiplayer.Samples.BossRoom.Shared.Infrastructure
{
/// <summary>
/// This type of message channel allows the server to publish a message that will be sent to clients as well as
/// being published locally. Clients and the server both can subscribe to it, but it needs to be done after
/// the NetworkManager is initialized.
/// being published locally. Clients and the server both can subscribe to it. However, that subscription needs to be
/// done after the NetworkManager has initialized. On objects whose lifetime is bigger than a networked session,
/// subscribing will be required each time a new session starts.
/// </summary>
/// <typeparam name="T"></typeparam>
public class NetworkedMessageChannel<T> : MessageChannel<T> where T : unmanaged
Expand Down Expand Up @@ -37,7 +38,8 @@ public override IDisposable Subscribe(Action<T> handler)
{
if (NetworkManager.Singleton != null && NetworkManager.Singleton.IsListening)
{
if (!m_HasRegisteredHandler && NetworkManager.Singleton.IsClient)
// Only register message handler on clients
if (!m_HasRegisteredHandler && !NetworkManager.Singleton.IsServer)
{
NetworkManager.Singleton.CustomMessagingManager.RegisterNamedMessageHandler(m_Name, ReceiveMessageThroughNetwork);
m_HasRegisteredHandler = true;
Expand Down