ResultObject.cs 2.4 KB

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