// Note:ToAwaitableEnumerator/StartAsCoroutine/LazyTask are obsolete way on Unity 5.3 // You can use ToYieldInstruction. #if !(UNITY_4_0 || UNITY_4_1 || UNITY_4_2 || UNITY_4_3 || UNITY_4_4 || UNITY_4_5 || UNITY_4_6 || UNITY_5_0 || UNITY_5_1 || UNITY_5_2) IEnumerator TestNewCustomYieldInstruction() { // wait Rx Observable. yield return(QWait.ForSeconds(1.0f)); // you can change the scheduler(this is ignore Time.scale) yield return(QWait.ForSeconds(1.0f)); // get return value from ObservableYieldInstruction var o = ObservableWWW.Get("http://unity3d.com/").ToYieldInstruction(throwOnError: false); yield return(o); if (o.HasError) { Debug.Log(o.Error.ToString()); } if (o.HasResult) { Debug.Log(o.Result); } // other sample(wait until transform.position.y >= 100) yield return(this.ObserveEveryValueChanged(x => x.transform).FirstOrDefault(x => x.position.y >= 100).ToYieldInstruction()); }
private IEnumerator Start() { mClient = FlexiSocket.Create(ServerIp, 1366, Protocols.BodyLengthPrefix); //ipv6 yield return(QWait.ForSeconds(1.0f)); // wait for server to startup since bot server and clients are in the same scene using (var connect = mClient.ConnectAsync()) { yield return(connect); if (!connect.IsSuccessful) { Debug.LogException(connect.Exception); yield break; } Debug.Log("Connected", this); } while (mClient.IsConnected) { using (var receive = mClient.ReceiveAsync()) { yield return(receive); if (!receive.IsSuccessful) { if (receive.Exception != null) { Debug.LogException(receive.Exception); } if (receive.Error != SocketError.Success) { Debug.LogError(receive.Error); } mClient.Close(); yield break; } Debug.Log("Client received: " + Encoding.UTF8.GetString(receive.Data), this); } var send = mClient.SendAsync("Hey I've got your message"); yield return(send); if (!send.IsSuccessful) { if (send.Exception != null) { Debug.LogException(send.Exception); } if (send.Error != SocketError.Success) { Debug.LogError(send.Error); } mClient.Close(); yield break; } Debug.Log("Message sent", this); GameObject.CreatePrimitive(PrimitiveType.Cylinder); } }