Skip to content

Commit a4a6a89

Browse files
committed
修复Unity运行时,触发代码编译导致卡死问题。性能优化,修改Socket发送线程休眠时间。
1 parent 6b0b1ab commit a4a6a89

File tree

4 files changed

+23
-3
lines changed

4 files changed

+23
-3
lines changed

Assets/UnityWebSocket/Scripts/Editor/SettingsWindow.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ private void DrawHelper()
120120
Application.OpenURL(uri.AbsoluteUri);
121121
}
122122

123-
GUI.Label(new Rect(330, 275, 100, 18), "QQ群:", TextStyle(10, TextAnchor.MiddleRight));
123+
GUI.Label(new Rect(330, 275, 100, 18), "QQ Group:", TextStyle(10, TextAnchor.MiddleRight));
124124
if (GUI.Button(new Rect(440, 275, 150, 18), Settings.QQ_GROUP))
125125
{
126126
Application.OpenURL(Settings.QQ_GROUP_LINK);

Assets/UnityWebSocket/Scripts/Runtime/Core/Settings.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ public static class Settings
77
public const string QQ_GROUP_LINK = "https://qm.qq.com/cgi-bin/qm/qr?k=KcexYJ9aYwogFXbj2aN0XHH5b2G7ICmd";
88
public const string EMAIL = "[email protected]";
99
public const string AUHTOR = "psygames";
10-
public const string VERSION = "2.8.3";
10+
public const string VERSION = "2.8.4";
1111
}
1212
}

Assets/UnityWebSocket/Scripts/Runtime/Implementation/NoWebGL/WebSocket.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ private async void StartSendTask()
174174
Log($"Send, type: {buffer.type}, size: {buffer.data.Length}, queue left: {sendQueue.Count}");
175175
await socket.SendAsync(new ArraySegment<byte>(buffer.data), buffer.type, true, cts.Token);
176176
}
177-
Thread.Sleep(1);
177+
Thread.Sleep(3);
178178
}
179179
if (closeProcessing && socket != null && cts != null && !cts.IsCancellationRequested)
180180
{

Assets/UnityWebSocket/Scripts/Runtime/Implementation/NoWebGL/WebSocketManager.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace UnityWebSocket
66
{
7+
[DisallowMultipleComponent]
78
[DefaultExecutionOrder(-10000)]
89
internal class WebSocketManager : MonoBehaviour
910
{
@@ -29,6 +30,10 @@ public static void CreateInstance()
2930
if (!go) go = new GameObject(rootName);
3031
_instance = go.GetComponent<WebSocketManager>();
3132
if (!_instance) _instance = go.AddComponent<WebSocketManager>();
33+
#if UNITY_EDITOR && UNITY_2019_1_OR_NEWER
34+
UnityEditor.Compilation.CompilationPipeline.compilationStarted -= OnCompilationStarted;
35+
UnityEditor.Compilation.CompilationPipeline.compilationStarted += OnCompilationStarted;
36+
#endif
3237
}
3338

3439
private readonly List<WebSocket> sockets = new List<WebSocket>();
@@ -55,7 +60,22 @@ private void Update()
5560
}
5661

5762
#if UNITY_EDITOR
63+
#if UNITY_2019_1_OR_NEWER
64+
private static void OnCompilationStarted(object obj)
65+
{
66+
if (_instance != null)
67+
{
68+
_instance.SocketAbort();
69+
}
70+
}
71+
#endif
72+
5873
private void OnApplicationQuit()
74+
{
75+
SocketAbort();
76+
}
77+
78+
private void SocketAbort()
5979
{
6080
for (int i = sockets.Count - 1; i >= 0; i--)
6181
{

0 commit comments

Comments
 (0)