/// <summary> /// Main loop for the WAAPI API. Checks if the client is connected and consumes all commands. /// </summary> private static async void Loop() { try { ErrorMessage = ""; if (await CheckConnection()) { await ConsumeCommandQueue(); } if (!kill) { if (loopSleep > 0) { await Task.Delay(loopSleep * 1000); } } } //Handle socket issues caused by closing Wwise Authoring. catch (System.Net.WebSockets.WebSocketException) { UnityEngine.Debug.Log("Wwise Unity : WAAPI disconnected because Wwise Authoring was closed"); Disconnecting?.Invoke(false); waapiCommandQueue = new ConcurrentQueue <WaapiCommand>(); projectConnected = false; try { await m_WaapiClient.Close(); } //Closing the client will throw other exceptions because it tries to send messages to a closed socket. catch (System.Net.Sockets.SocketException) { } } catch (Wamp.WampNotConnectedException e) { ErrorMessage = e.Message; } finally { UnityEditor.EditorApplication.delayCall += () => Loop(); } }