public void GoMainMenuOKSDK() { PhotonNetwork.DestroyPlayerObjects(PhotonNetwork.player); MainMenuManage.gameLoginType = MainMenuManage.GameLoginType.MainMenu; if (!YuanUnityPhoton.GetYuanUnityPhotonInstantiate().ServerConnected) { YuanUnityPhoton.NewYuanUnityPhotonInstantiate().ServerAddress = PlayerPrefs.GetString("TestServer") + ":5059"; YuanUnityPhoton.GetYuanUnityPhotonInstantiate().ServerApplication = PlayerPrefs.GetString("TestServerName"); YuanUnityPhoton.GetYuanUnityPhotonInstantiate().Connect(); } SendMessage("SongLoadOut", SendMessageOptions.DontRequireReceiver); }
IEnumerator Connect() { if (txtServerIP.text != "") { //YuanUnityPhoton.GetYuanUnityPhotonInstantiate().peer.Disconnect(); //while (YuanUnityPhoton.GetYuanUnityPhotonInstantiate().peer.PeerState != ExitGames.Client.Photon.PeerStateValue.Disconnected) //{ // yield return new WaitForSeconds(1); //} //YuanUnityPhoton.GetYuanUnityPhotonInstantiate().ServerAddress = txtServerIP.text + ":5059"; //YuanUnityPhoton.GetYuanUnityPhotonInstantiate().Connect(); //YuanUnityPhoton.GetYuanUnityPhotonInstantiate().peer.Disconnect(); //YuanUnityPhoton.GetYuanUnityPhotonInstantiate().peer = new ExitGames.Client.Photon.PhotonPeer(YuanUnityPhoton.GetYuanUnityPhotonInstantiate()); //YuanUnityPhoton.GetYuanUnityPhotonInstantiate().peer.Connect(txtServerIP.text+":5059", "YuanPhotonServerRoom"); //InRoom.GetInRoomInstantiate().peer.Disconnect(); //InRoom.GetInRoomInstantiate().peer = new ExitGames.Client.Photon.PhotonPeer(InRoom.GetInRoomInstantiate()); YuanUnityPhoton.GetYuanUnityPhotonInstantiate().peer.Disconnect(); YuanUnityPhoton.NewYuanUnityPhotonInstantiate().ServerAddress = txtServerIP.text + ":5059"; YuanUnityPhoton.GetYuanUnityPhotonInstantiate().MMManage = this.mmManage; YuanUnityPhoton.GetYuanUnityPhotonInstantiate().tableRead = this.tableRead; YuanUnityPhoton.GetYuanUnityPhotonInstantiate().Connect(); InRoom.GetInRoomInstantiate().peer.Disconnect(); InRoom.NewInRoomInstantiate(); //InRoom.GetInRoomInstantiate().Connect(); ServerSettings.DefaultServerAddress = txtServerIP.text + ":5055"; PhotonNetwork.Disconnect(); while (PhotonNetwork.connectionState != ConnectionState.Disconnected) { yield return(new WaitForSeconds(0.5f)); } PhotonNetwork.Connect(txtServerIP.text, 5055, "Master", "1.0"); PlayerPrefs.SetString("TestServer", txtServerIP.text); PlayerPrefs.SetString("TestServerName", "YuanPhotonServerRoom"); } }
/// <summary> /// YuanUnity服务器重连方法 /// </summary> /// <returns> /// The yuan unity. /// </returns> /// <param name='mNum'> /// 超时时间 /// </param> public IEnumerator ConnectYuanUnity(int mNum) { if (ZealmConnector.connection == null) //if(!YuanUnityPhoton.GetYuanUnityPhotonInstantiate ().ServerConnected) { YuanUnityPhoton.NewYuanUnityPhotonInstantiate().ServerAddress = PlayerPrefs.GetString("ConnectionIP"); Debug.Log("BtmManageer:" + PlayerPrefs.GetString("ConnectionIP")); YuanUnityPhoton.GetYuanUnityPhotonInstantiate().ServerApplication = PlayerPrefs.GetString("ConnectionApp"); YuanUnityPhoton.GetYuanUnityPhotonInstantiate().MMManage = MainMenuManage.my; YuanUnityPhoton.GetYuanUnityPhotonInstantiate().tableRead = TableRead.my; YuanUnityPhoton.GetYuanUnityPhotonInstantiate().Connect(); int tempNum = 0; while (true) { yield return(new WaitForSeconds(1)); tempNum++; if (tempNum >= mNum || YuanUnityPhoton.GetYuanUnityPhotonInstantiate().ServerConnected) { break; } } } }
IEnumerator Connect() { // serverAddress = serverAddress2; tableRead.strInfo = StaticLoc.Loc.Get("meg0101"); Ping ping = new Ping(serverAddress.Split(':')[0]); Ping ping2 = new Ping(serverAddress2.Split(':')[0]); int timeOut = 0; int p1 = 0; int p2 = 0; while (true) { if (ping.isDone || ping2.isDone) { break; } if (timeOut > 30) { break; } timeOut++; Debug.Log(string.Format("---------------------Ping:{0},{1};Ping2:{2},{3}", ping.isDone, ping.time, ping2.isDone, ping2.time)); yield return(new WaitForSeconds(0.1f)); } p1 = ping.time; p2 = ping2.time; Debug.Log(string.Format("---------------------PingEnd:{0},{1};Ping2:{2},{3}", ping.isDone, p1, ping2.isDone, p2)); if (p1 == -1 && p2 == -1) { tableRead.strInfo = StaticLoc.Loc.Get("meg0096"); //ShowConnectFail(StaticLoc.Loc.Get("meg0096")+StaticLoc.Loc.Get("meg0103")); tableRead.ReadTimeOut(StaticLoc.Loc.Get("meg0096") + StaticLoc.Loc.Get("meg0103")); } else if (p2 != -1 && p1 != -1) { if (p1 > p2) { serverAddress = serverAddress2; } } else if (p2 != -1) { serverAddress = serverAddress2; } ping.DestroyPing(); ping2.DestroyPing(); Debug.Log("===============ConnectIP:" + serverAddress); tableRead.strInfo = StaticLoc.Loc.Get("meg0095"); //NGUIDebug.Log ("--------------------------RadyConnect"); yuan.YuanClass.SwitchList(listBtnServer, false, true); // if(YuanUnityPhoton.GetYuanUnityPhotonInstantiate().ServerConnected) // { // // //YuanUnityPhoton.GetYuanUnityPhotonInstantiate().peer.Disconnect(); // ZealmConnector.closeConnection(); // while(YuanUnityPhoton.GetYuanUnityPhotonInstantiate().ServerConnected) // { // yield return new WaitForSeconds(0.1f); // } // } // // if(InRoom.GetInRoomInstantiate ().ServerConnected) // { // //InRoom.GetInRoomInstantiate().peer.Disconnect(); // ZealmConnector.closeConnection(); // while(InRoom.GetInRoomInstantiate ().ServerConnected) // { // yield return new WaitForSeconds(0.1f); // } // } ZealmConnector.closeConnection(); //try //{ //NGUIDebug.Log ("-------------------------------IP:"+serverAddress); YuanUnityPhoton.NewYuanUnityPhotonInstantiate().ServerAddress = serverAddress; // YuanUnityPhoton.NewYuanUnityPhotonInstantiate().ServerAddress = "117.131.207.219" + ":5059"; // YuanUnityPhoton.NewYuanUnityPhotonInstantiate().ServerAddress = "192.168.1.100" + ":5059"; YuanUnityPhoton.GetYuanUnityPhotonInstantiate().ServerApplication = "YuanPhotonServerRoom"; YuanUnityPhoton.GetYuanUnityPhotonInstantiate().MMManage = this.mmManage; YuanUnityPhoton.GetYuanUnityPhotonInstantiate().tableRead = this.tableRead; //NGUIDebug.Log ("--------------------------StratConnect"); YuanUnityPhoton.GetYuanUnityPhotonInstantiate().Connect(); PhotonHandler.ShowLog("SetConnectionIP:" + serverAddress); PlayerPrefs.SetString("ConnectionIP", serverAddress); while (!YuanUnityPhoton.GetYuanUnityPhotonInstantiate().ServerConnected) { yield return(new WaitForSeconds(0.1f)); } //NGUIDebug.Log ("--------------------------Connected"); if (StartGame) { StartGame = false; YuanUnityPhoton.GetYuanUnityPhotonInstantiate().SetPlayerBehavior(yuan.YuanPhoton.ConsumptionType.GameSchedule, ((int)GameScheduleType.OpenGame).ToString(), SystemInfo.deviceUniqueIdentifier); } // Debug.Log("Con2222222"); //} //catch(System.Exception ex) //{ //Debug.LogError (ex.ToString ()); //} /************************************************** * // if(InRoom.GetInRoomInstantiate ().peer.PeerState==ExitGames.Client.Photon.PeerStateValue.Connected) * // { * // InRoom.GetInRoomInstantiate().peer.Disconnect(); * // while(InRoom.GetInRoomInstantiate ().peer.PeerState!=ExitGames.Client.Photon.PeerStateValue.Disconnected) * // { * // yield return new WaitForSeconds(0.1f); * // } * // } *******************************************************/ try { InRoom.NewInRoomInstantiate(); } catch (System.Exception ex) { Debug.LogError(ex.ToString()); } PhotonNetwork.Disconnect(); }