protected virtual async void Start() { var token = this.GetCancellationTokenOnDestroy(); await UniTask.Run(_networkHandler.Initialize, cancellationToken : token); onConnectCommand.Subscribe(() => { if (connectionStatusVariable == ConnectionStatusEnum.Disconnected) { connectionStatusVariable.Value = ConnectionStatusEnum.Connecting; _networkHandler.Connect(address).Forget(); } }) .AddTo(token); onDisconnectCommand.Subscribe(async() => { await _networkHandler.Disconnect(); connectionStatusVariable.Value = ConnectionStatusEnum.Disconnected; }) .AddTo(token); if (stringMessageSender != null) { stringMessageSender .Where(_ => connectionStatusVariable == ConnectionStatusEnum.Connected) .Subscribe(_networkHandler.SendString) .AddTo(token); } if (byteMessageSender != null) { byteMessageSender .Where(_ => connectionStatusVariable == ConnectionStatusEnum.Connected) .Subscribe(_networkHandler.SendBytes) .AddTo(token); } }