JCFruitMaster.cs 3.3 KB

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