JCFruitMaster.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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 (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. AutoResetView.DoIdentity();
  71. }
  72. }
  73. #region 显示和隐藏准心
  74. void SetVisiable(bool value)
  75. {
  76. if (visiable == value) return;
  77. visiable = value;
  78. //Debug.Log("AimingCross_img.enabled :" + visiable);
  79. aimingCross.enabled = visiable;
  80. //Debug.Log("AimingCross_img.enabled :" + aimingCross.enabled);
  81. }
  82. public void SetOpen(bool open)
  83. {
  84. this.open = open;
  85. if (!this.open)
  86. {
  87. SetVisiable(false);
  88. }
  89. }
  90. public bool GetOpen()
  91. {
  92. return this.open;
  93. }
  94. public void SetOnlyShow(bool onlyShow)
  95. {
  96. this.onlyShow = onlyShow;
  97. Debug.Log("AimingCross_img.onlyShow :" + this.onlyShow);
  98. }
  99. public bool GetOnlyShow()
  100. {
  101. return this.onlyShow;
  102. }
  103. #endregion
  104. }