JCFruitMaster.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. public class JCFruitMaster : MonoBehaviour
  6. {
  7. [SerializeField] Canvas menuUI;
  8. [SerializeField] Canvas gamingUI;
  9. [SerializeField] GameObject btnStart;
  10. [SerializeField] GameObject btnResume;
  11. bool _mouseAwaked = true;
  12. bool _needMouseAwaked;
  13. [SerializeField] Image aimingCross;
  14. private bool open = false;
  15. private bool visiable = false;
  16. private bool onlyShow = true;
  17. public static JCFruitMaster ins;
  18. void Start()
  19. {
  20. ins = this;
  21. menuUI.sortingOrder = 4;
  22. gamingUI.sortingOrder = 4;
  23. gamingUI.transform.Find("PauseExitBack/ExitBtn").gameObject.SetActive(false);
  24. gamingUI.transform.Find("PauseExitBack/PauseBtn").gameObject.SetActive(false);
  25. CrossHairOutBoundChecker1 outBoundChecker = Instantiate(Resources.Load<GameObject>("Prefabs/CrossHairOutBoundChecker1")).GetComponent<CrossHairOutBoundChecker1>();
  26. outBoundChecker.crossHair = aimingCross.transform as RectTransform;
  27. //this.open = UserSettings.ins.openCrossHair;
  28. SetOpen(UserSettings.ins.openCrossHair);
  29. //this.visiable = aimingCross.enabled;
  30. visiable = open;
  31. aimingCross.enabled = open;
  32. //读取准心值
  33. if (AimHandler.ins&&!AimHandler.ins.bRuning9Axis() && InfraredDemo._ins) SetOnlyShow(InfraredDemo._ins.getCrosshairValue() == 1);
  34. }
  35. void OnDestroy()
  36. {
  37. if (ins == this) ins = null;
  38. }
  39. void Update()
  40. {
  41. _needMouseAwaked = btnStart.activeInHierarchy || btnResume.activeInHierarchy;
  42. if (_mouseAwaked && !_needMouseAwaked)
  43. {
  44. SimulateMouseController.ins?.RemoveOpenLocker("NotGame");
  45. _mouseAwaked = false;
  46. }
  47. else if (!_mouseAwaked && _needMouseAwaked)
  48. {
  49. SimulateMouseController.ins?.AddOpenLocker("NotGame");
  50. _mouseAwaked = true;
  51. }
  52. //aimingCross.enabled = !SB_EventSystem.ins.simulateMouseIsAwaked;
  53. if (AutoResetView.ins != null)
  54. {
  55. //进入校准时候,一定显示准心
  56. SetVisiable(true);
  57. }
  58. else
  59. {
  60. if (open)
  61. SetVisiable(onlyShow && !SB_EventSystem.ins.simulateMouseIsAwaked);
  62. else
  63. SetVisiable(false);
  64. }
  65. }
  66. public void ResetAim()
  67. {
  68. if (_needMouseAwaked)
  69. {
  70. AimHandler.ins?.DoIdentity();
  71. }
  72. else
  73. {
  74. AutoResetView.DoIdentity();
  75. }
  76. }
  77. #region 显示和隐藏准心
  78. void SetVisiable(bool value)
  79. {
  80. if (visiable == value) return;
  81. visiable = value;
  82. //Debug.Log("AimingCross_img.enabled :" + visiable);
  83. aimingCross.enabled = visiable;
  84. //Debug.Log("AimingCross_img.enabled :" + aimingCross.enabled);
  85. }
  86. public void SetOpen(bool open)
  87. {
  88. this.open = open;
  89. if (!this.open)
  90. {
  91. SetVisiable(false);
  92. }
  93. }
  94. public bool GetOpen()
  95. {
  96. return this.open;
  97. }
  98. public void SetOnlyShow(bool onlyShow)
  99. {
  100. this.onlyShow = onlyShow;
  101. Debug.Log("AimingCross_img.onlyShow :" + this.onlyShow);
  102. }
  103. public bool GetOnlyShow()
  104. {
  105. return this.onlyShow;
  106. }
  107. #endregion
  108. }