InfraredDemo.cs 63 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732
  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. infraredCameraHelper.EnterScreenLocateManualAuto();
  1248. }
  1249. public void OnClick_SetAdjustPointsOffset()
  1250. {
  1251. var _sl = ScreenLocate.Main;
  1252. var buffer = _sl.infraredSpotBuffer;
  1253. if (buffer != null)
  1254. {
  1255. for (int i = 0; i < buffer.Length; i++)
  1256. {
  1257. if (buffer[i].CameraLocation != null)
  1258. {
  1259. Debug.Log("CameraLocation:"+buffer[i].CameraLocation.Value);
  1260. var centerOffset = infraredCameraHelper.GetCenterOffset(buffer[i].CameraLocation.Value, "CameraLocation");
  1261. Debug.Log("CenterOffset: " + centerOffset);
  1262. var uvCenterOffset = infraredCameraHelper.GetCenterOffset(buffer[i].ScreenUV.Value, "ScreenUV");
  1263. Debug.Log("UvCenterOffset: " + uvCenterOffset);
  1264. //如果是新手教程场景里面的校准
  1265. InfraredGuider infraredGuiderObj = FindObjectOfType<InfraredGuider>();
  1266. if (infraredGuiderObj != null)
  1267. {
  1268. GameObject infraredGuiderGameObject = infraredGuiderObj.gameObject;
  1269. infraredGuiderGameObject.GetComponent<InfraredGuider>().SetTitleAfterCalibration();
  1270. }
  1271. }
  1272. }
  1273. }
  1274. }
  1275. /// <summary>
  1276. /// 重置中心点
  1277. /// </summary>
  1278. public void ResetCenterOffset() {
  1279. infraredCameraHelper.ResetCenterOffset();
  1280. }
  1281. /// <summary>
  1282. /// 撤销中心点
  1283. /// </summary>
  1284. public void RevokeCenterOffset()
  1285. {
  1286. infraredCameraHelper.RevokeCenterOffset();
  1287. }
  1288. /// <summary>
  1289. /// 重置定位数据
  1290. /// </summary>
  1291. public void ResetPositioningData(bool bSyncLocal = false) {
  1292. infraredCameraHelper.ClearInfraredPositioningData(bSyncLocal);
  1293. }
  1294. void SetCaptureValue(float v)
  1295. {
  1296. captureValue.Set(v);
  1297. _sliderCapture.SetValueWithoutNotify(captureValue.Get());
  1298. _sliderCapture.transform.Find("Value").GetComponent<Text>().text = captureValue.Get().ToString("f1");
  1299. infraredCameraHelper.SetCapture((int)captureValue.Get());
  1300. }
  1301. void SetDelayValue(float v)
  1302. {
  1303. delayValue.Set(v);
  1304. _sliderDelay.SetValueWithoutNotify(delayValue.Get());
  1305. _sliderDelay.transform.Find("Value").GetComponent<Text>().text = delayValue.Get().ToString("f1");
  1306. infraredCameraHelper.SetDelay((int)delayValue.Get());
  1307. }
  1308. #endregion
  1309. #region 相机感光度(默认修改对比度)
  1310. public void onSetSliderCustomValue(Slider _slider, float min = 0.0f, float max = 10.0f)
  1311. {
  1312. onSetSliderValue(_slider, "PU_CONTRAST", min, max);
  1313. }
  1314. public void onSliderCustomEvent(float value, float min = 0.0f, float max = 10.0f)
  1315. {
  1316. onSliderEvent(value, "PU_CONTRAST", min, max);
  1317. }
  1318. public void onSetSliderCustomBrightnessValue(Slider _slider, float min = 0.0f, float max = 10.0f)
  1319. {
  1320. onSetSliderValue(_slider, "PU_BRIGHTNESS", min, max);
  1321. }
  1322. public void onSliderCustomBrightnessEvent(float value, float min = 0.0f, float max = 10.0f)
  1323. {
  1324. onSliderEvent(value, "PU_BRIGHTNESS", min, max);
  1325. }
  1326. public void onSetSliderValue(Slider _slider,string typeStr = "PU_CONTRAST", float min = 0.0f, float max = 10.0f)
  1327. {
  1328. if (BluetoothWindows.IsWindows()) {
  1329. float v = typeStr == "PU_CONTRAST"?infraredCameraHelper.GetContrast(): infraredCameraHelper.GetBrightness();
  1330. // 目标区间 [0, 10] 的边界值
  1331. double targetMin = min;
  1332. double targetMax = max;
  1333. double originalMin = -1;
  1334. double originalMax = 1;
  1335. // 计算转换后的值
  1336. double v2 = MapValue(v, originalMin, originalMax, targetMin, targetMax);
  1337. Debug.Log("PC获取相机的感光度 "+ typeStr + " :" + v + " = " + v2);
  1338. _slider.SetValueWithoutNotify((float)v2);
  1339. return;
  1340. }
  1341. //功能也改为UVC的对比度
  1342. if (running)
  1343. {
  1344. //string typeStr = "PU_CONTRAST";//"PU_BRIGHTNESS";
  1345. //UInt64 _VALUE = currentCameraInfo.GetTypeByName(typeStr);
  1346. UVCCtrlInfo _UVCCtrlInfo = currentCameraInfo.GetInfo(typeStr);
  1347. float v = currentCameraInfo.GetValue(typeStr); // infraredCameraHelper.GetBrightness();
  1348. //float v2 = (v / _UVCCtrlInfo.max) * 10;
  1349. // 目标区间 [0, 10] 的边界值
  1350. double targetMin = min;
  1351. double targetMax = max;
  1352. double originalMin = _UVCCtrlInfo.min;
  1353. double originalMax = _UVCCtrlInfo.max;
  1354. // 计算转换后的值
  1355. double v2 = MapValue(v, originalMin, originalMax, targetMin, targetMax);
  1356. Debug.Log("获取相机的感光度" + typeStr + ": " + v + " = " + v2);
  1357. _slider.SetValueWithoutNotify((float)v2);
  1358. }
  1359. else _slider.SetValueWithoutNotify(5);
  1360. }
  1361. public void onSliderEvent(float value, string typeStr = "PU_CONTRAST", float min = 0.0f,float max = 10.0f)
  1362. {
  1363. // string typeStr = "PU_CONTRAST";// "PU_BRIGHTNESS";
  1364. //pc
  1365. if (BluetoothWindows.IsWindows())
  1366. {
  1367. Transform trans = _cameraParameterPanel.transform.Find(typeStr);
  1368. Slider slider = trans.GetComponent<Slider>();
  1369. Text textObj = trans.Find("text").GetComponent<Text>();
  1370. // 原始区间和目标区间的边界值
  1371. double originalMin = min;
  1372. double originalMax = max;
  1373. double targetMin = -1;
  1374. double targetMax = 1;
  1375. // 计算转换后的值
  1376. double result = MapValue(value, originalMin, originalMax, targetMin, targetMax);
  1377. float _current = (float)result;
  1378. //Debug.Log("_current:" + _current + " , result:" + result);
  1379. textObj.text = _current + "";
  1380. slider.value = _current;
  1381. if (typeStr == "PU_CONTRAST")
  1382. {
  1383. infraredCameraHelper.SetContrast(_current);
  1384. pcCONTRAST.Set(_current);
  1385. }
  1386. else {
  1387. infraredCameraHelper.SetBrightness(_current);
  1388. pcBRIGHTNESS.Set(_current);
  1389. }
  1390. return;
  1391. }
  1392. //修改亮度时,调试界面的亮度也应该一起修改
  1393. //功能也改为UVC的对比度
  1394. if (running)
  1395. {
  1396. //Slider slider = transform.Find("InfraredCamera/Layout/SliderBrightness")
  1397. // .GetComponent<Slider>();
  1398. // UInt64 _VALUE = currentCameraInfo.GetTypeByName(typeStr);
  1399. Transform trans = _cameraParameterPanel.transform.Find(typeStr);
  1400. Slider slider = trans.GetComponent<Slider>();
  1401. Text textObj = trans.Find("text").GetComponent<Text>();
  1402. UVCCtrlInfo _UVCCtrlInfo = currentCameraInfo.GetInfo(typeStr);
  1403. int _currentUVCValue = currentCameraInfo.GetValue(typeStr);
  1404. //value 0 ~ 10
  1405. // 原始区间和目标区间的边界值
  1406. double originalMin = min;
  1407. double originalMax = max;
  1408. double targetMin = _UVCCtrlInfo.min;
  1409. double targetMax = _UVCCtrlInfo.max;
  1410. // 计算转换后的值
  1411. double result = MapValue(value, originalMin, originalMax, targetMin, targetMax);
  1412. int _current = (int)(result);
  1413. Debug.Log("_current:" + value + " , result:" + result);
  1414. textObj.text = _current + "";
  1415. slider.value = _current;
  1416. //dUVCParameters.GetValueOrDefault(typeStr).Set(_current);
  1417. //存储初始值,设置一次到UVC参数
  1418. if (_currentUVCValue != _current) currentCameraInfo.SetValue(typeStr, _current);
  1419. }
  1420. }
  1421. public static double MapValue(double value, double originalMin, double originalMax, double targetMin, double targetMax)
  1422. {
  1423. // 线性插值公式
  1424. return targetMin + (value - originalMin) * (targetMax - targetMin) / (originalMax - originalMin);
  1425. }
  1426. #endregion
  1427. #region 绘制线段部分
  1428. public void SetLineWidth(float v)
  1429. {
  1430. lineWidth.Set(v);
  1431. _sliderLineWidth.SetValueWithoutNotify(lineWidth.Get());
  1432. _sliderLineWidth.transform.Find("Value").GetComponent<Text>().text = lineWidth.Get().ToString("f1");
  1433. }
  1434. public void SetFanWidth(float v)
  1435. {
  1436. fanWidth.Set(v);
  1437. _fanWidth.SetValueWithoutNotify(fanWidth.Get());
  1438. _fanWidth.transform.Find("Value").GetComponent<Text>().text = fanWidth.Get().ToString("f1");
  1439. }
  1440. #endregion
  1441. #region 亮度检测部分
  1442. public void SetInfraredFilterValue(float v)
  1443. {
  1444. infraredFileterValue.Set(v);
  1445. _infraredFilter.SetValueWithoutNotify(infraredFileterValue.Get());
  1446. _infraredFilter.transform.Find("Value").GetComponent<Text>().text = infraredFileterValue.Get().ToString("f1");
  1447. infraredCameraHelper.SetInfraredLocateBrightnessThreshold(infraredFileterValue.Get());
  1448. }
  1449. #endregion
  1450. public void resetInfraredPlayerPrefs()
  1451. {
  1452. //测试用
  1453. PlayerPrefs.DeleteKey("entry-guider-infrared-" + LoginMgr.myUserInfo.id);
  1454. PlayerPrefs.DeleteKey("hideInfraredBowAndArrow");
  1455. }
  1456. #region 显示Log部分信息
  1457. [SerializeField] Text _calibrationFixedText;
  1458. [SerializeField] Text _cameraSizeText;
  1459. [SerializeField] Text _quadUnityVectorListText;
  1460. /// <summary>
  1461. /// 校准时候的固定值分辨率
  1462. /// </summary>
  1463. /// <param name="v"></param>
  1464. public void SetCalibrationFixedText(Vector2 v)
  1465. {
  1466. _calibrationFixedText.text = v.x + "*" + v.y;
  1467. }
  1468. /// <summary>
  1469. /// 渲染摄像机当前分辨率
  1470. /// </summary>
  1471. /// <param name="v"></param>
  1472. public void SetCameraSizeText(Vector2 v)
  1473. {
  1474. _cameraSizeText.text = v.x + "*" + v.y;
  1475. }
  1476. /// <summary>
  1477. /// 渲染摄像机识别点
  1478. /// </summary>
  1479. /// <param name="v"></param>
  1480. public void SetQuadUnityVectorListText(string v)
  1481. {
  1482. _quadUnityVectorListText.text = v;
  1483. }
  1484. #endregion
  1485. }
  1486. public class ParamFloatValue
  1487. {
  1488. private string _saveKey;
  1489. private float _valueDefault;
  1490. private bool _valueLoaded;
  1491. private float _value;
  1492. public ParamFloatValue(string saveKey, float valueDefault)
  1493. {
  1494. _saveKey = saveKey;
  1495. _valueDefault = valueDefault;
  1496. }
  1497. public float Get()
  1498. {
  1499. if (!_valueLoaded) _value = PlayerPrefs.GetFloat(_saveKey, _valueDefault);
  1500. return _value;
  1501. }
  1502. public void Set(float value)
  1503. {
  1504. _value = value;
  1505. PlayerPrefs.SetFloat(_saveKey, _value);
  1506. PlayerPrefs.Save();
  1507. }
  1508. }