PKGameSettleView.cs 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. using UnityEngine.SceneManagement;
  6. /* PK模式的结算界面 */
  7. public class PKGameSettleView : MonoBehaviour
  8. {
  9. void Start()
  10. {
  11. GameMode gameMode = GameMgr.ins.gameMode;
  12. if (PKGameView.ins) {
  13. PKGameView.ins.gameObject.SetActive(false);
  14. }
  15. string[] results = (string[]) gameMode.Settle();
  16. for (int i = 1; i <= 2; i++) {
  17. if (GlobalData.pkMatchType == PKMatchType.OnlinePK) {
  18. int playerIndex = i - 1;
  19. (Sprite avatar, string nickName) = RoleMgr.GetRoleInfo(GlobalData.matchPlayerInfos[playerIndex].avatarID);
  20. nickName = GlobalData.matchPlayerInfos[playerIndex].nickname;
  21. this.transform.Find("Avatar" + i + "/Sprite").GetComponent<Image>().sprite = avatar;
  22. this.transform.Find("Name" + i).GetComponent<Text>().text = nickName;
  23. } else if (GlobalData.pkMatchType == PKMatchType.LocalPK) {
  24. (Sprite avatar, string nickName) = RoleMgr.GetRoleInfo(PKGameMode.playerRoleIDs[i - 1]);
  25. this.transform.Find("Avatar" + i + "/Sprite").GetComponent<Image>().sprite = avatar;
  26. this.transform.Find("Name" + i).GetComponent<Text>().text = nickName;
  27. }
  28. this.transform.Find("Win" + i).gameObject.SetActive(results[i - 1] == "胜利");
  29. this.transform.Find("Fail" + i).gameObject.SetActive(results[i - 1] == "失败");
  30. if (GlobalData.pkMatchType == PKMatchType.LocalPK) {
  31. this.transform.Find("Score" + i + "/Text").GetComponent<Text>().text = ((PKGameMode)gameMode).totalScores[i - 1].ToString();
  32. } else if (GlobalData.pkMatchType == PKMatchType.OnlinePK) {
  33. this.transform.Find("Score" + i + "/Text").GetComponent<Text>().text = ((PKGameMode_OnlinePK)gameMode).gameLogic.totalScores[i - 1].ToString();
  34. }
  35. }
  36. AudioMgr.ins.PlayWin();
  37. if (GlobalData.pkMatchType == PKMatchType.OnlinePK) {
  38. int gameRes = 2;
  39. if (results[0] == "胜利") {
  40. gameRes = 0;
  41. } else if (results[1] == "胜利") {
  42. gameRes = 1;
  43. }
  44. try {
  45. RankComp.ins.uploadPKGameRes(gameRes);
  46. } catch (System.Exception e) { Debug.LogError(e.Message); }
  47. }
  48. if (GlobalData.pkMatchType == PKMatchType.OnlinePK) {
  49. if (SocketPlayer.ins) SocketPlayer.ins.isGameOver = true;
  50. }
  51. SimulateMouseController.ins?.AddOpenLocker("NotGame");
  52. }
  53. public void GoHome() {
  54. AudioMgr.ins.PlayBtn();
  55. GoHomeLogic();
  56. }
  57. private void GoHomeLogic() {
  58. SceneManager.LoadScene("Home", LoadSceneMode.Single);
  59. HomeMgr.DestroyCacheViews();
  60. }
  61. JC.CS.Throttler throttlerTryAgainOnline = new JC.CS.Throttler(3000);
  62. public void TryAgain() {
  63. AudioMgr.ins.PlayBtn();
  64. if (GameAssistUI.ins) GameAssistUI.ins.recordPlayerRecordsWhenGameTryAgain();
  65. if (GlobalData.pkMatchType == PKMatchType.OnlinePK) {
  66. if (throttlerTryAgainOnline.CanPass() == false) {
  67. PopupMgr.ins.ShowTip(TextAutoLanguage2.GetTextByCNKey("操作过于频繁"));
  68. return;
  69. }
  70. PKMatchingView view = PKMatchingView.Create();
  71. view.InitForInviterToTryAgain();
  72. view.eventOnRejectPKInvite += () => {
  73. view.banBackBtnLogic = true;
  74. DoTweenUtil.CallDelay(2f, GoHomeLogic);
  75. };
  76. } else {
  77. SceneManager.LoadScene("Game", LoadSceneMode.Single);
  78. }
  79. }
  80. }