Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
fa0fef6
Added delegate types and appropriate events in NetworkSceneManager.
pdeschain Apr 20, 2021
adf18e3
Added a new internal message that is sent out to all the clients when…
pdeschain Apr 21, 2021
d10910b
Added comments and an array of timed out client IDs to the OnAllClien…
pdeschain Apr 21, 2021
c802347
Noticed that I was trying to check the list of connected clients on t…
pdeschain Apr 22, 2021
ffb06da
Added automated tests for introduced callbacks.
pdeschain Apr 26, 2021
6dfbebb
More work on tests
pdeschain Apr 27, 2021
d23e199
More work on tests
pdeschain Apr 28, 2021
16468ef
Merge branch 'develop' of https://github.com/Unity-Technologies/com.u…
pdeschain Apr 28, 2021
9fb4a8c
Merge branch 'develop' into feature/onclientready-mtt588
NoelStephensUnity Apr 28, 2021
531ebdb
Moved scenes used for OnClientReady tests under the Assets/ directory
pdeschain Apr 30, 2021
4f0b4e3
Moved OnAllClientsReady scenes back into package, testing how Yamato …
pdeschain Apr 30, 2021
b8280e2
Moved the test scenes back under Assets/ folder, tweaked the code tha…
pdeschain Apr 30, 2021
1e2c31a
More of the same attempts to placate Yamato
pdeschain Apr 30, 2021
e3beeb1
#
pdeschain Apr 30, 2021
fcd7f42
Due to current limitations in our ability to reference scenes in Asse…
pdeschain Apr 30, 2021
73efb2e
Renamed the message and added events and delegates to be more underst…
pdeschain May 3, 2021
007719f
Merge branch 'develop' of https://github.com/Unity-Technologies/com.u…
pdeschain May 3, 2021
cf3d516
doc tweaks
pdeschain May 3, 2021
a7f9add
Yamato taming
pdeschain May 3, 2021
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
Renamed the message and added events and delegates to be more underst…
…andable at a glance
  • Loading branch information
pdeschain committed May 3, 2021
commit 73efb2e1f9376a3704d84f69a2f1674f531cd6e2
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ internal static class NetworkConstants
internal const byte TIME_SYNC = 11;
internal const byte NETWORK_VARIABLE_DELTA = 12;
internal const byte NETWORK_VARIABLE_UPDATE = 13;
internal const byte ALL_CLIENTS_SWITCH_SCENE_COMPLETED = 14;
internal const byte ALL_CLIENTS_LOADED_SCENE = 14;
internal const byte UNNAMED_MESSAGE = 20;
internal const byte DESTROY_OBJECTS = 21;
internal const byte NAMED_MESSAGE = 22;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1258,7 +1258,7 @@ internal void HandleIncomingData(ulong clientId, NetworkChannel networkChannel,
}

break;
case NetworkConstants.ALL_CLIENTS_SWITCH_SCENE_COMPLETED:
case NetworkConstants.ALL_CLIENTS_LOADED_SCENE:
if (IsClient)
{
MessageHandler.HandleAllClientsSwitchSceneCompleted(clientId, messageStream);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,21 @@ public class NetworkSceneManager

/// <summary>
/// Delegate for when a client has reported to the server that it has completed scene transition
/// <see cref='NetworkSceneManager.OnNotifyServerClientLoadedScene'/>
/// </summary>
public delegate void OnClientLoadedSceneDelegate(SceneSwitchProgress progress, ulong clientId);
public delegate void NotifyServerClientLoadedSceneDelegate(SceneSwitchProgress progress, ulong clientId);


/// <summary>
/// Delegate for when all clients have reported to the server that they have completed scene transition or timed out
/// <see cref='NetworkSceneManager.OnNotifyServerAllClientsLoadedScene'/>
/// </summary>
public delegate void OnAllClientsLoadedSceneDelegate(SceneSwitchProgress progress, bool timedOut);
public delegate void NotifyServerAllClientsLoadedSceneDelegate(SceneSwitchProgress progress, bool timedOut);

/// <summary>
/// Delegate for when the clients get notified by the server that all clients have completed their scene transitions
/// Delegate for when the clients get notified by the server that all clients have completed their scene transitions.
/// <see cref='NetworkSceneManager.OnNotifyClientAllClientsLoadedScene'/>
/// </summary>
public delegate void AllClientsReadyDelegate(ulong[] clientIds, ulong[] timedOutClientIds);
public delegate void NotifyClientAllClientsLoadedSceneDelegate(ulong[] clientIds, ulong[] timedOutClientIds);

/// <summary>
/// Event that is invoked when the scene is switched
Expand All @@ -59,18 +61,19 @@ public class NetworkSceneManager
/// <summary>
/// Event that is invoked on the server when a client completes scene transition
/// </summary>
public event OnClientLoadedSceneDelegate OnClientLoadedScene;
public event NotifyServerClientLoadedSceneDelegate OnNotifyServerClientLoadedScene;

/// <summary>
/// Event that is invoked on the server when all clients have reported that they have completed scene transition
/// </summary>
public event OnAllClientsLoadedSceneDelegate OnAllClientsLoadedScene;
public event NotifyServerAllClientsLoadedSceneDelegate OnNotifyServerAllClientsLoadedScene;

/// <summary>
/// Event that is invoked on the clients after all clients have successfully completed scene transition or timed out.
/// This event relies on MessageSender, which doesn't send events from the server to itself (which is the case for a Host client).
/// This event happens after <see cref="OnNotifyServerAllClientsLoadedScene"/> fires on the server and a <see cref="NetworkConstants.ALL_CLIENTS_LOADED_SCENE"/> message is sent to the clients.
/// It relies on MessageSender, which doesn't send events from the server to itself (which is the case for a Host client).
/// </summary>
public event AllClientsReadyDelegate OnAllClientsReady;
public event NotifyClientAllClientsLoadedSceneDelegate OnNotifyClientAllClientsLoadedScene;

internal readonly HashSet<string> RegisteredSceneNames = new HashSet<string>();
internal readonly Dictionary<string, uint> SceneNameToIndex = new Dictionary<string, uint>();
Expand Down Expand Up @@ -173,10 +176,10 @@ public SceneSwitchProgress SwitchScene(string sceneName)
SceneSwitchProgresses.Add(switchSceneProgress.Guid, switchSceneProgress);
CurrentSceneSwitchProgressGuid = switchSceneProgress.Guid;

switchSceneProgress.OnClientLoadedScene += clientId => { OnClientLoadedScene?.Invoke(switchSceneProgress, clientId); };
switchSceneProgress.OnClientLoadedScene += clientId => { OnNotifyServerClientLoadedScene?.Invoke(switchSceneProgress, clientId); };
switchSceneProgress.OnComplete += timedOut =>
{
OnAllClientsLoadedScene?.Invoke(switchSceneProgress, timedOut);
OnNotifyServerAllClientsLoadedScene?.Invoke(switchSceneProgress, timedOut);

using (var buffer = PooledNetworkBuffer.Get())
using (var writer = PooledNetworkWriter.Get(buffer))
Expand All @@ -187,7 +190,7 @@ public SceneSwitchProgress SwitchScene(string sceneName)
writer.WriteULongArray(doneClientIds, doneClientIds.Length);
writer.WriteULongArray(timedOutClientIds, timedOutClientIds.Length);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! Both active and timed out clients!
Very useful!


m_NetworkManager.MessageSender.Send(NetworkManager.Singleton.ServerClientId, NetworkConstants.ALL_CLIENTS_SWITCH_SCENE_COMPLETED, NetworkChannel.Internal, buffer);
m_NetworkManager.MessageSender.Send(NetworkManager.Singleton.ServerClientId, NetworkConstants.ALL_CLIENTS_LOADED_SCENE, NetworkChannel.Internal, buffer);
}
};

Expand Down Expand Up @@ -454,7 +457,7 @@ private void MoveObjectsToScene(Scene scene)

internal void AllClientsReady(ulong[] clientIds, ulong[] timedOutClientIds)
{
OnAllClientsReady?.Invoke(clientIds, timedOutClientIds);
OnNotifyClientAllClientsLoadedScene?.Invoke(clientIds, timedOutClientIds);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ public override void NetworkStart()
{
if (IsServer)
{
NetworkManager.SceneManager.OnClientLoadedScene += (progress, clientId) =>
NetworkManager.SceneManager.OnNotifyServerClientLoadedScene += (progress, clientId) =>
{
Debug.Log("OnClientLoadedScene invoked on the host - Passed");
Debug.Log("OnNotifyServerClientLoadedScene invoked on the host - Passed");
};

NetworkManager.SceneManager.OnAllClientsLoadedScene += (progress, timedOut) =>
NetworkManager.SceneManager.OnNotifyServerAllClientsLoadedScene += (progress, timedOut) =>
{
Debug.Log("OnAllClientsLoadedScene invoked on the host - Passed");
Debug.Log("OnNotifyServerAllClientsLoadedScene invoked on the host - Passed");
};

NetworkManager.SceneManager.SwitchScene("SceneWeAreSwitchingTo");
Expand Down