JCFruitMaster.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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) SetVisiable(onlyShow && !SB_EventSystem.ins.simulateMouseIsAwaked);
  61. }
  62. }
  63. public void ResetAim()
  64. {
  65. if (_needMouseAwaked)
  66. {
  67. AimHandler.ins?.DoIdentity();
  68. }
  69. else
  70. {
  71. AutoResetView.DoIdentity();
  72. }
  73. }
  74. #region 显示和隐藏准心
  75. void SetVisiable(bool value)
  76. {
  77. if (visiable == value) return;
  78. visiable = value;
  79. //Debug.Log("AimingCross_img.enabled :" + visiable);
  80. aimingCross.enabled = visiable;
  81. //Debug.Log("AimingCross_img.enabled :" + aimingCross.enabled);
  82. }
  83. public void SetOpen(bool open)
  84. {
  85. this.open = open;
  86. if (!this.open)
  87. {
  88. SetVisiable(false);
  89. }
  90. }
  91. public bool GetOpen()
  92. {
  93. return this.open;
  94. }
  95. public void SetOnlyShow(bool onlyShow)
  96. {
  97. this.onlyShow = onlyShow;
  98. Debug.Log("AimingCross_img.onlyShow :" + this.onlyShow);
  99. }
  100. public bool GetOnlyShow()
  101. {
  102. return this.onlyShow;
  103. }
  104. #endregion
  105. }