ResultObject.cs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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. if (String.IsNullOrEmpty(effectName))
  44. ResultText.text = effectName;
  45. }
  46. }
  47. else if (Winner != null)
  48. {
  49. ContinuousController.instance.PlaySE(GManager.instance.LoseSE);
  50. WinImage.gameObject.SetActive(false);
  51. LoseImage.gameObject.SetActive(true);
  52. if (Winner != null)
  53. {
  54. if (Surrendered)
  55. ResultText.text = "You have surrendered.";
  56. }
  57. }
  58. else
  59. {
  60. WinImage.gameObject.SetActive(false);
  61. LoseImage.gameObject.SetActive(true);
  62. bool isDisconnected = true;
  63. if (PhotonNetwork.IsConnected)
  64. {
  65. if (PhotonNetwork.PlayerList.Length == 2)
  66. {
  67. isDisconnected = false;
  68. }
  69. if (GManager.instance.IsAI)
  70. {
  71. isDisconnected = false;
  72. }
  73. WinImage.gameObject.SetActive(true);
  74. LoseImage.gameObject.SetActive(false);
  75. }
  76. if (isDisconnected)
  77. {
  78. log += $"\nDisconnected";
  79. ResultText.text = "Disconnected.";
  80. }
  81. else
  82. {
  83. log += $"\nDraw";
  84. ResultText.text = "Draw.";
  85. }
  86. }
  87. PlayLog.OnAddLog?.Invoke(log);
  88. }
  89. }