PKGameSettleView.cs 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. }
  52. public void GoHome() {
  53. AudioMgr.ins.PlayBtn();
  54. GoHomeLogic();
  55. }
  56. private void GoHomeLogic() {
  57. SceneManager.LoadScene("Home", LoadSceneMode.Single);
  58. HomeMgr.DestroyCacheViews();
  59. }
  60. JC.CS.Throttler throttlerTryAgainOnline = new JC.CS.Throttler(3000);
  61. public void TryAgain() {
  62. AudioMgr.ins.PlayBtn();
  63. if (GameAssistUI.ins) GameAssistUI.ins.recordPlayerRecordsWhenGameTryAgain();
  64. if (GlobalData.pkMatchType == PKMatchType.OnlinePK) {
  65. if (throttlerTryAgainOnline.CanPass() == false) {
  66. PopupMgr.ins.ShowTip(TextAutoLanguage2.GetTextByCNKey("操作过于频繁"));
  67. return;
  68. }
  69. PKMatchingView view = PKMatchingView.Create();
  70. view.InitForInviterToTryAgain();
  71. view.eventOnRejectPKInvite += () => {
  72. view.banBackBtnLogic = true;
  73. DoTweenUtil.CallDelay(2f, GoHomeLogic);
  74. };
  75. } else {
  76. SceneManager.LoadScene("Game", LoadSceneMode.Single);
  77. }
  78. }
  79. }