void Connect() { if (_connected == false && _connecting == false) { Debug.Log ("start connection procedure"); ConnectionDtO cdto = new ConnectionDtO(connectionPanel.username.text, version); connectionPanel.error.text = "Connecting"; _connecting = true; _local_client.GetPublicScene ("main", cdto).ContinueWith (task => { if (task.IsFaulted) { Debug.Log ("connection failed : " + task.Exception.Message); _connecting = false; } else { _scene = task.Result; Debug.Log ("configuring routes"); _scene.AddRoute ("create_ball", onCreateBalls); _scene.AddRoute ("destroy_ball", onDestroyBalls); Debug.Log ("connecting to remote scene"); _scene.Connect().ContinueWith( t => { if (_scene.Connected) { _connected = true; _connecting = false; Debug.Log("connection succeful"); UniRx.MainThreadDispatcher.Post (() =>{ connectionPanel.error.text = "Please enter a username"; connectionPanel.connectBtn.enabled = true; }); } else { Debug.Log ("connection failed: " + t.Exception.InnerException.Message); _connecting = false; UniRx.MainThreadDispatcher.Post (() =>{ connectionPanel.error.text = t.Exception.InnerException.Message; }); } }); } }); } }
public void clickOnPlay() { if (_scene != null && _connected == true) { ConnectionDtO ctdo = new ConnectionDtO(connectionPanel.username.text, version); _scene.Rpc<ConnectionDtO, int>("play", ctdo).Subscribe(resp => {onPlay(resp);}); } }