/// <summary> /// 协程改造的Connect和Send函数 /// </summary> /// <returns>The connect.</returns> IEnumerator InitConnect() { if (rc != null) { rc = null; yield return(new WaitForSeconds(2)); } //玩家自己模型尚未初始化准备完毕则不要连接服务器放置Logic之后玩家的ID没有设置 while (ObjectManager.objectManager.GetMyPlayer() == null) { yield return(null); } //重新构建新的连接 rc = new RemoteClient(ml); rc.evtHandler = EvtHandler; rc.msgHandler = MsgHandler; rc.Connect(ServerIP, 10001); while (lastEvt == RemoteClientEvent.None && state == WorldState.Connecting) { yield return(null); } Debug.LogError("StartInitData: " + lastEvt); if (lastEvt == RemoteClientEvent.Connected) { state = WorldState.Connected; yield return(StartCoroutine(InitData())); yield return(StartCoroutine(SendCommandToServer())); } else { //StartCoroutine(RetryConnect()); } }