InfraredDemo.cs 80 KB

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