UIManagerSingle.cs 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.SceneManagement;
  5. using UnityEngine.UI;
  6. namespace InfraredManager
  7. {
  8. public class UIManagerSingle : MonoBehaviour
  9. {
  10. //连接弓箭按钮
  11. public Button mConnectBow;
  12. private Text mConnectBowText;
  13. //滚动的日志
  14. public GameObject logObj;
  15. public Text mScrollViewLogTextBow;
  16. private int bowLogTextCount = 0;
  17. //清空日志按钮
  18. public Button mClearLogBow;
  19. public Button mControlLogBtn;
  20. //进入野鸭模拟场景按钮
  21. public Button EnterDuckHunterBtn;
  22. //进入射箭模拟场景按钮
  23. public Button EnterGameBtn;
  24. //发送数据
  25. public Toggle SyncVector;
  26. #region 需要隐藏的面板节点
  27. public GameObject[] uiArray;
  28. public bool bGetPanelActive
  29. {
  30. get {
  31. return bPanelActive;
  32. }
  33. }
  34. bool bPanelActive = true;
  35. #endregion
  36. #region 需要调整的材质信息
  37. [Range(0.1f, 3.0f)]
  38. public float brightness = 1.0f; // 亮度
  39. public Slider brightnessSlider;
  40. public Text brightnessText;
  41. [Range(0.1f, 3.0f)]
  42. public float saturation = 1.0f; // 饱和度
  43. public Slider saturationSlider;
  44. public Text saturationText;
  45. [Range(0.1f, 3.0f)]
  46. public float contrast = 1.0f; // 对比度
  47. public Slider contrastSlider;
  48. public Text contrastText;
  49. public Material material; // 材质
  50. //亮度
  51. public void SliderBrightness()
  52. {
  53. var _value = brightnessSlider.value;
  54. brightness = ((int)(_value * 10)) / 10.0f;
  55. brightnessText.text = brightness + "";
  56. material.SetFloat("_Brightness", brightness); // 设置亮度
  57. }
  58. //饱和度
  59. public void SliderSaturation()
  60. {
  61. var _value = saturationSlider.value;
  62. saturation = ((int)(_value * 10)) / 10.0f;
  63. saturationText.text = saturation + "";
  64. material.SetFloat("_Saturation", saturation); // 设置饱和度
  65. }
  66. //对比度
  67. public void SliderContrast()
  68. {
  69. var _value = contrastSlider.value;
  70. contrast = ((int)(_value * 10)) / 10.0f;
  71. contrastText.text = contrast + "";
  72. material.SetFloat("_Contrast", contrast); // 设置对比度
  73. }
  74. public void onReset() {
  75. brightnessSlider.value = 1.0f;
  76. saturationSlider.value = 1.0f;
  77. contrastSlider.value = 1.0f;
  78. SliderBrightness();
  79. SliderSaturation();
  80. SliderContrast();
  81. }
  82. #endregion
  83. void Awake()
  84. {
  85. if (ConnetDevicesSingle.ins)
  86. ConnetDevicesSingle.ins.OnLogAction += SetLogText;
  87. Debug.Log("SetLogText!");
  88. }
  89. // Start is called before the first frame update
  90. void Start()
  91. {
  92. mConnectBow.onClick.AddListener(onConnectBowDevice);
  93. mConnectBowText = mConnectBow.GetComponentInChildren<Text>();
  94. mClearLogBow.onClick.AddListener(clearLogText);
  95. mControlLogBtn.onClick.AddListener(onControlLog);
  96. EnterGameBtn.onClick.AddListener(enterGame);
  97. EnterDuckHunterBtn.onClick.AddListener(enterDuckHunter);
  98. EnterDuckHunterBtn.interactable = true;
  99. EnterGameBtn.interactable = true;
  100. mConnectBow.interactable = false;
  101. //默认显示并且在start 读取
  102. SyncVector.isOn = PlayerPrefs.GetInt("CrossHairImageActive", 1) == 1;
  103. }
  104. void OnDestroy()
  105. {
  106. if (ConnetDevicesSingle.ins)
  107. ConnetDevicesSingle.ins.OnLogAction -= SetLogText;
  108. }
  109. // Update is called once per frame
  110. void Update()
  111. {
  112. //更新ui
  113. if (ConnetDevicesSingle.ins)
  114. {
  115. //进入游戏
  116. if (ConnetDevicesSingle.ins.mBluetoothHelperBow != null)
  117. {
  118. bool mBowConnected = ConnetDevicesSingle.ins.mBluetoothHelperBow.isConnected();
  119. bool mBowIsScanning = ConnetDevicesSingle.ins.mIsBowScanning;
  120. bool mBowIsConnecting = ConnetDevicesSingle.ins.mIsBowConnecting;
  121. if (!mBowConnected && !mBowIsScanning && !mBowIsConnecting)
  122. {
  123. //未连接,未扫描,不是连接中
  124. mConnectBowText.text = "点击连接弓箭";
  125. if (!mConnectBow.interactable)
  126. mConnectBow.interactable = true;
  127. }
  128. else if (!mBowConnected && mBowIsScanning)
  129. {
  130. //扫描中
  131. mConnectBowText.text = "扫描中...";
  132. if (mConnectBow.interactable)
  133. mConnectBow.interactable = false;
  134. }
  135. else if (mBowConnected)
  136. {
  137. //已连接
  138. mConnectBowText.text = "已连接";
  139. //if (mConnectBow.interactable)
  140. // mConnectBow.interactable = false;
  141. if (!mConnectBow.interactable)
  142. mConnectBow.interactable = true;
  143. }
  144. //if (mBowConnected)
  145. //{
  146. // if (!EnterDuckHunterBtn.interactable)
  147. // EnterDuckHunterBtn.interactable = true;
  148. // if (!EnterGameBtn.interactable)
  149. // EnterGameBtn.interactable = true;
  150. //}
  151. //else
  152. //{
  153. // if (EnterDuckHunterBtn.interactable)
  154. // EnterDuckHunterBtn.interactable = false;
  155. // if (EnterGameBtn.interactable)
  156. // EnterGameBtn.interactable = false;
  157. //}
  158. }
  159. }
  160. }
  161. //连接弓箭设备
  162. void onConnectBowDevice()
  163. {
  164. ConnetDevicesSingle.ins?.OnBowScanNearbyDevices();
  165. }
  166. public void SetLogText(string text)
  167. {
  168. //Debug.Log("SetLogText:" + text);
  169. if (bowLogTextCount > 200)
  170. {
  171. clearLogText();
  172. }
  173. mScrollViewLogTextBow.text += text + "\n";
  174. bowLogTextCount++;
  175. }
  176. public void clearLogText()
  177. {
  178. mScrollViewLogTextBow.text = "";
  179. bowLogTextCount = 0;
  180. }
  181. public void onControlLog() {
  182. logObj.SetActive(!logObj.activeSelf);
  183. }
  184. public void enterGame()
  185. {
  186. SceneManager.LoadScene("Game_InfraredCamera", LoadSceneMode.Single);
  187. hideManager();
  188. }
  189. public void enterDuckHunter()
  190. {
  191. SceneManager.LoadScene("DuckHunter_Test2", LoadSceneMode.Single);
  192. hideManager();
  193. }
  194. public void SendGetConfig()
  195. {
  196. }
  197. public void SendGetShoot()
  198. {
  199. ConnetDevicesSingle.ins?.ButtonShoot();
  200. }
  201. public void onHideCrosshair()
  202. {
  203. ConnetDevicesSingle.ins?.onHideCrosshair();
  204. SyncVector.isOn = false;
  205. }
  206. public void onShowCrosshair()
  207. {
  208. ConnetDevicesSingle.ins?.onShowCrosshair();
  209. SyncVector.isOn = true;
  210. }
  211. public void onToggleSyncVector() {
  212. if (SyncVector.isOn)
  213. {
  214. ConnetDevicesSingle.ins?.onShowCrosshair();
  215. }
  216. else {
  217. ConnetDevicesSingle.ins?.onHideCrosshair();
  218. }
  219. }
  220. //隐藏控制面板UI
  221. public void hideManager()
  222. {
  223. // transform.parent.GetComponent<Canvas>().gameObject.SetActive(false);
  224. bPanelActive = false;
  225. for (int i = 0; i < uiArray.Length; i++)
  226. {
  227. uiArray[i].SetActive(false);
  228. }
  229. }
  230. //显示控制面板UI
  231. public void showManager()
  232. {
  233. // transform.parent.GetComponent<Canvas>().gameObject.SetActive(true);
  234. bPanelActive = true;
  235. for (int i = 0; i < uiArray.Length; i++)
  236. {
  237. uiArray[i].SetActive(true);
  238. }
  239. }
  240. }
  241. }