InfraredDemo.cs 63 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. using InfraredManager;
  6. using ZIM;
  7. using System.Linq;
  8. using SLAMUVC;
  9. using System;
  10. using SmartBowSDK;
  11. using ZIM.Unity;
  12. public class InfraredDemo : JCUnityLib.ViewBase
  13. {
  14. public static bool DebugInEditor = true;
  15. public static InfraredDemo _ins;
  16. [SerializeField]
  17. RectTransform canvasRectTransform;
  18. public Button mBtnSee;
  19. public static void Create()
  20. {
  21. if (_ins) return;
  22. GameObject o = Instantiate(Resources.Load<GameObject>("InfraredDemo"));
  23. DontDestroyOnLoad(o);
  24. _ins = o.GetComponent<InfraredDemo>();
  25. //添加一个父物体
  26. o.transform.SetParent(ViewMgr.Instance.transform.Find("1").transform);
  27. CanvasScaler canvasScaler = o.GetComponent<CanvasScaler>();
  28. if (canvasScaler != null)
  29. {
  30. Destroy(canvasScaler);
  31. }
  32. RectTransform rectTransform = o.GetComponent<RectTransform>();
  33. rectTransform.anchorMin = Vector2.zero; // 左下角对齐父级
  34. rectTransform.anchorMax = Vector2.one; // 右上角对齐父级
  35. rectTransform.offsetMin = Vector2.zero; // 移除左下角偏移
  36. rectTransform.offsetMax = Vector2.zero; // 移除右上角偏移
  37. rectTransform.localScale = Vector3.one; // 确保缩放为 1
  38. //直接初始化一次
  39. _ins.InitInfraredCamera();
  40. }
  41. void Start()
  42. {
  43. if (Application.platform != RuntimePlatform.WindowsEditor) DebugInEditor = false;
  44. SetVisiable(false);
  45. InitDebugScreenPoint();
  46. gameObject.AddComponent<FPSTester>();
  47. if (CommonConfig.StandaloneModeOrPlatformB)
  48. {
  49. mBtnSee.gameObject.SetActive(false);
  50. }
  51. else {
  52. mBtnSee.interactable = false;
  53. mBtnSee.transform.Find("Text").GetComponent<Text>().text = TextAutoLanguage2.GetTextByKey("WaitingForInitialization"); // "等待初始化..";
  54. }
  55. //直接初始化一次
  56. //InitInfraredCamera();
  57. Debug.Log("[InfraredDemo] Start Function!");
  58. initToggle();
  59. initExport();
  60. InitFullScreen();
  61. #if UNITY_STANDALONE_WIN
  62. _calibrationFixedText.transform.parent.gameObject.SetActive(false);
  63. #endif
  64. }
  65. void Update()
  66. {
  67. UpdateInfraredCamera();
  68. //UpdateDebugScreenPoint();
  69. }
  70. public void OnClick_See()
  71. {
  72. SetVisiable(!_visiable);
  73. }
  74. //初始化一次 initScreenLocateManual
  75. bool hasCalled = false;
  76. bool _visiable;
  77. void SetVisiable(bool value)
  78. {
  79. _visiable = value;
  80. transform.Find("Background").gameObject.SetActive(value);
  81. transform.Find("InfraredCamera").gameObject.SetActive(value);
  82. //如果是b端,控制这里按钮显示
  83. if (CommonConfig.StandaloneModeOrPlatformB)
  84. {
  85. mBtnSee.gameObject.SetActive(value);
  86. }
  87. updateBtnSee();
  88. Action<Text> onApplyToNext = (t) => {
  89. updateBtnSee();
  90. };
  91. mBtnSee.GetComponentInChildren<TextAutoLanguage2>().onApplyToNext += onApplyToNext;
  92. //if (value) InitInfraredCamera();
  93. //刷新翻译的Dropdown
  94. if (value) {
  95. UpdateLanguage();
  96. updateDropdownResolution2();
  97. }
  98. if (!hasCalled && value)
  99. {
  100. hasCalled = true;
  101. //如果本地有记录,初始化一次
  102. StartCoroutine(initScreenLocateManual());
  103. Debug.Log("[InfraredDemo] SetVisiable Function!");
  104. }
  105. }
  106. void updateBtnSee() {
  107. mBtnSee.GetComponentInChildren<Text>().text = _visiable ? TextAutoLanguage2.GetTextByKey("HideInterface") : TextAutoLanguage2.GetTextByKey("DebugInfrared");//"隐藏界面" : "调试红外";
  108. }
  109. Text _spText;
  110. Vector2 _screenPoint;
  111. void InitDebugScreenPoint()
  112. {
  113. _spText = transform.Find("SPText").GetComponent<Text>();
  114. //_spText.gameObject.SetActive(DebugInEditor);
  115. _spText.gameObject.SetActive(false);
  116. }
  117. void UpdateDebugScreenPoint()
  118. {
  119. if (!DebugInEditor) return;
  120. if (infraredCameraHelper == null) return;
  121. _screenPoint.x = Mathf.Clamp(
  122. _screenPoint.x + Input.GetAxis("Horizontal") * Screen.width / 400f,
  123. 0, Screen.width);
  124. _screenPoint.y = Mathf.Clamp(
  125. _screenPoint.y + Input.GetAxis("Vertical") * Screen.height / 400f,
  126. 0, Screen.height);
  127. infraredCameraHelper.InvokeOnPositionUpdate(_screenPoint);
  128. _spText.text = _screenPoint.ToString();
  129. }
  130. #region 红外摄像
  131. [SerializeField] RawImage _cameraRender;
  132. [SerializeField] RawImage _cameraRender2;
  133. /// <summary>
  134. /// 测试texture
  135. /// </summary>
  136. public RawImage MyCameraRender2
  137. {
  138. get { return _cameraRender2; }
  139. set { _cameraRender2 = value; }
  140. }
  141. //[SerializeField] MaintainAspectRatio _MaintainAspectRatio;
  142. [SerializeField] List<RectTransform> _crosshairsInCamera;
  143. [SerializeField] Slider _sliderShakeFilter;
  144. [SerializeField] Button _btnReset;
  145. [SerializeField] Button _btnScreenLocateManual;
  146. [SerializeField] Button _btnScreenLocateManualAuto;
  147. [SerializeField] Slider _sliderCapture;
  148. [SerializeField] Slider _sliderDelay;
  149. [SerializeField] Dropdown _dropdownResolution;
  150. [SerializeField] Dropdown _dropdownResolution2;
  151. [SerializeField] Slider _sliderLineWidth;
  152. [SerializeField] Slider _fanWidth;
  153. //红外线阈值
  154. [SerializeField] Slider _infraredFilter;
  155. //调试UVC参数
  156. [SerializeField] GameObject _cameraParameterPanel;
  157. [SerializeField] Button _btnAdjusting;
  158. //野鸭选择
  159. [SerializeField] Dropdown _duckLevelDropdown;
  160. //Dictionary<string, ParamFloatValue> dUVCParameters = new Dictionary<string, ParamFloatValue>();
  161. //public ParamFloatValue brightness = new ParamFloatValue("ic_brightness", 1.0f);
  162. //public ParamFloatValue saturation = new ParamFloatValue("ic_saturation", 1.0f);
  163. //public ParamFloatValue contrast = new ParamFloatValue("ic_contrast", 1.0f);
  164. #if UNITY_ANDROID
  165. //初始化纹理-1280*720,index = 0
  166. // public ParamFloatValue resoution = new ParamFloatValue("ic_resoution2", 0);
  167. //摄像机分辨率 -320*240,index = 10
  168. public ParamFloatValue resoutionNew = new ParamFloatValue("ic_resoutionNew", 10);
  169. //摄像机分辨率 -只处理高低分辨率情况
  170. public ParamFloatValue resoution = new ParamFloatValue("ic_resoution", 0);
  171. //string[] resolutions = { "高分辨率", "低分辨率" };
  172. #endif
  173. //抖动过滤值 - 6.0
  174. public ParamFloatValue shakeFilterValue = new ParamFloatValue("ic_shakeFilterValue2", 6.0f);
  175. //亮度过滤阈值 - 0.8
  176. public ParamFloatValue infraredFileterValue = new ParamFloatValue("ic_infraredFileterValue", 0.8f);
  177. //线段宽度阈值
  178. public ParamFloatValue lineWidth = new ParamFloatValue("ic_lineWidth", 4.0f);
  179. //扇形宽度
  180. public ParamFloatValue fanWidth = new ParamFloatValue("ic_fanWidth", 90.0f);
  181. public ParamFloatValue captureValue = new ParamFloatValue("ic_captureValue", 30.0f);
  182. public ParamFloatValue delayValue = new ParamFloatValue("ic_delayValue", 30.0f);
  183. //红外准心,默认打开吧
  184. public ParamFloatValue crosshairValue = new ParamFloatValue("ic_crosshairValue", 1);
  185. //野鸭测试存储
  186. public ParamFloatValue duckHunterLevel = new ParamFloatValue("test_duckHunterLevelValue", 1);
  187. public static InfraredCameraHelper infraredCameraHelper;
  188. public static bool running { get => infraredCameraHelper != null; }
  189. private bool _inited;
  190. #region 参数控制
  191. public GameObject togglePrefab; // 拖入一个Toggle预设体
  192. public GameObject sliderPrefab; // 拖入一个Slider预设体
  193. public GameObject spawnPoint;
  194. //自动曝光
  195. bool bAutoAE = false;
  196. Toggle CTRLAEToggle;
  197. Slider CTRLAEABSSlider;
  198. string[] sliderNameArray = new string[]{
  199. "自动曝光模式",
  200. "曝光时间(绝对)",
  201. "亮度", //
  202. "对比度",
  203. "色调",
  204. "饱和度",
  205. "锐度",
  206. "伽玛",
  207. //"白平衡温度",
  208. //"白平衡分量",
  209. "背光补偿",
  210. "增益" };
  211. string[] sliderStrArray = new string[]{
  212. "CTRL_AE",
  213. "CTRL_AE_ABS",
  214. "PU_BRIGHTNESS",
  215. "PU_CONTRAST",
  216. "PU_HUE",
  217. "PU_SATURATION",
  218. "PU_SHARPNESS",
  219. "PU_GAMMA",
  220. //"PU_WB_TEMP",
  221. //"PU_WB_COMPO",
  222. "PU_BACKLIGHT",
  223. "PU_GAIN" };
  224. UVCManager.CameraInfo currentCameraInfo;
  225. //初始化相机参数
  226. public void initSlider(UVCManager.CameraInfo cameraInfo)
  227. {
  228. if (currentCameraInfo != null) return;
  229. currentCameraInfo = cameraInfo;
  230. string[] sliderNameArrayKey = new string[] {
  231. "AutoExposureMode", // "自动曝光模式"
  232. "ExposureTimeAbsolute", // "曝光时间(绝对)"
  233. "Brightness", // "亮度"
  234. "Contrast", // "对比度"
  235. "Hue", // "色调"
  236. "Saturation", // "饱和度"
  237. "Sharpness", // "锐度"
  238. "Gamma", // "伽玛"
  239. "BacklightCompensation", // "背光补偿"
  240. "Gain" // "增益"
  241. };
  242. for (int i = 0; i < sliderStrArray.Length; i++)
  243. {
  244. string typeStr = sliderStrArray[i];
  245. // UInt64 _VALUE = cameraInfo.GetTypeByName(typeStr);
  246. //不支持的,跳过
  247. bool bContains = cameraInfo.ContainsKey(typeStr);
  248. if (!bContains) continue;
  249. if (typeStr == "CTRL_AE")
  250. {
  251. //曝光Toggle
  252. GameObject toggleObject = Instantiate(togglePrefab, spawnPoint.transform);
  253. toggleObject.SetActive(true);
  254. toggleObject.name = typeStr;
  255. Text labelObj = toggleObject.transform.Find("Label").GetComponent<Text>();
  256. //labelObj.text = sliderNameArray[i];
  257. labelObj.gameObject.AddComponent<TextAutoLanguage2>().SetTextKey(sliderNameArrayKey[i]);
  258. Toggle toggle = toggleObject.GetComponent<Toggle>();
  259. CTRLAEToggle = toggle;
  260. UVCCtrlInfo _AEInfo = cameraInfo.GetInfo(typeStr);
  261. Debug.Log("UVCCtrlInfo:" + _AEInfo.ToString());
  262. int _currentValue = cameraInfo.GetValue(typeStr);
  263. bAutoAE = _currentValue == 8 ? true : false; //如果当前值是 8,则当前摄像机是自动曝光模式
  264. toggle.isOn = bAutoAE;
  265. //cameraInfo.SetValue(_VALUE, _currentValue!=8? 8:1);
  266. toggle.onValueChanged.AddListener((bool bValue) =>
  267. {
  268. //Debug.Log("Toggle value changed to: " + bValue + " from " + _VALUE);
  269. if (typeStr == "CTRL_AE")
  270. {
  271. //开关控制是否自动曝光
  272. bAutoAE = bValue;
  273. if (CTRLAEABSSlider) CTRLAEABSSlider.interactable = !bAutoAE;
  274. int _value = bValue ? 8 : 1;
  275. //Debug.Log("_value " + _value);
  276. cameraInfo.SetValue(typeStr, _value);
  277. }
  278. });
  279. }
  280. else
  281. {
  282. //其余使用slider
  283. GameObject sliderObject = Instantiate(sliderPrefab, spawnPoint.transform);
  284. sliderObject.SetActive(true);
  285. sliderObject.name = typeStr;
  286. Slider slider = sliderObject.GetComponent<Slider>();
  287. Text textObj = sliderObject.transform.Find("text").GetComponent<Text>();
  288. Text titleTextObj = sliderObject.transform.Find("title").GetComponent<Text>();
  289. //titleTextObj.text = sliderNameArray[i];//类型名字
  290. titleTextObj.gameObject.AddComponent<TextAutoLanguage2>().SetTextKey(sliderNameArrayKey[i]);
  291. if (slider != null)
  292. {
  293. UVCCtrlInfo _UVCCtrlInfo = cameraInfo.GetInfo(typeStr);
  294. slider.minValue = _UVCCtrlInfo.min;
  295. slider.maxValue = _UVCCtrlInfo.max;
  296. slider.wholeNumbers = true;
  297. int _defValue = _UVCCtrlInfo.def;
  298. //指定默认值
  299. //5、UVC亮度 - 50
  300. //6、UVC对比度 - 50
  301. if (typeStr == "PU_BRIGHTNESS") {
  302. _defValue = 50;
  303. } else if (typeStr == "PU_CONTRAST") {
  304. _defValue = 50;
  305. }
  306. //记录一个typeStr类型的数据存储操作对象
  307. ParamFloatValue paramFloatValue = new ParamFloatValue("ic_uvc_" + typeStr, _defValue);
  308. if (typeStr == "PU_BRIGHTNESS" || typeStr == "PU_CONTRAST")
  309. {
  310. //获取设置默认存储的值
  311. int _Value = (int)paramFloatValue.Get();
  312. cameraInfo.SetValue(typeStr, _Value);
  313. Debug.Log("[InfraredDemo] UVC 设置" + typeStr + "默认值:" + _Value);
  314. slider.value = _Value;
  315. textObj.text = _Value + "";
  316. }
  317. else {
  318. //获取设置当前值
  319. int _currentValue = cameraInfo.GetValue(typeStr);
  320. slider.value = _currentValue;
  321. textObj.text = _currentValue + "";
  322. }
  323. //如果是曝光slider
  324. if (typeStr == "CTRL_AE_ABS")
  325. {
  326. CTRLAEABSSlider = slider;
  327. slider.interactable = !bAutoAE;
  328. }
  329. slider.onValueChanged.AddListener((newValue) =>
  330. {
  331. var _value = Mathf.FloorToInt(newValue);
  332. textObj.text = _value + "";
  333. //Debug.Log("Slider value changed to: " + newValue + " from " + _VALUE);
  334. cameraInfo.SetValue(typeStr, _value);
  335. });
  336. }
  337. }
  338. }
  339. }
  340. public void OpenUVCPanel()
  341. {
  342. _cameraParameterPanel.SetActive(true);
  343. }
  344. public void CloseUVCPanel()
  345. {
  346. _cameraParameterPanel.SetActive(false);
  347. }
  348. public void onResetUVCData()
  349. {
  350. #if UNITY_ANDROID
  351. resetUVCData();
  352. #endif
  353. #if UNITY_STANDALONE_WIN || UNITY_EDITOR
  354. resetPCData();
  355. #endif
  356. }
  357. void resetUVCData() {
  358. if (currentCameraInfo == null) return;
  359. for (int i = 0; i < sliderStrArray.Length; i++)
  360. {
  361. string typeStr = sliderStrArray[i];
  362. // UInt64 _VALUE = currentCameraInfo.GetTypeByName(typeStr);
  363. bool bContains = currentCameraInfo.ContainsKey(typeStr);
  364. if (!bContains) continue;
  365. if (typeStr == "CTRL_AE")
  366. {
  367. //toggle值不进行重置
  368. Debug.Log("CTRL_AE 不需要重置");
  369. }
  370. else if (typeStr == "CTRL_AE_ABS")
  371. {
  372. if (!bAutoAE)
  373. {
  374. //如果是手动曝光,重置值
  375. Transform trans = _cameraParameterPanel.transform.Find(typeStr);
  376. Slider slider = trans.GetComponent<Slider>();
  377. Text textObj = trans.Find("text").GetComponent<Text>();
  378. UVCCtrlInfo _AEInfo = currentCameraInfo.GetInfo(typeStr);
  379. //获取当前值
  380. int _currentValue = currentCameraInfo.GetValue(typeStr);
  381. Debug.Log("CTRL_AE_ABS:" + _currentValue + " = " + _AEInfo.def + " = " + ",bAutoAE:" + bAutoAE);
  382. textObj.text = _AEInfo.def + "";
  383. slider.value = _AEInfo.def;
  384. if (_AEInfo.def != _currentValue) currentCameraInfo.SetValue(typeStr, _AEInfo.def);
  385. }
  386. }
  387. else
  388. {
  389. Transform trans = _cameraParameterPanel.transform.Find(typeStr);
  390. Slider slider = trans.GetComponent<Slider>();
  391. Text textObj = trans.Find("text").GetComponent<Text>();
  392. UVCCtrlInfo _UVCCtrlInfo = currentCameraInfo.GetInfo(typeStr);
  393. //重置的值
  394. int _defValue = _UVCCtrlInfo.def;
  395. if (typeStr == "PU_BRIGHTNESS")
  396. {
  397. _defValue = 50;
  398. }
  399. else if (typeStr == "PU_CONTRAST")
  400. {
  401. _defValue = 50;
  402. }
  403. textObj.text = _defValue + "";
  404. slider.value = _defValue;
  405. //获取当前值
  406. int _currentValue = currentCameraInfo.GetValue(typeStr);
  407. //重置存储值
  408. //dUVCParameters.GetValueOrDefault(typeStr).Set(_UVCCtrlInfo.def);
  409. //存储初始值,设置一次到UVC参数
  410. if (_defValue != _currentValue) currentCameraInfo.SetValue(typeStr, _defValue);
  411. }
  412. }
  413. }
  414. //windows 相机
  415. string[] sliderNameArrayPC = new string[]{
  416. "亮度",
  417. "对比度",};
  418. string[] sliderNameArrayPCKey = new string[]{
  419. "Brightness",
  420. "Contrast",};
  421. string[] sliderStrArrayPC = new string[]{
  422. "PU_BRIGHTNESS",
  423. "PU_CONTRAST"};
  424. //记录一个typeStr类型的数据存储操作对象
  425. ParamFloatValue pcBRIGHTNESS = new ParamFloatValue("ic_pc_PU_BRIGHTNESS", 0);
  426. ParamFloatValue pcCONTRAST = new ParamFloatValue("ic_pc_PU_CONTRAST", 0);
  427. public void initSliderPC()
  428. {
  429. for (int i = 0; i < sliderStrArrayPC.Length; i++)
  430. {
  431. string typeStr = sliderStrArrayPC[i];
  432. GameObject sliderObject = Instantiate(sliderPrefab, spawnPoint.transform);
  433. sliderObject.SetActive(true);
  434. sliderObject.name = typeStr;
  435. Slider slider = sliderObject.GetComponent<Slider>();
  436. Text textObj = sliderObject.transform.Find("text").GetComponent<Text>();
  437. Text titleTextObj = sliderObject.transform.Find("title").GetComponent<Text>();
  438. //titleTextObj.text = TextAutoLanguage2.GetTextByKey(sliderNameArrayPCKey[i]);// sliderNameArrayPC[i];//类型名字
  439. titleTextObj.gameObject.AddComponent<TextAutoLanguage2>().SetTextKey(sliderNameArrayPCKey[i]);
  440. if (slider != null)
  441. {
  442. slider.minValue = -1;
  443. slider.maxValue = 1;
  444. //记录一个typeStr类型的数据存储操作对象
  445. if (typeStr == "PU_BRIGHTNESS")
  446. {
  447. //获取设置默认存储的值
  448. float _Value = pcBRIGHTNESS.Get();
  449. infraredCameraHelper.SetBrightness(_Value);
  450. Debug.Log("[InfraredDemo] PC 设置 PU_BRIGHTNESS:" + typeStr + "默认值:" + _Value);
  451. slider.value = _Value;
  452. textObj.text = _Value + "";
  453. slider.onValueChanged.AddListener((newValue) =>
  454. {
  455. var _value = newValue;
  456. textObj.text = _value + "";
  457. infraredCameraHelper.SetBrightness(_value);
  458. pcBRIGHTNESS.Set(_value);
  459. });
  460. }
  461. else if (typeStr == "PU_CONTRAST")
  462. {
  463. //获取设置默认存储的值
  464. float _Value = pcCONTRAST.Get();
  465. infraredCameraHelper.SetContrast(_Value);
  466. Debug.Log("[InfraredDemo] PC 设置 PU_CONTRAST:" + typeStr + "默认值:" + _Value);
  467. slider.value = _Value;
  468. textObj.text = _Value + "";
  469. slider.onValueChanged.AddListener((newValue) =>
  470. {
  471. var _value = newValue;
  472. textObj.text = _value + "";
  473. infraredCameraHelper.SetContrast(_value);
  474. pcCONTRAST.Set(_value);
  475. });
  476. }
  477. }
  478. }
  479. }
  480. void resetPCData() {
  481. for (int i = 0; i < sliderStrArrayPC.Length; i++)
  482. {
  483. string typeStr = sliderStrArrayPC[i];
  484. Transform trans = _cameraParameterPanel.transform.Find(typeStr);
  485. Slider slider = trans.GetComponent<Slider>();
  486. Text textObj = trans.Find("text").GetComponent<Text>();
  487. //重置的值
  488. int _defValue = 0;
  489. if (typeStr == "PU_BRIGHTNESS")
  490. {
  491. _defValue = 0;
  492. infraredCameraHelper.SetBrightness(_defValue);
  493. }
  494. else if (typeStr == "PU_CONTRAST")
  495. {
  496. _defValue = 0;
  497. infraredCameraHelper.SetContrast(_defValue);
  498. }
  499. textObj.text = _defValue + "";
  500. slider.value = _defValue;
  501. }
  502. }
  503. #endregion
  504. void InitInfraredCamera()
  505. {
  506. if (_inited) return;
  507. _inited = true;
  508. //SDK创建
  509. if (infraredCameraHelper == null)
  510. {
  511. infraredCameraHelper = InfraredCameraHelper.GetInstance();
  512. #if UNITY_STANDALONE_WIN || UNITY_EDITOR
  513. infraredCameraHelper.CreateToPc();
  514. #endif
  515. #if UNITY_ANDROID
  516. //开始时候设置一个默认分辨率
  517. Debug.Log("开始时候的分辨率下标:" + resoution.Get());
  518. Vector2 resoutionVec2 = SetDefByIndex((int)resoution.Get());
  519. infraredCameraHelper.Create((int)resoutionVec2.x, (int)resoutionVec2.y);
  520. #endif
  521. infraredCameraHelper.OnPositionUpdate += (Vector2 point) =>
  522. {
  523. //跑九轴时候,不处理这里位置
  524. if (AimHandler.ins && AimHandler.ins.bRuning9Axis()) return;
  525. if (Camera.main == null) return;
  526. Ray ray = Camera.main.ScreenPointToRay(point);
  527. Vector3 rayEndPoint = ray.GetPoint(200);
  528. Quaternion quat = Quaternion.LookRotation(rayEndPoint - Camera.main.transform.position);
  529. // 挑战场景中其相机的父级有旋转,需要换算
  530. if (UnityEngine.SceneManagement.SceneManager.GetActiveScene().name == "GameChallenge")
  531. {
  532. quat = Quaternion.AngleAxis(-180, Vector3.up) * quat;
  533. }
  534. if (CameraToLook.ins != null) CameraToLook.ins.localRotation = quat;
  535. if (SB_EventSystem.ins) SB_EventSystem.ins.MoveSimulateMouseByInfrared(point);
  536. //移动目标游戏
  537. if (GeneratingTarget.gm != null) GeneratingTarget.gm.shootingEvent.OnPositionUpdate(point);
  538. };
  539. infraredCameraHelper.OnUVCIsReady += (UVCManager.CameraInfo camera) =>
  540. {
  541. //生成控制摄像机的参数滑条
  542. Debug.Log("初始化摄像机!");
  543. //可以操作按钮
  544. mBtnSee.interactable = true;
  545. //mBtnSee.transform.Find("Text").GetComponent<Text>().text = "调试红外";
  546. updateBtnSee();
  547. //延迟重新设置一次分辨率
  548. StartCoroutine(delayInitOhterInfo(camera));
  549. };
  550. //屏幕变化时候
  551. infraredCameraHelper.OnUVCPosUpdate += (list) =>
  552. {
  553. Debug.Log("OnUVCPosUpdate list.Count" + list.Count);
  554. SetLocatePointsToCameraRender(list, 1, 1);
  555. //InfraredScreenPositioningView 页面
  556. if (list.Count == 4)
  557. {
  558. FindObjectOfType<InfraredScreenPositioningView>()?.SyncScreenPosition();
  559. }
  560. else {
  561. FindObjectOfType<InfraredScreenPositioningView>()?.onReset();
  562. }
  563. };
  564. }
  565. }
  566. private void updateDropdownResolution2()
  567. {
  568. string[] resolutions = {
  569. TextAutoLanguage2.GetTextByKey("HighResolution"),
  570. TextAutoLanguage2.GetTextByKey("LowResolution")
  571. };
  572. // 清除默认选项
  573. _dropdownResolution2.ClearOptions();
  574. // 将分辨率字符串数组转换为 Dropdown 选项
  575. _dropdownResolution2.AddOptions(new List<string>(resolutions));
  576. }
  577. /// <summary>
  578. /// 初始化一些游戏配置
  579. /// </summary>
  580. /// <returns></returns>
  581. IEnumerator delayInitOhterInfo(UVCManager.CameraInfo camera) {
  582. //yield return new WaitForSeconds(1f);
  583. yield return new WaitForEndOfFrame();
  584. #if UNITY_ANDROID
  585. initSlider(camera);
  586. camera.GetResolutionsStrs();
  587. // 默认设置
  588. updateDropdownResolution2();
  589. int index = (int)resoution.Get();
  590. _dropdownResolution2.value = index;
  591. _dropdownResolution2.RefreshShownValue();
  592. // 处理 Dropdown 的选择变化
  593. _dropdownResolution2.onValueChanged.AddListener(index => { OnResolutionChanged(index); });
  594. #endif
  595. #if UNITY_STANDALONE_WIN || UNITY_EDITOR
  596. initSliderPC();
  597. //隐藏不需要的设置
  598. _btnAdjusting.transform.Find("Text").GetComponent<Text>().text = "调整PC参数";
  599. _dropdownResolution.gameObject.SetActive(false);
  600. _dropdownResolution2.gameObject.SetActive(false);
  601. #endif
  602. //震动阈值
  603. SetShakeFilterValue(shakeFilterValue.Get());
  604. _sliderShakeFilter.onValueChanged.AddListener(SetShakeFilterValue);
  605. //功能按钮
  606. //重置触发测试
  607. _btnReset.onClick.AddListener(OnClick_Reset);
  608. _btnScreenLocateManual.onClick.AddListener(OnClick_ScreenLocateManual);
  609. _btnScreenLocateManualAuto.onClick.AddListener(OnClick_ScreenLocateManualAuto);
  610. SetCaptureValue(captureValue.Get());
  611. _sliderCapture.onValueChanged.AddListener(SetCaptureValue);
  612. SetDelayValue(delayValue.Get());
  613. _sliderDelay.onValueChanged.AddListener(SetDelayValue);
  614. //绘制线段
  615. SetLineWidth(lineWidth.Get());
  616. _sliderLineWidth.onValueChanged.AddListener(SetLineWidth);
  617. SetFanWidth(fanWidth.Get());
  618. _fanWidth.onValueChanged.AddListener(SetFanWidth);
  619. //检测红外亮度阈值
  620. SetInfraredFilterValue(infraredFileterValue.Get());
  621. _infraredFilter.onValueChanged.AddListener(SetInfraredFilterValue);
  622. //野鸭设置初始关卡
  623. int defLevel = (int)duckHunterLevel.Get() - 1 < 0 ? 0 : (int)duckHunterLevel.Get() - 1;
  624. _duckLevelDropdown.SetValueWithoutNotify(defLevel);
  625. _duckLevelDropdown.onValueChanged.AddListener(SetDuckLevelTest);
  626. }
  627. /// <summary>
  628. /// 初始化时候获取设置和存储来控制显示准心
  629. /// </summary>
  630. /// <returns></returns>
  631. public bool bInitCrosshairShow() {
  632. return UserSettings.ins.openCrossHair && getCrosshairValue() == 1 ? true : false;
  633. }
  634. /// <summary>
  635. /// 获取弓箭准心存储值
  636. /// </summary>
  637. /// <returns></returns>
  638. public int getCrosshairValue() {
  639. return (int)crosshairValue.Get();
  640. }
  641. public void setCrosshairValue(bool bshow) {
  642. crosshairValue.Set(bshow ? 1 : 0);
  643. }
  644. public void onStartPreview()
  645. {
  646. infraredCameraHelper.onStartPreview();
  647. }
  648. public void onStopPreview()
  649. {
  650. infraredCameraHelper.onStopPreview();
  651. }
  652. /// <summary>
  653. /// 获取并且初始化一次记录点的数据
  654. /// </summary>
  655. /// <returns></returns>
  656. IEnumerator initScreenLocateManual()
  657. {
  658. yield return new WaitForSeconds(1f);
  659. infraredCameraHelper.InitScreenLocateManual();
  660. }
  661. IEnumerator RestartOrKillApp()
  662. {
  663. yield return new WaitForSeconds(0.3f);
  664. if (Application.isEditor) yield break;
  665. if (Application.platform == RuntimePlatform.Android)
  666. {
  667. using (var unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer"))
  668. {
  669. const int kIntent_FLAG_ACTIVITY_CLEAR_TASK = 0x00008000;
  670. const int kIntent_FLAG_ACTIVITY_NEW_TASK = 0x10000000;
  671. var currentActivity = unityPlayer.GetStatic<AndroidJavaObject>("currentActivity");
  672. var pm = currentActivity.Call<AndroidJavaObject>("getPackageManager");
  673. var intent = pm.Call<AndroidJavaObject>("getLaunchIntentForPackage", Application.identifier);
  674. intent.Call<AndroidJavaObject>("setFlags", kIntent_FLAG_ACTIVITY_NEW_TASK | kIntent_FLAG_ACTIVITY_CLEAR_TASK);
  675. currentActivity.Call("startActivity", intent);
  676. currentActivity.Call("finish");
  677. var process = new AndroidJavaClass("android.os.Process");
  678. int pid = process.CallStatic<int>("myPid");
  679. process.CallStatic("killProcess", pid);
  680. }
  681. }
  682. else {
  683. // 获取当前应用程序的可执行文件路径
  684. string executablePath = System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName;
  685. // 重启应用程序
  686. System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo
  687. {
  688. FileName = executablePath,
  689. UseShellExecute = false
  690. };
  691. System.Diagnostics.Process.Start(startInfo);
  692. // 退出当前应用程序
  693. Application.Quit();
  694. };
  695. }
  696. void UpdateInfraredCamera()
  697. {
  698. if (!_visiable) return;
  699. if (!_inited) return;
  700. if (infraredCameraHelper == null) return;
  701. //渲染相机画面
  702. //_cameraRender.texture = infraredCameraHelper.GetCameraTexture();
  703. //_cameraRender.material = infraredCameraHelper.GetCameraMaterial();
  704. if (ScreenLocate.Main.getUVCTexture)
  705. {
  706. if (isFullscreen || ScreenLocate.Main.OutputTextures[4] == null)
  707. {
  708. if (_cameraRender.texture == null || ScreenLocate.Main.getUVCTexture.GetNativeTexturePtr() != _cameraRender.texture.GetNativeTexturePtr())
  709. _cameraRender.texture = ScreenLocate.Main.getUVCTexture;
  710. //ScreenLocate.Main.OutputTextures[4] == null 并且 摄像机缩小的情况下。显示适配线段
  711. if (!isFullscreen) SetAllToggle(true);
  712. }
  713. else if (ScreenLocate.Main.OutputTextures[4] != null)
  714. {
  715. //缩小的情况下。显示黑白色差的合成图
  716. if (_cameraRender.texture == null || ScreenLocate.Main.OutputTextures[4] != null && ScreenLocate.Main.OutputTextures[4].GetNativeTexturePtr() != _cameraRender.texture.GetNativeTexturePtr())
  717. _cameraRender.texture = ScreenLocate.Main.OutputTextures[4];
  718. //底图缩小的情况下。不显示适配线段,并且隐藏points
  719. if (!isFullscreen) {
  720. if (showPoints) {
  721. Transform pointsTF2 = _cameraRender.transform.Find("Points");
  722. for (int i = 0; i < pointsTF2.childCount; i++)
  723. {
  724. Transform pointTF = pointsTF2.GetChild(i);
  725. pointTF.gameObject.SetActive(false);
  726. showPoints = false;
  727. }
  728. }
  729. SetAllToggle(false);
  730. }
  731. }
  732. //_cameraRender.SetNativeSize();
  733. // _MaintainAspectRatio.AdjustSize();
  734. }
  735. //在相机画面显示准心
  736. if (ScreenLocate.Main)
  737. {
  738. var _sl = ScreenLocate.Main;
  739. var buffer = _sl.infraredSpotBuffer;
  740. if (buffer != null)
  741. {
  742. for (int i = 0; i < buffer.Length; i++)
  743. {
  744. if (buffer[i].CameraLocation != null)
  745. {
  746. //添加一个偏移量,使得最后输出的准心是指向正中心
  747. Vector2 newPoint2 = _sl.GetOffsetCameraLocation(buffer[i].CameraLocation.Value);
  748. // 检测到光点
  749. var pos = newPoint2.pixelToLocalPosition_AnchorCenter(_sl.mUVCCameraInfo.Size, _cameraRender.rectTransform.rect);
  750. _crosshairsInCamera[i].gameObject.SetActive(true);
  751. _crosshairsInCamera[i].anchoredPosition = pos;
  752. }
  753. else
  754. _crosshairsInCamera[i].gameObject.SetActive(false);
  755. }
  756. }
  757. //渲染固定摄像机分辨率
  758. SetCalibrationFixedText(_sl.mUVCCameraInfo.CurrentCalibrationResolution);
  759. //渲染摄像机大小
  760. if (_sl.mUVCCameraInfo != null) SetCameraSizeText(_sl.mUVCCameraInfo.Size);
  761. //渲染摄像机识别点位置
  762. SetQuadUnityVectorListText(_sl.PrintVector2List(ScreenLocate.quadUnityVectorList));
  763. }
  764. }
  765. bool showPoints = false;
  766. public void SetLocatePointsToCameraRender(List<Vector2> points, float w, float h)
  767. {
  768. Transform pointsTF2 = _cameraRender.transform.Find("Points");
  769. if (pointsTF2.childCount == points.Count)
  770. {
  771. Vector2 texSize = new Vector2(w, h);
  772. for (int i = 0; i < pointsTF2.childCount; i++)
  773. {
  774. Transform pointTF = pointsTF2.GetChild(i);
  775. Vector2 pos = points[i];
  776. pointTF.localPosition = pos.pixelToLocalPosition_AnchorCenter(texSize, _cameraRender.rectTransform.rect);
  777. pointTF.gameObject.SetActive(true);
  778. showPoints = true;
  779. }
  780. }
  781. else {
  782. for (int i = 0; i < pointsTF2.childCount; i++)
  783. {
  784. Transform pointTF = pointsTF2.GetChild(i);
  785. pointTF.gameObject.SetActive(false);
  786. showPoints = false;
  787. }
  788. }
  789. //绘制数据
  790. DrawTestLine();
  791. }
  792. #region 测试数据绘制
  793. [SerializeField] private Toggle curToggle;
  794. [SerializeField] private Toggle autoToggle; // 控制 AutoUILineGenerator 的 Toggle
  795. [SerializeField] private Toggle semiAutoToggle; // 控制 SemiAutoUILineGenerator 的 Toggle
  796. [SerializeField] private Toggle manualToggle; // 控制 ManualUILineGenerator 的 Toggle
  797. [SerializeField] LineGenerator CurUILineGenerator;//当前结果屏幕线条
  798. [SerializeField] LineGenerator AutoUILineGenerator;//第一个结果屏幕线条
  799. [SerializeField] LineGenerator SemiAutoUILineGenerator;//第二个结果屏幕线条
  800. [SerializeField] LineGenerator ManualUILineGenerator;//第三个结果屏幕线条
  801. [SerializeField] private Dropdown dropdown; // 引用场景中的 Dropdown 组件
  802. [SerializeField] RawImage _cameraRenderTest5;
  803. [SerializeField] RawImage _cameraRenderTest6;
  804. void DrawTestLine()
  805. {
  806. Vector2 texSize = ScreenLocate.Main.getUVCCameraInfoSize;
  807. // 判断 texSize 是否为有效值
  808. if (texSize == Vector2.zero)
  809. {
  810. Debug.LogWarning("Texture size is zero, cannot proceed with line drawing.");
  811. return;
  812. }
  813. // 设置三个屏幕四边形和线条生成器
  814. QuadrilateralInCamera[] screenQuads = new QuadrilateralInCamera[] {
  815. ScreenLocate.Main.ScreenIdentification?.QuadAuto,
  816. ScreenLocate.Main.ScreenIdentification?.QuadSemiAuto,
  817. ScreenLocate.Main.ScreenIdentification?.QuadManual
  818. };
  819. LineGenerator[] lineGenerators = new LineGenerator[] {
  820. AutoUILineGenerator,
  821. SemiAutoUILineGenerator,
  822. ManualUILineGenerator
  823. };
  824. for (int i = 0; i < screenQuads.Length; i++)
  825. {
  826. if (screenQuads[i] == null)
  827. {
  828. Debug.LogWarning($"Screen quadrilateral {i} is null, skipping this line.");
  829. continue;
  830. }
  831. if (lineGenerators[i] == null)
  832. {
  833. Debug.LogWarning($"Line generator {i} is null, skipping this line.");
  834. continue;
  835. }
  836. lineGenerators[i].Points = ConvertQuadToPoints(screenQuads[i], texSize);
  837. }
  838. // 清除旧选项并填充新的选项
  839. dropdown.ClearOptions();
  840. List<string> options = new List<string>();
  841. //for (int i = 0; i < screenQuads.Length; i++)
  842. //{
  843. // options.Add($"Quad {i + 1}");
  844. //}
  845. //options.Add("自动识别");
  846. //options.Add("半自动识别");
  847. //options.Add("手动识别");
  848. options.Add(TextAutoLanguage2.GetTextByKey("AutoRecognition")); // "自动识别"
  849. options.Add(TextAutoLanguage2.GetTextByKey("SemiAutoRecognition")); // "半自动识别"
  850. options.Add(TextAutoLanguage2.GetTextByKey("ManualRecognition")); // "手动识别"
  851. dropdown.AddOptions(options);
  852. // 添加监听器来处理选择事件
  853. dropdown.onValueChanged.AddListener((index) => {
  854. OnDropdownValueChanged(index, screenQuads);
  855. });
  856. if (screenQuads[0] != null || screenQuads[1] != null)
  857. {
  858. Texture texImage6 = ScreenLocate.Main.OutputTextures[5];
  859. if (texImage6 != null) _cameraRenderTest6.texture = texImage6;
  860. }
  861. if (ScreenLocate.quadUnityVectorList.Count == 4) {
  862. //绘制白色线段
  863. var lo = new Vector2(-0.5f, -0.5f);
  864. CurUILineGenerator.Points = new Vector2[4] {
  865. 2 * (ScreenLocate.quadUnityVectorList[0] + lo),
  866. 2 * (ScreenLocate.quadUnityVectorList[1] + lo),
  867. 2 * (ScreenLocate.quadUnityVectorList[3] + lo),
  868. 2 * (ScreenLocate.quadUnityVectorList[2] + lo) };
  869. }
  870. }
  871. // 当下拉框选项更改时调用的方法
  872. private void OnDropdownValueChanged(int index, QuadrilateralInCamera[] screenQuads)
  873. {
  874. if (index >= 0 && index < screenQuads.Length)
  875. {
  876. if (screenQuads[index] != null)
  877. {
  878. QuadrilateralInCamera selectedQuad = screenQuads[index];
  879. Debug.Log($"Selected Quad {index + 1}: {selectedQuad}");
  880. CurUILineGenerator.Points = ConvertQuadToPoints(selectedQuad, ScreenLocate.Main.getUVCCameraInfoSize);
  881. }
  882. else
  883. {
  884. Debug.LogWarning($"Selected Quad {index + 1} is null.");
  885. }
  886. }
  887. else
  888. {
  889. Debug.LogWarning("所选索引超出范围!");
  890. }
  891. }
  892. /// <summary>
  893. /// 提取转换四边形的方法
  894. /// </summary>
  895. /// <param name="quad"></param>
  896. /// <param name="texSize"></param>
  897. /// <returns></returns>
  898. public Vector2[] ConvertQuadToPoints(QuadrilateralInCamera quad, Vector2 texSize)
  899. {
  900. if (quad == null || quad.Quad == null || quad.Quad.Count < 4)
  901. {
  902. Debug.LogWarning("Invalid quadrilateral data provided.");
  903. return new Vector2[0]; // 返回空数组以避免异常
  904. }
  905. Vector2 offset = new Vector2(-0.5f, -0.5f); // 假设 'lo' 是某个已定义的偏移量
  906. return new Vector2[4] {
  907. 2 * (new Vector2(quad.Quad[0].x / texSize.x, quad.Quad[0].y / texSize.y) + offset),
  908. 2 * (new Vector2(quad.Quad[1].x / texSize.x, quad.Quad[1].y / texSize.y) + offset),
  909. 2 * (new Vector2(quad.Quad[3].x / texSize.x, quad.Quad[3].y / texSize.y) + offset),
  910. 2 * (new Vector2(quad.Quad[2].x / texSize.x, quad.Quad[2].y / texSize.y) + offset)
  911. };
  912. }
  913. public Vector2[] ConvertPointsToCoordinates(Vector2[] points, Vector2 texSize, Vector2 pivot)
  914. {
  915. if (points == null || points.Length < 1)
  916. {
  917. Debug.LogWarning("Invalid point data provided.");
  918. return new Vector2[0]; // 返回空数组以避免异常
  919. }
  920. Vector2 offset = new Vector2(-0.5f, -0.5f); // 将坐标从中心对齐到左下角对齐
  921. List<Vector2> transformedPoints = new List<Vector2>();
  922. // 遍历所有传入的点进行转换
  923. foreach (var point in points)
  924. {
  925. // 转换每个点,考虑 texSize 和 pivot 偏移
  926. Vector2 transformedPoint = 2 * ((point / texSize) + offset + pivot);
  927. transformedPoints.Add(transformedPoint);
  928. }
  929. return transformedPoints.ToArray();
  930. }
  931. void initToggle()
  932. {
  933. // 监听 Toggle 值的变化
  934. if (curToggle != null)
  935. curToggle.onValueChanged.AddListener(isOn => ToggleLineGenerator(CurUILineGenerator, isOn));
  936. // 监听 Toggle 值的变化
  937. if (autoToggle != null)
  938. autoToggle.onValueChanged.AddListener(isOn => ToggleLineGenerator(AutoUILineGenerator, isOn));
  939. if (semiAutoToggle != null)
  940. semiAutoToggle.onValueChanged.AddListener(isOn => ToggleLineGenerator(SemiAutoUILineGenerator, isOn));
  941. if (manualToggle != null)
  942. manualToggle.onValueChanged.AddListener(isOn => ToggleLineGenerator(ManualUILineGenerator, isOn));
  943. }
  944. // 控制 LineGenerator 的启用/禁用
  945. private void ToggleLineGenerator(LineGenerator lineGenerator, bool isOn)
  946. {
  947. if (lineGenerator != null && lineGenerator.enabled != isOn)
  948. {
  949. lineGenerator.enabled = isOn;
  950. Debug.Log($"{lineGenerator.name} is now {(isOn ? "enabled" : "disabled")}");
  951. }
  952. }
  953. /// <summary>
  954. /// 设置全部显示
  955. /// </summary>
  956. /// <param name="value"></param>
  957. private void SetAllToggle(bool value) {
  958. ToggleLineGenerator(CurUILineGenerator, value);
  959. ToggleLineGenerator(AutoUILineGenerator, value);
  960. ToggleLineGenerator(SemiAutoUILineGenerator, value);
  961. ToggleLineGenerator(ManualUILineGenerator, value);
  962. }
  963. /// <summary>
  964. /// 放大时候同步一次toggle
  965. /// </summary>
  966. private void SyncAllToggle()
  967. {
  968. ToggleLineGenerator(CurUILineGenerator, curToggle.isOn);
  969. ToggleLineGenerator(AutoUILineGenerator, autoToggle.isOn);
  970. ToggleLineGenerator(SemiAutoUILineGenerator, semiAutoToggle.isOn);
  971. ToggleLineGenerator(ManualUILineGenerator, manualToggle.isOn);
  972. }
  973. // 下拉菜单用于显示纹理名称
  974. public Dropdown textureDropdown;
  975. // 按钮用于导出选中的纹理
  976. public Button exportSelectedButton;
  977. // 按钮用于导出所有纹理
  978. public Button exportAllButton;
  979. // 定义纹理名称
  980. string[] textureNames;
  981. /// <summary>
  982. /// 更新一下菜单
  983. /// </summary>
  984. public void UpdateLanguage() {
  985. string[] _textureNames = {
  986. TextAutoLanguage2.GetTextByKey("ScreenAOriginal"), // "A屏幕原图"
  987. TextAutoLanguage2.GetTextByKey("SemiAutoSegmentB"), // "B半自动识别线段"
  988. TextAutoLanguage2.GetTextByKey("BlackWhiteContrastC"), // "C黑白色差"
  989. TextAutoLanguage2.GetTextByKey("RecognitionResultD"), // "D识别结果"
  990. TextAutoLanguage2.GetTextByKey("ColorContrastOverlayE"), // "E色差叠加识别结果"
  991. TextAutoLanguage2.GetTextByKey("SemiAutoAlternativeF") // "F半自动备选线段"
  992. };
  993. textureNames = _textureNames;
  994. // 设置下拉菜单的选项
  995. textureDropdown.ClearOptions();
  996. textureDropdown.AddOptions(new System.Collections.Generic.List<string>(textureNames));
  997. }
  998. void initExport() {
  999. UpdateLanguage();
  1000. // 添加导出选中纹理的按钮点击事件
  1001. exportSelectedButton.onClick.AddListener(() => SaveTextureToLocal(textureDropdown.value));
  1002. // 添加导出所有纹理的按钮点击事件
  1003. exportAllButton.onClick.AddListener(SaveAllTexturesToLocal);
  1004. }
  1005. /// <summary>
  1006. /// 导出所有纹理
  1007. /// </summary>
  1008. public void SaveAllTexturesToLocal()
  1009. {
  1010. for (int i = 0; i < textureNames.Length; i++)
  1011. {
  1012. SaveTextureToLocal(i); // 调用之前定义的保存方法
  1013. }
  1014. }
  1015. /// <summary>
  1016. /// 导出图片
  1017. /// </summary>
  1018. /// <param name="index"></param>
  1019. public void SaveTextureToLocal(int index)
  1020. {
  1021. Texture2D[] outputTexture2D = ScreenLocate.Main.OutputTextures;
  1022. if (outputTexture2D == null || index >= outputTexture2D.Length || outputTexture2D[index] == null)
  1023. {
  1024. Debug.LogError("Invalid texture index or texture is null.index:"+ index);
  1025. return;
  1026. }
  1027. // 定义保存路径
  1028. string time = DateTime.Now.ToString("yyyyMMdd_HHmmss");
  1029. string baseName = $"{time}_Texture_{index}";
  1030. // 检查索引是否在命名数组内
  1031. string fileName = index < textureNames.Length ? textureNames[index] : $"Texture_{index}";
  1032. #if UNITY_ANDROID && !UNITY_EDITOR_WIN
  1033. string path = System.IO.Path.Combine("/storage/emulated/0/Download", $"{baseName}_{fileName}.png"); //public
  1034. #else
  1035. string path = System.IO.Path.Combine(Application.persistentDataPath, $"{baseName}_{fileName}.png");
  1036. #endif
  1037. // 编码纹理为 PNG 格式
  1038. byte[] bytes = outputTexture2D[index].EncodeToPNG();
  1039. // 将字节写入文件
  1040. System.IO.File.WriteAllBytes(path, bytes);
  1041. Debug.Log($"Texture saved as: {path}");
  1042. }
  1043. //下面是处理对象放大缩小
  1044. public RectTransform cameraObj1; // 拖拽你的 CameraSize1 对象到此字段
  1045. public Button toggleButton; // 缩小时使用的按钮
  1046. private Vector2 originalSize;
  1047. private Vector2 originalAnchoredPosition; // 使用 anchoredPosition 代替 localPosition
  1048. private Vector2 originalAnchorMin;
  1049. private Vector2 originalAnchorMax;
  1050. private int originalSiblingIndex; // 保存初始的层级索引
  1051. private bool isFullscreen = false;
  1052. /// <summary>
  1053. /// 测试效果屏幕数据初始化
  1054. /// </summary>
  1055. void InitFullScreen() {
  1056. if (cameraObj1 != null)
  1057. {
  1058. // 保存初始大小、位置和层级索引
  1059. originalSize = cameraObj1.sizeDelta;
  1060. originalAnchoredPosition = cameraObj1.anchoredPosition;
  1061. originalAnchorMin = cameraObj1.anchorMin; // 记录初始 anchorMin
  1062. originalAnchorMax = cameraObj1.anchorMax; // 记录初始 anchorMax
  1063. originalSiblingIndex = cameraObj1.GetSiblingIndex();
  1064. // 为 cameraObj1 添加点击事件
  1065. cameraObj1.GetComponent<Button>().onClick.AddListener(ToggleFullscreen);
  1066. toggleButton.transform.parent.gameObject.SetActive(false);
  1067. }
  1068. if (toggleButton != null)
  1069. {
  1070. // 为按钮添加点击事件以恢复大小
  1071. toggleButton.onClick.AddListener(RestoreSize);
  1072. }
  1073. }
  1074. void ToggleFullscreen()
  1075. {
  1076. if (cameraObj1 == null) return;
  1077. if (!isFullscreen)
  1078. {
  1079. // 设置锚点为全屏,调整位置和偏移量
  1080. cameraObj1.anchorMin = Vector2.zero;
  1081. cameraObj1.anchorMax = Vector2.one;
  1082. cameraObj1.offsetMin = Vector2.zero;
  1083. cameraObj1.offsetMax = Vector2.zero;
  1084. cameraObj1.anchoredPosition = Vector3.zero;
  1085. cameraObj1.SetSiblingIndex(cameraObj1.parent.childCount - 1); // 设置为最上层
  1086. //刷新一次点
  1087. SetLocatePointsToCameraRender(ScreenLocate.quadUnityVectorList, 1, 1);
  1088. toggleButton.transform.parent.gameObject.SetActive(true);
  1089. isFullscreen = true;
  1090. //放大情况根据toggle来显示
  1091. SyncAllToggle();
  1092. }
  1093. }
  1094. void RestoreSize()
  1095. {
  1096. if (cameraObj1 == null || !isFullscreen) return;
  1097. // 恢复锚点和偏移量
  1098. cameraObj1.anchorMin = originalAnchorMin; // 使用在 Start() 中记录的初始锚点
  1099. cameraObj1.anchorMax = originalAnchorMax; // 使用在 Start() 中记录的初始锚点
  1100. cameraObj1.sizeDelta = originalSize;
  1101. cameraObj1.anchoredPosition = originalAnchoredPosition; // 恢复为初始 anchoredPosition
  1102. cameraObj1.SetSiblingIndex(originalSiblingIndex); // 恢复到原本的层级索引
  1103. //刷新一次点
  1104. SetLocatePointsToCameraRender(ScreenLocate.quadUnityVectorList, 1, 1);
  1105. toggleButton.transform.parent.gameObject.SetActive(false);
  1106. isFullscreen = false;
  1107. }
  1108. #endregion
  1109. public void SetLocatePointsToCameraRenderTest(List<Vector2> points, float w, float h)
  1110. {
  1111. Transform pointsTF2 = _cameraRender.transform.Find("PointsTest");
  1112. if (pointsTF2.childCount == points.Count)
  1113. {
  1114. Vector2 texSize = new Vector2(w, h);
  1115. for (int i = 0; i < pointsTF2.childCount; i++)
  1116. {
  1117. Transform pointTF = pointsTF2.GetChild(i);
  1118. Vector2 pos = points[i];
  1119. pointTF.localPosition = pos.pixelToLocalPosition_AnchorCenter(texSize, _cameraRender.rectTransform.rect);
  1120. pointTF.gameObject.SetActive(true);
  1121. }
  1122. }
  1123. else
  1124. {
  1125. for (int i = 0; i < pointsTF2.childCount; i++)
  1126. {
  1127. Transform pointTF = pointsTF2.GetChild(i);
  1128. pointTF.gameObject.SetActive(false);
  1129. }
  1130. }
  1131. }
  1132. void SetShakeFilterValue(float v)
  1133. {
  1134. shakeFilterValue.Set(v);
  1135. _sliderShakeFilter.SetValueWithoutNotify(shakeFilterValue.Get());
  1136. _sliderShakeFilter.transform.Find("Value").GetComponent<Text>().text = shakeFilterValue.Get().ToString("f1");
  1137. infraredCameraHelper.SetShakeFilterValue(shakeFilterValue.Get());
  1138. }
  1139. /// <summary>
  1140. /// 重新设置分辨率
  1141. /// </summary>
  1142. /// <param name="index"></param>
  1143. public void resolutionRestartApp(int index)
  1144. {
  1145. #if UNITY_ANDROID
  1146. //StartCoroutine(RestartOrKillApp());
  1147. //获取第一个分辨率设置后设置size
  1148. switch (index)
  1149. {
  1150. case 0:
  1151. infraredCameraHelper.SetHighCameraResolution();
  1152. resoution.Set(index);
  1153. _dropdownResolution2.SetValueWithoutNotify(index);
  1154. break;
  1155. case 1:
  1156. infraredCameraHelper.SetLowCameraResolution();
  1157. resoution.Set(index);
  1158. _dropdownResolution2.SetValueWithoutNotify(index);
  1159. break;
  1160. }
  1161. #endif
  1162. }
  1163. /// <summary>
  1164. /// 初始化时候,设置的值
  1165. /// </summary>
  1166. /// <param name="index"></param>
  1167. public Vector2 SetDefByIndex(int index = 0)
  1168. {
  1169. //SetResolutionNew 里面对应的下标
  1170. Vector2 vec2 = new Vector2(320, 240);
  1171. switch (index)
  1172. {
  1173. case 0:
  1174. vec2 = new Vector2(320, 240);
  1175. break;
  1176. case 1:
  1177. vec2 = new Vector2(160, 120);
  1178. break;
  1179. }
  1180. return vec2;
  1181. }
  1182. /// <summary>
  1183. /// 当 Dropdown 选择变化时的处理方法
  1184. /// </summary>
  1185. /// <param name="OnResolutionChanged">320x240</param>
  1186. private void OnResolutionChanged(int index)
  1187. {
  1188. #if UNITY_ANDROID
  1189. Debug.Log("Selected Resolution: " + index);
  1190. // 将选定的分辨率转换为实际的宽度和高度
  1191. // 并且需要判断是否存在最低分辨率
  1192. if (index == 1 && currentCameraInfo.ContainsResulutionKey("160x120"))
  1193. {
  1194. // 在这里你可以根据实际需要设置屏幕分辨率或进行其他操作
  1195. infraredCameraHelper.SetLowCameraResolution();
  1196. // 保存选择的分辨率到 PlayerPrefs
  1197. resoution.Set(index);
  1198. }
  1199. else if(index == 0){
  1200. //如果是0就 使用高分辨率
  1201. infraredCameraHelper.SetHighCameraResolution();
  1202. // 保存选择的分辨率到 PlayerPrefs
  1203. resoution.Set(index);
  1204. }
  1205. #endif
  1206. }
  1207. /// <summary>
  1208. /// 野鸭关卡测试初始值
  1209. /// </summary>
  1210. /// <param name="optionIndex"></param>
  1211. public void SetDuckLevelTest(int optionIndex)
  1212. {
  1213. //选择下标+1
  1214. int v = optionIndex + 1;
  1215. duckHunterLevel.Set(v);
  1216. int defLevel = (int)duckHunterLevel.Get() - 1 < 0 ? 0 : (int)duckHunterLevel.Get() - 1;
  1217. _duckLevelDropdown.SetValueWithoutNotify(defLevel);
  1218. //_duckLevelDropdown.transform.Find("Value").GetComponent<Text>().text = defLevel+"";
  1219. }
  1220. void OnClick_Reset()
  1221. {
  1222. //SetBrightness(1);
  1223. //SetSaturation(1);
  1224. //SetContrast(1);
  1225. SetShakeFilterValue(6);
  1226. SetLineWidth(4);
  1227. SetFanWidth(90);
  1228. SetInfraredFilterValue(0.8f);
  1229. SetCaptureValue(30.0f);
  1230. SetDelayValue(30.0f);
  1231. //重置为第一关
  1232. SetDuckLevelTest(0);
  1233. }
  1234. public void OnClickClearAll() {
  1235. PlayerPrefs.DeleteAll();
  1236. // 保存更改
  1237. PlayerPrefs.Save();
  1238. StartCoroutine(RestartOrKillApp());
  1239. }
  1240. void OnClick_ScreenLocateManual()
  1241. {
  1242. ViewManager2.ShowView(ViewManager2.Path_InfraredScreenPositioningView);
  1243. FindObjectOfType<InfraredScreenPositioningView>().enterFromInfraredDemo = true;
  1244. }
  1245. void OnClick_ScreenLocateManualAuto()
  1246. {
  1247. ResetCenterOffset();
  1248. ResetPositioningData();
  1249. infraredCameraHelper.EnterScreenLocateManualAuto();
  1250. }
  1251. public void OnClick_SetAdjustPointsOffset()
  1252. {
  1253. var _sl = ScreenLocate.Main;
  1254. var buffer = _sl.infraredSpotBuffer;
  1255. if (buffer != null)
  1256. {
  1257. for (int i = 0; i < buffer.Length; i++)
  1258. {
  1259. if (buffer[i].CameraLocation != null)
  1260. {
  1261. Debug.Log("CameraLocation:"+buffer[i].CameraLocation.Value);
  1262. var centerOffset = infraredCameraHelper.GetCenterOffset(buffer[i].CameraLocation.Value, "CameraLocation");
  1263. Debug.Log("CenterOffset: " + centerOffset);
  1264. var uvCenterOffset = infraredCameraHelper.GetCenterOffset(buffer[i].ScreenUV.Value, "ScreenUV");
  1265. Debug.Log("UvCenterOffset: " + uvCenterOffset);
  1266. //如果是新手教程场景里面的校准
  1267. InfraredGuider infraredGuiderObj = FindObjectOfType<InfraredGuider>();
  1268. if (infraredGuiderObj != null)
  1269. {
  1270. GameObject infraredGuiderGameObject = infraredGuiderObj.gameObject;
  1271. infraredGuiderGameObject.GetComponent<InfraredGuider>().SetTitleAfterCalibration();
  1272. }
  1273. }
  1274. }
  1275. }
  1276. }
  1277. /// <summary>
  1278. /// 重置中心点
  1279. /// </summary>
  1280. public void ResetCenterOffset() {
  1281. infraredCameraHelper.ResetCenterOffset();
  1282. }
  1283. /// <summary>
  1284. /// 撤销中心点
  1285. /// </summary>
  1286. public void RevokeCenterOffset()
  1287. {
  1288. infraredCameraHelper.RevokeCenterOffset();
  1289. }
  1290. /// <summary>
  1291. /// 重置定位数据
  1292. /// </summary>
  1293. public void ResetPositioningData(bool bSyncLocal = false) {
  1294. infraredCameraHelper.ClearInfraredPositioningData(bSyncLocal);
  1295. }
  1296. void SetCaptureValue(float v)
  1297. {
  1298. captureValue.Set(v);
  1299. _sliderCapture.SetValueWithoutNotify(captureValue.Get());
  1300. _sliderCapture.transform.Find("Value").GetComponent<Text>().text = captureValue.Get().ToString("f1");
  1301. infraredCameraHelper.SetCapture((int)captureValue.Get());
  1302. }
  1303. void SetDelayValue(float v)
  1304. {
  1305. delayValue.Set(v);
  1306. _sliderDelay.SetValueWithoutNotify(delayValue.Get());
  1307. _sliderDelay.transform.Find("Value").GetComponent<Text>().text = delayValue.Get().ToString("f1");
  1308. infraredCameraHelper.SetDelay((int)delayValue.Get());
  1309. }
  1310. #endregion
  1311. #region 相机感光度(默认修改对比度)
  1312. public void onSetSliderCustomValue(Slider _slider, float min = 0.0f, float max = 10.0f)
  1313. {
  1314. onSetSliderValue(_slider, "PU_CONTRAST", min, max);
  1315. }
  1316. public void onSliderCustomEvent(float value, float min = 0.0f, float max = 10.0f)
  1317. {
  1318. onSliderEvent(value, "PU_CONTRAST", min, max);
  1319. }
  1320. public void onSetSliderCustomBrightnessValue(Slider _slider, float min = 0.0f, float max = 10.0f)
  1321. {
  1322. onSetSliderValue(_slider, "PU_BRIGHTNESS", min, max);
  1323. }
  1324. public void onSliderCustomBrightnessEvent(float value, float min = 0.0f, float max = 10.0f)
  1325. {
  1326. onSliderEvent(value, "PU_BRIGHTNESS", min, max);
  1327. }
  1328. public void onSetSliderValue(Slider _slider,string typeStr = "PU_CONTRAST", float min = 0.0f, float max = 10.0f)
  1329. {
  1330. if (BluetoothWindows.IsWindows()) {
  1331. float v = typeStr == "PU_CONTRAST"?infraredCameraHelper.GetContrast(): infraredCameraHelper.GetBrightness();
  1332. // 目标区间 [0, 10] 的边界值
  1333. double targetMin = min;
  1334. double targetMax = max;
  1335. double originalMin = -1;
  1336. double originalMax = 1;
  1337. // 计算转换后的值
  1338. double v2 = MapValue(v, originalMin, originalMax, targetMin, targetMax);
  1339. Debug.Log("PC获取相机的感光度 "+ typeStr + " :" + v + " = " + v2);
  1340. _slider.SetValueWithoutNotify((float)v2);
  1341. return;
  1342. }
  1343. //功能也改为UVC的对比度
  1344. if (running)
  1345. {
  1346. //string typeStr = "PU_CONTRAST";//"PU_BRIGHTNESS";
  1347. //UInt64 _VALUE = currentCameraInfo.GetTypeByName(typeStr);
  1348. UVCCtrlInfo _UVCCtrlInfo = currentCameraInfo.GetInfo(typeStr);
  1349. float v = currentCameraInfo.GetValue(typeStr); // infraredCameraHelper.GetBrightness();
  1350. //float v2 = (v / _UVCCtrlInfo.max) * 10;
  1351. // 目标区间 [0, 10] 的边界值
  1352. double targetMin = min;
  1353. double targetMax = max;
  1354. double originalMin = _UVCCtrlInfo.min;
  1355. double originalMax = _UVCCtrlInfo.max;
  1356. // 计算转换后的值
  1357. double v2 = MapValue(v, originalMin, originalMax, targetMin, targetMax);
  1358. Debug.Log("获取相机的感光度" + typeStr + ": " + v + " = " + v2);
  1359. _slider.SetValueWithoutNotify((float)v2);
  1360. }
  1361. else _slider.SetValueWithoutNotify(5);
  1362. }
  1363. public void onSliderEvent(float value, string typeStr = "PU_CONTRAST", float min = 0.0f,float max = 10.0f)
  1364. {
  1365. // string typeStr = "PU_CONTRAST";// "PU_BRIGHTNESS";
  1366. //pc
  1367. if (BluetoothWindows.IsWindows())
  1368. {
  1369. Transform trans = _cameraParameterPanel.transform.Find(typeStr);
  1370. Slider slider = trans.GetComponent<Slider>();
  1371. Text textObj = trans.Find("text").GetComponent<Text>();
  1372. // 原始区间和目标区间的边界值
  1373. double originalMin = min;
  1374. double originalMax = max;
  1375. double targetMin = -1;
  1376. double targetMax = 1;
  1377. // 计算转换后的值
  1378. double result = MapValue(value, originalMin, originalMax, targetMin, targetMax);
  1379. float _current = (float)result;
  1380. //Debug.Log("_current:" + _current + " , result:" + result);
  1381. textObj.text = _current + "";
  1382. slider.value = _current;
  1383. if (typeStr == "PU_CONTRAST")
  1384. {
  1385. infraredCameraHelper.SetContrast(_current);
  1386. pcCONTRAST.Set(_current);
  1387. }
  1388. else {
  1389. infraredCameraHelper.SetBrightness(_current);
  1390. pcBRIGHTNESS.Set(_current);
  1391. }
  1392. return;
  1393. }
  1394. //修改亮度时,调试界面的亮度也应该一起修改
  1395. //功能也改为UVC的对比度
  1396. if (running)
  1397. {
  1398. //Slider slider = transform.Find("InfraredCamera/Layout/SliderBrightness")
  1399. // .GetComponent<Slider>();
  1400. // UInt64 _VALUE = currentCameraInfo.GetTypeByName(typeStr);
  1401. Transform trans = _cameraParameterPanel.transform.Find(typeStr);
  1402. Slider slider = trans.GetComponent<Slider>();
  1403. Text textObj = trans.Find("text").GetComponent<Text>();
  1404. UVCCtrlInfo _UVCCtrlInfo = currentCameraInfo.GetInfo(typeStr);
  1405. int _currentUVCValue = currentCameraInfo.GetValue(typeStr);
  1406. //value 0 ~ 10
  1407. // 原始区间和目标区间的边界值
  1408. double originalMin = min;
  1409. double originalMax = max;
  1410. double targetMin = _UVCCtrlInfo.min;
  1411. double targetMax = _UVCCtrlInfo.max;
  1412. // 计算转换后的值
  1413. double result = MapValue(value, originalMin, originalMax, targetMin, targetMax);
  1414. int _current = (int)(result);
  1415. Debug.Log("_current:" + value + " , result:" + result);
  1416. textObj.text = _current + "";
  1417. slider.value = _current;
  1418. //dUVCParameters.GetValueOrDefault(typeStr).Set(_current);
  1419. //存储初始值,设置一次到UVC参数
  1420. if (_currentUVCValue != _current) currentCameraInfo.SetValue(typeStr, _current);
  1421. }
  1422. }
  1423. public static double MapValue(double value, double originalMin, double originalMax, double targetMin, double targetMax)
  1424. {
  1425. // 线性插值公式
  1426. return targetMin + (value - originalMin) * (targetMax - targetMin) / (originalMax - originalMin);
  1427. }
  1428. #endregion
  1429. #region 绘制线段部分
  1430. public void SetLineWidth(float v)
  1431. {
  1432. lineWidth.Set(v);
  1433. _sliderLineWidth.SetValueWithoutNotify(lineWidth.Get());
  1434. _sliderLineWidth.transform.Find("Value").GetComponent<Text>().text = lineWidth.Get().ToString("f1");
  1435. }
  1436. public void SetFanWidth(float v)
  1437. {
  1438. fanWidth.Set(v);
  1439. _fanWidth.SetValueWithoutNotify(fanWidth.Get());
  1440. _fanWidth.transform.Find("Value").GetComponent<Text>().text = fanWidth.Get().ToString("f1");
  1441. }
  1442. #endregion
  1443. #region 亮度检测部分
  1444. public void SetInfraredFilterValue(float v)
  1445. {
  1446. infraredFileterValue.Set(v);
  1447. _infraredFilter.SetValueWithoutNotify(infraredFileterValue.Get());
  1448. _infraredFilter.transform.Find("Value").GetComponent<Text>().text = infraredFileterValue.Get().ToString("f1");
  1449. infraredCameraHelper.SetInfraredLocateBrightnessThreshold(infraredFileterValue.Get());
  1450. }
  1451. #endregion
  1452. public void resetInfraredPlayerPrefs()
  1453. {
  1454. //测试用
  1455. PlayerPrefs.DeleteKey("entry-guider-infrared-" + LoginMgr.myUserInfo.id);
  1456. PlayerPrefs.DeleteKey("hideInfraredBowAndArrow");
  1457. }
  1458. #region 显示Log部分信息
  1459. [SerializeField] Text _calibrationFixedText;
  1460. [SerializeField] Text _cameraSizeText;
  1461. [SerializeField] Text _quadUnityVectorListText;
  1462. /// <summary>
  1463. /// 校准时候的固定值分辨率
  1464. /// </summary>
  1465. /// <param name="v"></param>
  1466. public void SetCalibrationFixedText(Vector2 v)
  1467. {
  1468. _calibrationFixedText.text = v.x + "*" + v.y;
  1469. }
  1470. /// <summary>
  1471. /// 渲染摄像机当前分辨率
  1472. /// </summary>
  1473. /// <param name="v"></param>
  1474. public void SetCameraSizeText(Vector2 v)
  1475. {
  1476. _cameraSizeText.text = v.x + "*" + v.y;
  1477. }
  1478. /// <summary>
  1479. /// 渲染摄像机识别点
  1480. /// </summary>
  1481. /// <param name="v"></param>
  1482. public void SetQuadUnityVectorListText(string v)
  1483. {
  1484. _quadUnityVectorListText.text = v;
  1485. }
  1486. #endregion
  1487. }
  1488. public class ParamFloatValue
  1489. {
  1490. private string _saveKey;
  1491. private float _valueDefault;
  1492. private bool _valueLoaded;
  1493. private float _value;
  1494. public ParamFloatValue(string saveKey, float valueDefault)
  1495. {
  1496. _saveKey = saveKey;
  1497. _valueDefault = valueDefault;
  1498. }
  1499. public float Get()
  1500. {
  1501. if (!_valueLoaded) _value = PlayerPrefs.GetFloat(_saveKey, _valueDefault);
  1502. return _value;
  1503. }
  1504. public void Set(float value)
  1505. {
  1506. _value = value;
  1507. PlayerPrefs.SetFloat(_saveKey, _value);
  1508. PlayerPrefs.Save();
  1509. }
  1510. }