PKGameSettleView.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. int avatarID = GlobalData.matchPlayerInfos[playerIndex].avatarID;
  20. string avatarUrl = GlobalData.matchPlayerInfos[playerIndex].avatarUrl;
  21. string nickName = GlobalData.matchPlayerInfos[playerIndex].nickname;
  22. RoleMgr.SetAvatarToImage(this.transform.Find("Avatar" + i + "/Sprite").GetComponent<Image>(),
  23. avatarID, avatarUrl);
  24. //this.transform.Find("Name" + i).GetComponent<Text>().text = nickName;
  25. TextEllipsis.SetTextWithEllipsis(transform.Find("Name" + i).GetComponent<Text>(), nickName);
  26. } else if (GlobalData.pkMatchType == PKMatchType.LocalPK) {
  27. string nickName = RoleMgr.GetRoleInfo(PKGameMode.playerRoleIDs[i - 1],
  28. this.transform.Find("Avatar" + i + "/Sprite").GetComponent<Image>());
  29. //this.transform.Find("Name" + i).GetComponent<Text>().text = nickName;
  30. TextEllipsis.SetTextWithEllipsis(transform.Find("Name" + i).GetComponent<Text>(), nickName);
  31. }
  32. this.transform.Find("Win" + i).gameObject.SetActive(results[i - 1] == "胜利");
  33. //this.transform.Find("Fail" + i).gameObject.SetActive(results[i - 1] == "失败");
  34. if (GlobalData.pkMatchType == PKMatchType.LocalPK) {
  35. this.transform.Find("Score" + i + "/Text").GetComponent<Text>().text = ((PKGameMode)gameMode).totalScores[i - 1].ToString();
  36. } else if (GlobalData.pkMatchType == PKMatchType.OnlinePK) {
  37. this.transform.Find("Score" + i + "/Text").GetComponent<Text>().text = ((PKGameMode_OnlinePK)gameMode).gameLogic.totalScores[i - 1].ToString();
  38. }
  39. }
  40. AudioMgr.ins.PlayWin();
  41. if (GlobalData.pkMatchType == PKMatchType.OnlinePK) {
  42. int gameRes = 2;
  43. if (results[0] == "胜利") {
  44. gameRes = 0;
  45. } else if (results[1] == "胜利") {
  46. gameRes = 1;
  47. }
  48. try {
  49. RankComp.Instance.uploadPKGameRes(gameRes);
  50. } catch (System.Exception e) { Debug.LogError(e.Message); }
  51. }
  52. if (GlobalData.pkMatchType == PKMatchType.OnlinePK) {
  53. if (SocketPlayer.ins) SocketPlayer.ins.isGameOver = true;
  54. }
  55. SimulateMouseController.ins?.AddOpenLocker("NotGame");
  56. GameOverInterface.OnGameOver(GameMgr.gameType);
  57. }
  58. public void OnClick_Back() {
  59. AudioMgr.ins.PlayBtn();
  60. GoHomeLogic();
  61. }
  62. private void GoHomeLogic() {
  63. //SceneManager.LoadScene("Home", LoadSceneMode.Single);
  64. GameMgr.ins.gameMode.gameMgr.userGameAnalyse.showResultView(() => {
  65. SceneManager.LoadScene("Home", LoadSceneMode.Single);
  66. });
  67. }
  68. JCUnityLib.Throttler throttlerTryAgainOnline = new JCUnityLib.Throttler(3000);
  69. public void OnClick_Again() {
  70. AudioMgr.ins.PlayBtn();
  71. if (GameAssistUI.ins) GameAssistUI.ins.recordPlayerRecordsWhenGameTryAgain();
  72. if (GlobalData.pkMatchType == PKMatchType.OnlinePK) {
  73. if (throttlerTryAgainOnline.CanPass() == false) {
  74. PopupMgr.ins.ShowTip(TextAutoLanguage2.GetTextByCNKey("操作过于频繁"));
  75. return;
  76. }
  77. PKMatchingView view = PKMatchingView.Create();
  78. view.InitForInviterToTryAgain();
  79. view.eventOnRejectPKInvite += () => {
  80. view.banBackBtnLogic = true;
  81. DoTweenUtil.CallDelay(2f, GoHomeLogic);
  82. };
  83. } else {
  84. SceneManager.LoadScene("Game", LoadSceneMode.Single);
  85. }
  86. }
  87. }