Skip to content

Commit 2e9b7c1

Browse files
Merge branch 'develop-2.0.0' into fix/bufferedlinearinterpolator-jitter
2 parents f327a1e + dfef393 commit 2e9b7c1

File tree

3 files changed

+49
-0
lines changed

3 files changed

+49
-0
lines changed

com.unity.netcode.gameobjects/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Additional documentation and release notes are available at [Multiplayer Documen
1010

1111
### Added
1212

13+
- Added `NetworkManager.OnPreShutdown` which is called before the NetworkManager cleans up and shuts down. (#3366)
1314
- Added `LerpExtrapolateBlend` interpolation type that provides users with something between standard lerp and smooth dampening. (#3355)
1415
- Added property to enable or disable lerp smoothing for position, rotation, and scale interpolators. (#3355)
1516
- Added `NetworkTransform.InterpolationBufferTickOffset` static property to provide users with a way to increase or decrease the time marker where interpolators will pull state update from the queue. (#3355)

com.unity.netcode.gameobjects/Runtime/Core/NetworkManager.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -826,6 +826,12 @@ public struct ConnectionApprovalRequest
826826
/// </summary>
827827
public event Action OnClientStarted = null;
828828

829+
/// <summary>
830+
/// Subscribe to this event to get notifications before a <see cref="NetworkManager"/> instance is being destroyed.
831+
/// This is useful if you want to use the state of anything the NetworkManager cleans up during its shutdown.
832+
/// </summary>
833+
public event Action OnPreShutdown = null;
834+
829835
/// <summary>
830836
/// This callback is invoked once the local server is stopped.
831837
/// </summary>
@@ -1500,6 +1506,8 @@ internal void ShutdownInternal()
15001506
NetworkLog.LogInfo(nameof(ShutdownInternal));
15011507
}
15021508

1509+
OnPreShutdown?.Invoke();
1510+
15031511
this.UnregisterAllNetworkUpdates();
15041512

15051513
// Everything is shutdown in the order of their dependencies

com.unity.netcode.gameobjects/Tests/Runtime/NetworkManagerEventsTests.cs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,46 @@ public IEnumerator OnClientAndServerStartedCalledWhenHostStarts()
236236
Assert.AreEqual(2, callbacksInvoked, "either OnServerStarted or OnClientStarted wasn't invoked");
237237
}
238238

239+
[UnityTest]
240+
public IEnumerator OnPreShutdownCalledWhenShuttingDown()
241+
{
242+
bool preShutdownInvoked = false;
243+
bool shutdownInvoked = false;
244+
var gameObject = new GameObject(nameof(OnPreShutdownCalledWhenShuttingDown));
245+
m_ServerManager = gameObject.AddComponent<NetworkManager>();
246+
247+
// Set dummy transport that does nothing
248+
var transport = gameObject.AddComponent<DummyTransport>();
249+
m_ServerManager.NetworkConfig = new NetworkConfig() { NetworkTransport = transport };
250+
251+
Action onPreShutdown = () =>
252+
{
253+
preShutdownInvoked = true;
254+
Assert.IsFalse(shutdownInvoked, "OnPreShutdown was invoked after OnServerStopped");
255+
};
256+
257+
Action<bool> onServerStopped = (bool wasAlsoClient) =>
258+
{
259+
shutdownInvoked = true;
260+
Assert.IsTrue(preShutdownInvoked, "OnPreShutdown wasn't invoked before OnServerStopped");
261+
};
262+
263+
// Start server to cause initialization process
264+
Assert.True(m_ServerManager.StartServer());
265+
Assert.True(m_ServerManager.IsListening);
266+
267+
m_ServerManager.OnPreShutdown += onPreShutdown;
268+
m_ServerManager.OnServerStopped += onServerStopped;
269+
m_ServerManager.Shutdown();
270+
Object.DestroyImmediate(gameObject);
271+
272+
yield return WaitUntilManagerShutsdown();
273+
274+
Assert.False(m_ServerManager.IsListening);
275+
Assert.True(preShutdownInvoked, "OnPreShutdown wasn't invoked");
276+
Assert.True(shutdownInvoked, "OnServerStopped wasn't invoked");
277+
}
278+
239279
private IEnumerator WaitUntilManagerShutsdown()
240280
{
241281
/* Need two updates to actually shut down. First one to see the transport failing, which

0 commit comments

Comments
 (0)