PKGameSettleViewNew.cs 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.SceneManagement;
  5. using UnityEngine.UI;
  6. public class PKGameSettleViewNew : MonoBehaviour
  7. {
  8. // Start is called before the first frame update
  9. void OnEnable()
  10. {
  11. SimulateMouseController.ins?.AddOpenLocker(this);
  12. int[] pkResults = { 0, 0 };
  13. var gc = GameController.ins;
  14. if (gc.scores[0] > gc.scores[1])
  15. {
  16. pkResults[0] = 1;
  17. pkResults[1] = -1;
  18. }
  19. else if (gc.scores[0] < gc.scores[1])
  20. {
  21. pkResults[0] = -1;
  22. pkResults[1] = 1;
  23. }
  24. for (int i = 1; i <= 2; i++)
  25. {
  26. int index = i - 1;
  27. transform.Find("Win" + i).gameObject.SetActive(pkResults[index] == 1);
  28. transform.Find("Fail" + i).gameObject.SetActive(pkResults[index] == -1);
  29. transform.Find("Draw" + i).gameObject.SetActive(pkResults[index] == 0);
  30. string _format = "F" + CommonConfig.ringsPrecision; //显示保留一位小数
  31. transform.Find("Score" + i + "/Text").GetComponent<Text>().text = gc.scores[index].ToString(_format);
  32. }
  33. }
  34. void OnDisable()
  35. {
  36. SimulateMouseController.ins?.RemoveOpenLocker(this);
  37. }
  38. public void OnClick_Again()
  39. {
  40. gameObject.SetActive(false);
  41. AudioMgr.ins.PlayBtn();
  42. GameController.ins.InitGame();
  43. GameController.ins.HandleSelectDistance(GameController.ins.targetDistance);
  44. //清除箭矢,1p 和 2p
  45. foreach (var arrow in ArrowNew2.arrowSet)
  46. {
  47. try
  48. {
  49. GameObject.Destroy(arrow.gameObject);
  50. }
  51. catch (UnityException e)
  52. {
  53. Debug.Log("Delete Arrow Error\n" + e.Message);
  54. }
  55. }
  56. //重新load game
  57. //SceneManager.LoadScene("GameDouble", LoadSceneMode.Single);
  58. }
  59. public void OnClick_Back()
  60. {
  61. gameObject.SetActive(false);
  62. AudioMgr.ins.PlayBtn();
  63. //重新load game
  64. SceneManager.LoadScene("GameDouble", LoadSceneMode.Single);
  65. //GameController.ins.InitGame();
  66. //GameController.ins.SetDisplayDistanceSelectView(true);
  67. }
  68. }