ResultObject.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. using Photon.Pun;
  6. using Photon.Realtime;
  7. using System;
  8. public class ResultObject : MonoBehaviour
  9. {
  10. [SerializeField] Image WinImage;
  11. [SerializeField] Image LoseImage;
  12. [SerializeField] Text ResultText;
  13. public void Init()
  14. {
  15. this.gameObject.SetActive(false);
  16. }
  17. public void ShowResult(Player Winner, bool Surrendered, string effectName = "")
  18. {
  19. this.gameObject.SetActive(true);
  20. string log = "";
  21. log += "\nEnd Game";
  22. if (Winner != null)
  23. {
  24. log += $"\nWinner:{Winner.PlayerName}";
  25. }
  26. ResultText.text = "";
  27. if (String.IsNullOrEmpty(effectName))
  28. {
  29. log += $"\nEffect:{effectName}";
  30. ResultText.text = effectName;
  31. }
  32. if (Winner == GManager.instance.You)
  33. {
  34. ContinuousController.instance.PlaySE(GManager.instance.WinSE);
  35. WinImage.gameObject.SetActive(true);
  36. LoseImage.gameObject.SetActive(false);
  37. if (!GManager.instance.IsAI)
  38. {
  39. ContinuousController.instance.WinCount++;
  40. ContinuousController.instance.SaveWinCount();
  41. if (Surrendered)
  42. ResultText.text = "The opponent has surrendered.";
  43. }
  44. }
  45. else if (Winner != null)
  46. {
  47. ContinuousController.instance.PlaySE(GManager.instance.LoseSE);
  48. WinImage.gameObject.SetActive(false);
  49. LoseImage.gameObject.SetActive(true);
  50. if (Winner != null)
  51. {
  52. if (Surrendered)
  53. ResultText.text = "You have surrendered.";
  54. }
  55. }
  56. else
  57. {
  58. WinImage.gameObject.SetActive(false);
  59. LoseImage.gameObject.SetActive(true);
  60. bool isDisconnected = true;
  61. if (PhotonNetwork.IsConnected)
  62. {
  63. if (PhotonNetwork.PlayerList.Length == 2)
  64. {
  65. isDisconnected = false;
  66. }
  67. if (GManager.instance.IsAI)
  68. {
  69. isDisconnected = false;
  70. }
  71. WinImage.gameObject.SetActive(true);
  72. LoseImage.gameObject.SetActive(false);
  73. }
  74. if (isDisconnected)
  75. {
  76. log += $"\nDisconnected";
  77. ResultText.text = "Disconnected.";
  78. }
  79. else
  80. {
  81. log += $"\nDraw";
  82. ResultText.text = "Draw.";
  83. }
  84. }
  85. GManager.instance.playLog.AddLogString(log);
  86. }
  87. }