Skip to content

Commit c04b946

Browse files
committed
Improve PausedSocketFix. Also stop running NetManagers in Unity in OnApplicationQuit (when using library source code)
1 parent 60c453d commit c04b946

File tree

5 files changed

+125
-12
lines changed

5 files changed

+125
-12
lines changed

LiteNetLib/NetManager.cs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1603,20 +1603,21 @@ public void Stop(bool sendDisconnectMessages)
16031603
return;
16041604
NetDebug.Write("[NM] Stop");
16051605

1606+
//Send last disconnect
1607+
for (var netPeer = _headPeer; netPeer != null; netPeer = netPeer.NextPeer)
1608+
netPeer.Shutdown(null, 0, 0, !sendDisconnectMessages);
1609+
1610+
//Stop
1611+
CloseSocket();
1612+
16061613
#if UNITY_SOCKET_FIX
16071614
if (_useSocketFix)
16081615
{
16091616
_pausedSocketFix.Deinitialize();
16101617
_pausedSocketFix = null;
16111618
}
16121619
#endif
1613-
1614-
//Send last disconnect
1615-
for (var netPeer = _headPeer; netPeer != null; netPeer = netPeer.NextPeer)
1616-
netPeer.Shutdown(null, 0, 0, !sendDisconnectMessages);
1617-
1618-
//Stop
1619-
CloseSocket();
1620+
16201621
_updateTriggerEvent.Set();
16211622
if (!_manualMode)
16221623
{

LiteNetLib/PausedSocketFix.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#if UNITY_2018_3_OR_NEWER
22
using System.Net;
3+
using UnityEngine;
34

45
namespace LiteNetLib
56
{
@@ -19,14 +20,23 @@ public PausedSocketFix(NetManager netManager, IPAddress ipv4, IPAddress ipv6, in
1920
_ipv6 = ipv6;
2021
_port = port;
2122
_manualMode = manualMode;
22-
UnityEngine.Application.focusChanged += Application_focusChanged;
23+
Application.focusChanged += Application_focusChanged;
24+
Application.quitting += Deinitialize;
2325
_initialized = true;
2426
}
2527

2628
public void Deinitialize()
2729
{
2830
if (_initialized)
29-
UnityEngine.Application.focusChanged -= Application_focusChanged;
31+
{
32+
Application.focusChanged -= Application_focusChanged;
33+
Application.quitting -= Deinitialize;
34+
}
35+
36+
if (_netManager.IsRunning)
37+
{
38+
_netManager.Stop();
39+
}
3040
_initialized = false;
3141
}
3242

0 Bytes
Binary file not shown.

LiteNetLibSampleUnity/ProjectSettings/ProjectSettings.asset

Lines changed: 103 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,15 @@ PlayerSettings:
7676
androidMinimumWindowWidth: 400
7777
androidMinimumWindowHeight: 300
7878
androidFullscreenMode: 1
79+
androidAutoRotationBehavior: 1
7980
defaultIsNativeResolution: 1
8081
macRetinaSupport: 1
8182
runInBackground: 0
8283
captureSingleScreen: 0
8384
muteOtherAudioSources: 0
8485
Prepare IOS For Recording: 0
8586
Force IOS Speakers When Recording: 0
87+
audioSpatialExperience: 0
8688
deferSystemGesturesMode: 0
8789
hideHomeButton: 0
8890
submitAnalytics: 1
@@ -136,6 +138,8 @@ PlayerSettings:
136138
vulkanEnableLateAcquireNextImage: 0
137139
vulkanEnableCommandBufferRecycling: 1
138140
loadStoreDebugModeEnabled: 0
141+
visionOSBundleVersion: 1.0
142+
tvOSBundleVersion: 1.0
139143
bundleVersion: 1.0
140144
preloadedAssets: []
141145
metroInputSource: 0
@@ -234,6 +238,7 @@ PlayerSettings:
234238
iOSMetalForceHardShadows: 0
235239
metalEditorSupport: 1
236240
metalAPIValidation: 1
241+
metalCompileShaderBinary: 0
237242
iOSRenderExtraFrameOnPause: 1
238243
iosCopyPluginsCodeInsteadOfSymlink: 0
239244
appleDeveloperTeamID:
@@ -384,6 +389,103 @@ PlayerSettings:
384389
m_Height: 36
385390
m_Kind: 0
386391
m_SubKind:
392+
- m_BuildTarget: iPhone
393+
m_Icons:
394+
- m_Textures: []
395+
m_Width: 180
396+
m_Height: 180
397+
m_Kind: 0
398+
m_SubKind: iPhone
399+
- m_Textures: []
400+
m_Width: 120
401+
m_Height: 120
402+
m_Kind: 0
403+
m_SubKind: iPhone
404+
- m_Textures: []
405+
m_Width: 167
406+
m_Height: 167
407+
m_Kind: 0
408+
m_SubKind: iPad
409+
- m_Textures: []
410+
m_Width: 152
411+
m_Height: 152
412+
m_Kind: 0
413+
m_SubKind: iPad
414+
- m_Textures: []
415+
m_Width: 76
416+
m_Height: 76
417+
m_Kind: 0
418+
m_SubKind: iPad
419+
- m_Textures: []
420+
m_Width: 120
421+
m_Height: 120
422+
m_Kind: 3
423+
m_SubKind: iPhone
424+
- m_Textures: []
425+
m_Width: 80
426+
m_Height: 80
427+
m_Kind: 3
428+
m_SubKind: iPhone
429+
- m_Textures: []
430+
m_Width: 80
431+
m_Height: 80
432+
m_Kind: 3
433+
m_SubKind: iPad
434+
- m_Textures: []
435+
m_Width: 40
436+
m_Height: 40
437+
m_Kind: 3
438+
m_SubKind: iPad
439+
- m_Textures: []
440+
m_Width: 87
441+
m_Height: 87
442+
m_Kind: 1
443+
m_SubKind: iPhone
444+
- m_Textures: []
445+
m_Width: 58
446+
m_Height: 58
447+
m_Kind: 1
448+
m_SubKind: iPhone
449+
- m_Textures: []
450+
m_Width: 29
451+
m_Height: 29
452+
m_Kind: 1
453+
m_SubKind: iPhone
454+
- m_Textures: []
455+
m_Width: 58
456+
m_Height: 58
457+
m_Kind: 1
458+
m_SubKind: iPad
459+
- m_Textures: []
460+
m_Width: 29
461+
m_Height: 29
462+
m_Kind: 1
463+
m_SubKind: iPad
464+
- m_Textures: []
465+
m_Width: 60
466+
m_Height: 60
467+
m_Kind: 2
468+
m_SubKind: iPhone
469+
- m_Textures: []
470+
m_Width: 40
471+
m_Height: 40
472+
m_Kind: 2
473+
m_SubKind: iPhone
474+
- m_Textures: []
475+
m_Width: 40
476+
m_Height: 40
477+
m_Kind: 2
478+
m_SubKind: iPad
479+
- m_Textures: []
480+
m_Width: 20
481+
m_Height: 20
482+
m_Kind: 2
483+
m_SubKind: iPad
484+
- m_Textures: []
485+
m_Width: 1024
486+
m_Height: 1024
487+
m_Kind: 4
488+
m_SubKind: App Store
387489
m_BuildTargetBatching: []
388490
m_BuildTargetShaderSettings: []
389491
m_BuildTargetGraphicsJobs:
@@ -547,7 +649,6 @@ PlayerSettings:
547649
switchScreenResolutionBehavior: 2
548650
switchUseCPUProfiler: 0
549651
switchEnableFileSystemTrace: 0
550-
switchUseGOLDLinker: 0
551652
switchLTOSetting: 0
552653
switchApplicationID: 0x0005000C10000001
553654
switchNSODependencies:
@@ -846,6 +947,7 @@ PlayerSettings:
846947
metroSplashScreenBackgroundColor: {r: 0.13333334, g: 0.17254902, b: 0.21568628,
847948
a: 1}
848949
metroSplashScreenUseBackgroundColor: 1
950+
syncCapabilities: 0
849951
platformCapabilities: {}
850952
metroTargetDeviceFamilies: {}
851953
metroFTAName:
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
m_EditorVersion: 2022.3.12f1
2-
m_EditorVersionWithRevision: 2022.3.12f1 (4fe6e059c7ef)
1+
m_EditorVersion: 2022.3.50f1
2+
m_EditorVersionWithRevision: 2022.3.50f1 (c3db7f8bf9b1)

0 commit comments

Comments
 (0)