public override void OnReceive(int subCode, object value) { switch (subCode) { case AccCode.ACC_LOGIN_SREP: SceneMesg sMesg = new SceneMesg(1, () => { Debug.Log("场景加载成功"); UserDto userDto = value as UserDto; if (userDto == null) { return; } Dispatch(AreaCode.UI, UIEvent.UI_CHANGE_ID, userDto.Account); //TODO 接受返回的数据刷新视图 Dispatch(AreaCode.UI, UIEvent.UI_REFRESH, userDto); }); Dispatch(AreaCode.SCENE, SceneEvent.SCENE_LOAD, sMesg); break; case AccCode.ACC_LOGIN_NOACC: Dispatch(AreaCode.UI, UIEvent.UI_LOGIN_NOACC, null); break; case AccCode.ACC_CREATE_SREP: SceneMesg sceneMesg = new SceneMesg(1, () => { UserDto userDto = value as UserDto; if (userDto == null) { return; } if (userDto.Account == "0") { return; } ShowToast.MakeToast("创建成功"); Dispatch(AreaCode.UI, UIEvent.UI_CHANGE_ID, userDto.Account); Dispatch(AreaCode.UI, UIEvent.UI_REFRESH, userDto); }); Dispatch(AreaCode.SCENE, SceneEvent.SCENE_LOAD, sceneMesg); break; case AccCode.ACC_RELOAD_SREP: SceneMesg Mesg = new SceneMesg(1, () => { Debug.Log("场景加载成功"); UserDto userDto = value as UserDto; if (userDto == null) { return; } Dispatch(AreaCode.UI, UIEvent.UI_CHANGE_ID, userDto.Account); //TODO 接受返回的数据刷新视图 Dispatch(AreaCode.UI, UIEvent.UI_REFRESH, userDto); }); Dispatch(AreaCode.SCENE, SceneEvent.SCENE_LOAD, Mesg); break; default: break; } }
public static void MatchNotFoundListener() { MatchNotFoundMessage.Listener = (message) => { Debug.Log("Couldn't find Match!"); ShowToast.MyShowToastMethod("Couldn't Find Match"); if (!MainMenu.friendList_canvas.GetComponent <CanvasGroup>().interactable) { MainMenu.friendList_canvas.GetComponent <CanvasGroup>().interactable = true; } if (MainMenu.challengeResponse_canvas.enabled) { MainMenu.challengeResponse_canvas.enabled = false; } MainMenu.searchingForPlayer_canvas.enabled = false; MainMenu.searchingForPlayer_anim.SetActive(false); MainMenu.searchingForPlayerTimeRemaining_text.enabled = false; MainMenu.isSearchingForPlayer = false; MainMenu.timeLeftToSearchPlayer = 60.0f; if (!LoginWithFB.FacebookLoggedIn) { MainMenu.messageBox_text.text = "Couldn't Find Match!"; MainMenu.messageBox_canvas.enabled = true; MainMenu.disableMessageBox = true; } }; }
public void Reset(bool askConfirmation) { Debug.Log("Reset "); if (Application.platform == RuntimePlatform.Android) { Debug.Log("Android"); if (askConfirmation) { Debug.Log("Confirmation required"); if (Time.realtimeSinceStartup - lastClicked > 1.5f) { Debug.Log("ShowToaster"); lastClicked = Time.realtimeSinceStartup; ShowToast toast = new ShowToast(); toast.showToastOnUiThread("Press again to restart game"); return; } } } NextQuestion(); SetAmounts(m_save.defaultFillAmounts); GetComponent <WinLoose>().RestartGame(); }
private void CheckIfUserisAlreadyLoggedIn() { if (Application.internetReachability != NetworkReachability.NotReachable) { //internet reachable if (Database.GetLoginStatus() == GameConstants.LOGGED_IN_WITH_GAMESPARK) { new AuthenticationRequest().SetUserName(Database.GetUserName()).SetPassword(Database.GetPassword()).Send((response) => { Register.userId = response.UserId; if (!response.HasErrors) { Debug.Log("Player Authenticated..."); Database.LoadPlayerDataFromGameSpark(); //change scene SceneManager.LoadScene(GameConstants.STARTMENU_SCENE); ShowToast.MyShowToastMethod("Player Logged In!"); } else { Debug.Log("Error Logging in Player!"); ShowToast.MyShowToastMethod("Error Logging in Player!"); SceneManager.LoadScene(GameConstants.REGISTER_SCENE); } }); } else if (Database.GetLoginStatus() == GameConstants.LOGGED_IN_WITH_FB) { if (!FB.IsInitialized) { Debug.Log("Initializing Facebook..."); FB.Init(ConnectGameSparksToGameSparks, null); } else { FB.ActivateApp(); ConnectGameSparksToGameSparks(); } } else { StartCoroutine(ChangeScene(GameConstants.REGISTER_SCENE)); } } else { // internet not reachable Debug.Log("Internet Not Reachable"); ShowToast.MyShowToastMethod("Internet Not Reachable!"); StartCoroutine(ChangeScene(GameConstants.REGISTER_SCENE)); } }
private void onClick() { if (isConnected) { string acc = PlayerPrefs.GetString("ID", "0"); socketMessage.Change(OpCode.ACCOUNT, AccCode.ACC_LOGIN_CREQ, acc); Dispatch(AreaCode.NET, 0, socketMessage); } else { ShowToast.MakeToast("无法接到服务器"); } }
private void Exit() { if (isExit) { Application.Quit(); NetManager.Instance.OffLine(); } else { ShowToast.MakeToast("再点一次就退出了"); isExit = true; StartCoroutine(CountDown()); } }
private void ResetPasswordCanvasContinueBtn() { if (Register.isSoundPlaying) { audioSource.Play(); } string token = resetPasswordCanvas_token.text; string newPassword = resetPasswordCanvas_newPassword.text; if (token == "") { ShowToast.MyShowToastMethod("Please Enter Token!"); return; } if (newPassword == "") { ShowToast.MyShowToastMethod("Please Enter New Password!"); return; } GSRequestData gSRequestData = new GSRequestData(); gSRequestData.AddString("action", "resetPassword"); gSRequestData.AddString("token", token); gSRequestData.AddString("password", newPassword); new GameSparks.Api.Requests.AuthenticationRequest().SetUserName("").SetPassword("").SetScriptData(gSRequestData).Send((response) => { Register.userId = response.UserId; if (response.Errors.GetString("action") == "complete") { ShowToast.MyShowToastMethod("Password Changed Successfully"); Debug.Log("Password Changed Successfully"); forgetPassword_canvas.enabled = false; resetPassword_canvas.enabled = false; createOne_btn.enabled = true; login_btn.interactable = true; playAsGuest_btn.interactable = true; } else { ShowToast.MyShowToastMethod("Error Resetting Password!"); Debug.Log(response.Errors.GetString("action")); forgetPassword_canvas.enabled = false; login_btn.interactable = true; createOne_btn.interactable = true; playAsGuest_btn.interactable = true; } }); }
public void Connect() { ShowToast.MakeToast("尝试连接到服务器"); try { socket.Connect(IP, PORT); ShowToast.MakeToast("连接服务器成功"); GameObject.Find("LoginButton").GetComponent <Login>().isConnected = true; StartReceive(); } catch (Exception ex) { // Debug.LogError(ex.Message); ShowToast.MakeToast("无法接到服务器"); } }
private void LoginUser() { if (Register.isSoundPlaying) { audioSource.Play(); } StartMenu.playAsGuest = false; string _username = USERNAME.text; string _password = PASSWORD.text; if (_username == "") { ShowToast.MyShowToastMethod("Enter you Username!"); return; } if (_password == "") { ShowToast.MyShowToastMethod("Enter you Password!"); return; } login_btn.interactable = false; Debug.Log("Authorizing Player....."); new GameSparks.Api.Requests.AuthenticationRequest().SetUserName(_username).SetPassword(_password).Send((response) => { Register.userId = response.UserId; if (!response.HasErrors) { Debug.Log("Player Authenticated..."); Database.LoadPlayerDataFromGameSpark(); //change scene SceneManager.LoadScene(GameConstants.STARTMENU_SCENE); ShowToast.MyShowToastMethod("Player Logged In!"); login_btn.interactable = true; } else { Debug.Log("Error Authenticating Player..."); ShowToast.MyShowToastMethod("Error in Authentication!"); login_btn.interactable = true; } }); }
public static void MatchFoundListener() { MatchFoundMessage.Listener = (message) => { if (LoginWithFB.FacebookLoggedIn) { isOppnentsImageID_received = false; messageToSend = LoginWithFB.url; } ShowToast.MyShowToastMethod("Match Made:"); GSEnumerable <MatchFoundMessage._Participant> participants = message.Participants; foreach (MatchFoundMessage._Participant i in participants) { playerNames[count] = i.DisplayName; playerIDs[count] = i.Id; count++; } }; }
private void ForgetPasswordContinueBtn() { if (Register.isSoundPlaying) { audioSource.Play(); } string userName = forgetPasswordUserName.text; string email = forgetPasswordEmail.text; if (userName == "") { ShowToast.MyShowToastMethod("Please Enter User Name!"); return; } if (email == "") { ShowToast.MyShowToastMethod("Please Enter Email Address!"); return; } GSRequestData gSRequestData = new GSRequestData(); gSRequestData.AddString("action", "passwordRecoveryRequest"); gSRequestData.AddString("email", email); new GameSparks.Api.Requests.AuthenticationRequest().SetUserName(userName).SetPassword("").SetScriptData(gSRequestData).Send((response) => { Register.userId = response.UserId; if (response.Errors.GetString("action") == "complete") { ShowToast.MyShowToastMethod("Request Sent! Check You Email"); Debug.Log("Request Sent! Check You Email"); forgetPassword.enabled = false; resetPassword_canvas.enabled = true; } else { ShowToast.MyShowToastMethod("Error Sending Requset!"); Debug.Log("Error Sending Requset! " + response.Errors.GetString("action")); } }); }
private void LoadImageFav() { for (int i = 0; i < App.ListFavorite.get_Count(); i++) { if (App.ListFavorite.get_Item(i).ChanelName.Equals(PlayVideo.ChanelPlayer.ChanelName)) { if (this._clickfav) { ShowToast.InitializeBasicToast(string.Concat("Bạn vừa thêm kênh : (", PlayVideo.ChanelPlayer.ChanelName, ") vào mục yêu thích")); } this.ImgFav.set_Source(new BitmapImage(new Uri("icon/fav.png", 0))); return; } if (this._clickfav) { ShowToast.InitializeBasicToast(string.Concat("Xóa kênh : (", PlayVideo.ChanelPlayer.ChanelName, ") khỏi mục kênh yêu thích")); } this.ImgFav.set_Source(new BitmapImage(new Uri("icon/unfav.png", 0))); } }
/// <summary> /// 收到数据后回调 /// </summary> /// <param name="ar"></param> private void ReceiveCallBack(IAsyncResult ar) { try { int length = socket.EndReceive(ar); byte[] tmpByteArray = new byte[length]; Buffer.BlockCopy(receiveBuffer, 0, tmpByteArray, 0, length); dataCache.AddRange(tmpByteArray); if (!isReceiveProcess) { ProcessReceive(); } StartReceive(); } catch (Exception ex) { Debug.LogError(ex.Message); //断线报错 //TODO 返回标题界面 ShowToast.MakeToast("与服务器连接断开"); } }
public void Update() { if (Input.GetKeyDown(KeyCode.Escape)) { if (Application.platform == RuntimePlatform.Android) { Debug.Log("Android"); Debug.Log("Confirmation required"); if (Time.realtimeSinceStartup - lastClicked > 1.5f) { Debug.Log("ShowToaster"); lastClicked = Time.realtimeSinceStartup; ShowToast toast = new ShowToast(); toast.showToastOnUiThread("Press again to exit."); return; } } #if UNITY_ANDROID // Get the unity player activity AndroidJavaObject activity = new AndroidJavaClass("com.unity3d.player.UnityPlayer") .GetStatic <AndroidJavaObject>("currentActivity"); // call activity's boolean moveTaskToBack(boolean nonRoot) function // documentation: http://developer.android.com/reference/android/app/Activity.html#moveTaskToBack(boolean) activity.Call <bool>("moveTaskToBack", true); #else Application.Quit(); #endif } }
private void Update() { if (gameRunning) { StartGame(); } //if (startTimer) //{ // ChangeTurnIfTimeExceeds(); //} //if (ActivateTurnTakenListener) //{ // ActivateTurnTakenListener = false; // StartCoroutine(TurnTakenListenerDelay()); //} if (!internetCheck && GameInitializer.GameType == GameConstants.ONLINE_MULTIPLAYER) { internetCheck = true; StartCoroutine(OnlineMultiplayer.checkInternetConnection((isConnected) => { // handle connection status here if (isConnected) { isNetworkAvaiable = true; internetCheck = false; } else { ShowToast.MyShowToastMethod("Netowrk Error!"); isNetworkAvaiable = false; internetCheck = false; } })); } }
private void RegisterUser() { if (isSoundPlaying) { buttonAudioSource.Play(); } StartMenu.playAsGuest = false; string _name = NAME.text; string _email = EMAIL.text; string _username = USERNAME.text; string _password = PASSWORD.text; string _countryName = countryName.text; if (_name == "") { ShowToast.MyShowToastMethod("Enter you Name!"); return; } if (_email == "") { ShowToast.MyShowToastMethod("Enter you Email!"); return; } if (_username == "") { ShowToast.MyShowToastMethod("Enter you Username!"); return; } if (_password == "") { ShowToast.MyShowToastMethod("Enter you Password!"); return; } Debug.Log("Registering User..."); register_btn.interactable = false; GSRequestData gSRequestData = new GSRequestData(); gSRequestData.Add("email", _email); new RegistrationRequest().SetDisplayName(_name).SetUserName(_username).SetPassword(_password).SetScriptData(gSRequestData).Send((response) => { if (!response.HasErrors) { Debug.Log("Player Registered"); ShowToast.MyShowToastMethod("Player registered successfully!"); userId = response.UserId; Database.setPlayerDataInGameSpark(_name, _countryName, "null"); Database.setPlayerDataInLocalDatabase(_name, _countryName, 5000, userId); Database.setAllWinsAndLosesToZero(userId); //change scene SceneManager.LoadScene(GameConstants.STARTMENU_SCENE); register_btn.interactable = true; Database.SetLoginStatus(GameConstants.LOGGED_IN_WITH_GAMESPARK); Database.SetUserName(_username); Database.SetPassword(_password); Database.SetDisplayName(_name); } else if (response.Errors.GetString("ERROR") == "Email in use!") { ShowToast.MyShowToastMethod("Email already in use!"); Debug.Log("Email already in use!"); register_btn.interactable = true; } else { Debug.Log("Error Registering Player"); ShowToast.MyShowToastMethod("Error Registering Player!"); register_btn.interactable = true; Debug.Log(response.Errors.GetString("ERROR")); } }); }
private void ConnectGameSparksToGameSparks() { if (FB.IsInitialized) { FB.ActivateApp(); Debug.Log("Logging Into Facebook..."); var perms = new List <string>() { "public_profile", "email", "user_friends" }; FB.LogInWithReadPermissions(perms, (result) => { if (FB.IsLoggedIn) { Debug.Log("Logged In, Connecting GS via FB.."); new GameSparks.Api.Requests.FacebookConnectRequest() .SetAccessToken(AccessToken.CurrentAccessToken.TokenString) .SetSyncDisplayName(true) .SetDoNotLinkToCurrentPlayer(true) // we don't want to create a new account so link to the player that is currently logged in .SetSwitchIfPossible(true) //this will switch to the player with this FB account id they already have an account from a separate login .Send((fbauth_response) => { if (!fbauth_response.HasErrors) { new AccountDetailsRequest().Send((response) => { LoginWithFB.fb_id = response.ExternalIds.GetString("FB"); LoginWithFB.id = response.UserId; Debug.Log("Ludo Challenge Authenticated With Facebook!"); ShowToast.MyShowToastMethod("Ludo Challenge Authenticated With FB!"); LoginWithFB.FacebookLoggedIn = true; LoginWithFB.displayName_FB = fbauth_response.DisplayName; LoginWithFB.countryName = Register.countryName.text; LoginWithFB.url = "http://graph.facebook.com/" + LoginWithFB.fb_id + "/picture?width=100&height=100"; StartCoroutine(DownloadFBImage(LoginWithFB.url)); Database.SetLoginStatus(GameConstants.LOGGED_IN_WITH_FB); Register.userId = LoginWithFB.id; }); } else { Debug.LogWarning(fbauth_response.Errors.JSON); //if we have errors, print them out } }); } else { Debug.LogWarning("Facebook Login Failed:" + result.Error); ShowToast.MyShowToastMethod("Facebook Login Failed!"); LoginWithFB.FacebookLoggedIn = false; SceneManager.LoadScene(GameConstants.REGISTER_SCENE); } });// lastly call another method to login, and when logged in we have a callback } else { if (!FB.IsInitialized) { Debug.Log("Initializing Facebook..."); FB.Init(ConnectGameSparksToGameSparks, null); } else { FB.ActivateApp(); ConnectGameSparksToGameSparks(); } } }
public static void ChatOnChallegeListener() { ChallengeChatMessage.Listener = (message) => { chat_message = ""; if (message.Message.Contains("////")) { int j = 0; for (int i = 0; i < message.Message.Length; i++) { if (message.Message[i] == ' ' && message.Message[i + 1] == ' ' && message.Message[i + 2] == ' ') { j = i + 3; for (int k = j; k < message.Message.Length; k++) { chat_message = chat_message + message.Message[k]; } break; } } if (chat_message == "EndGame") { if (GameInitializer.NoOfPlayers == GameConstants.TWO_PLAYERS) { if (GameInitializer.messageToSend != "EndGame") { GameInitializer.SetValues_YouWin(); Debug.Log("You Oppenent Left The Game!"); ShowToast.MyShowToastMethod("Your opponent left the Game!"); } } else { GameObject game_manager = GameObject.FindGameObjectWithTag(GameConstants.GAME_MANAGER); if (message.Message.Contains(GameInitializer.Player2Name.text)) { Debug.Log(GameInitializer.Player2Name.text + " left the Game!"); ShowToast.MyShowToastMethod(GameInitializer.Player2Name.text + " left the Game!"); game_manager.GetComponent <GameInitializer>().player[1].SetActive(false); GameInitializer.player2_out = true; } else if (message.Message.Contains(GameInitializer.Player3Name.text)) { Debug.Log(GameInitializer.Player3Name.text + " left the Game!"); ShowToast.MyShowToastMethod(GameInitializer.Player3Name.text + " left the Game!"); game_manager.GetComponent <GameInitializer>().player[2].SetActive(false); GameInitializer.player3_out = true; } else if (message.Message.Contains(GameInitializer.Player4Name.text)) { Debug.Log(GameInitializer.Player4Name.text + " left the Game!"); ShowToast.MyShowToastMethod(GameInitializer.Player4Name.text + " left the Game!"); game_manager.GetComponent <GameInitializer>().player[3].SetActive(false); GameInitializer.player4_out = true; } } } for (int i = 0; i < opponents_name.Count; i++) { if (message.Message.Contains(opponents_name[i])) { if (GameInitializer.Player2Name.text == opponents_name[i]) { GameInitializer.player2Message = true; } else if (GameInitializer.Player3Name.text == opponents_name[i]) { GameInitializer.player3Message = true; } else if (GameInitializer.Player4Name.text == opponents_name[i]) { GameInitializer.player4Message = true; } } } return; } counter++; string name = "", id = ""; bool nameChecked = false; for (int i = 0; i < message.Message.Length; i++) { if (message.Message[i] != '/' && !nameChecked) { name = name + message.Message[i]; } if (nameChecked) { id = id + message.Message[i]; } if (message.Message[i] == '/') { nameChecked = true; } } Debug.Log(message.Message); if (LoginWithFB.FacebookLoggedIn) { nameChecked = false; if (name != LoginWithFB.displayName_FB) { Debug.Log("Oppenent Name: " + name); Debug.Log("Oppenent ID: " + id); opponents_name.Add(name); opponents_image_ids.Add(id); } } else { nameChecked = false; opponents_name.Add(name); opponents_image_ids.Add(id); } if (GameInitializer.NoOfPlayers == 2 && counter >= 2) { isOppnentsImageID_received = true; if (LoginWithFB.FacebookLoggedIn) { try { if (MainMenu.challengeResponse_canvas.enabled) { MainMenu.challengeResponse_canvas.enabled = false; } } catch (Exception e) { Debug.Log(e.Message); } } else { //MainMenu.searchingForPlayer_canvas.enabled = false; //MainMenu.searchingForPlayer_anim.SetActive(false); } //SceneManager.LoadScene("GamePlay"); StartMenu.startGame = true; } else if (GameInitializer.NoOfPlayers == 4 && counter >= 4) { //Start Game isOppnentsImageID_received = true; //MainMenu.searchingForPlayer_canvas.enabled = false; //MainMenu.searchingForPlayer_anim.SetActive(false); //SceneManager.LoadScene("GamePlay"); StartMenu.startGame = true; } }; }
private void CopyCode() { GUIUtility.systemCopyBuffer = PlayerPrefs.GetString("ID"); ShowToast.MakeToast("已复制到剪贴板"); }
public static void ChallengeTurnTakenListener() { ChallengeTurnTakenMessage.Listener = (message) => { Debug.Log(message.Who + " has taken his turn!"); GameInitializer.fillAmount = 0.92f; ChallengeTurnTakenMessage._Challenge challenge_data = message.Challenge; playerTurn_UserId = challenge_data.NextPlayer; GameObject game_Manager = GameObject.FindGameObjectWithTag(GameConstants.GAME_MANAGER); if ((GameInitializer.GameType == GameConstants.ONLINE_MULTIPLAYER && GameInitializer.NoOfPlayers == GameConstants.FOUR_PLAYERS && GameController.playerTurn == 0)) { GameController.playerTurn = game_Manager.GetComponent <PlayerActivation>().ChangePlayer(GameController.playerTurn); game_Manager.GetComponent <GameController>().dice = GameObject.FindGameObjectWithTag(GameConstants.PLAYER_DICE[GameController.playerTurn]); game_Manager.GetComponent <GameController>().checkLoop_AI_Dice = false; game_Manager.GetComponent <GameController>().checkLoop_AI_Marker = false; GameController.checkChangeTurn = false; GameController.GAME_STATE = GameConstants.DICE_ROLL; } who = message.Who; Debug.Log(who + " has taken his turn!"); if (who != MakeAMatch.displayName) { GSData scriptData = message.Challenge.ScriptData.GetGSData("data"); int diceValue = (int)scriptData.GetInt("d"); points = (int)scriptData.GetInt("p"); GameInitializer.points = points; //set points GameObject game_manager = GameObject.FindGameObjectWithTag(GameConstants.GAME_MANAGER); //Exit turn of leaving player if (GameInitializer.NoOfPlayers == 2 && points == 0) { GameInitializer.SetValues_YouWin(); Debug.Log("You Oppenent Left The Game!"); ShowToast.MyShowToastMethod("Your opponent left the Game!"); } if (points == 0) { game_manager.GetComponent <GameInitializer>().ChangeTurn(0); } if (who == GameInitializer.Player2Name.text) { game_manager.GetComponent <GameInitializer>().player2Points_text.text = "" + points; if (points == 0) { game_manager.GetComponent <GameInitializer>().player[1].SetActive(false); GameInitializer.player2_out = true; } } else if (who == GameInitializer.Player3Name.text) { game_manager.GetComponent <GameInitializer>().player3Points_text.text = "" + points; if (points == 0) { game_manager.GetComponent <GameInitializer>().player[2].SetActive(false); GameInitializer.player3_out = true; } } else if (who == GameInitializer.Player4Name.text) { game_manager.GetComponent <GameInitializer>().player4Points_text.text = "" + points; if (points == 0) { game_manager.GetComponent <GameInitializer>().player[3].SetActive(false); GameInitializer.player4_out = true; } } if (diceValue == -1) { GameObject gameController = GameObject.FindGameObjectWithTag(GameConstants.GAME_MANAGER); gameController.GetComponent <GameInitializer>().ChangeTurn(1); } else { markerNo_list.Add((int)scriptData.GetInt("m")); dice_value_list.Add((int)scriptData.GetInt("d")); Debug.Log("Counter: " + counter); if (counter == 0) { MoveOpponent(markerNo_list[counter], dice_value_list[counter]); } } } }; }