/// <summary> /// Invokes a callback after a successfull connection, /// instantly if connected, or after the timeout, if failed to connect /// </summary> public void WaitConnection(Action <IClientSocket> connectionCallback, float timeoutSeconds) { if (IsConnected) { connectionCallback.Invoke(this); return; } var isConnected = false; var timedOut = false; Action onConnected = null; onConnected = () => { Connected -= onConnected; isConnected = true; if (!timedOut) { connectionCallback.Invoke(this); } }; Connected += onConnected; BTimer.AfterSeconds(timeoutSeconds, () => { if (!isConnected) { timedOut = true; Connected -= onConnected; connectionCallback.Invoke(this); } }); }
// Use this for initialization private void Awake() { // Framework requires applications to run in background Application.runInBackground = true; _mainThreadActions = new List <Action>(); _instance = this; DontDestroyOnLoad(this); StartCoroutine(StartTicker()); }