StatusController.cs 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using Newtonsoft.Json;
  5. using UnityEngine;
  6. using UnityEngine.SceneManagement;
  7. using UnityEngine.UI;
  8. using UnityEngine.UIElements;
  9. using ZXing;
  10. using ZXing.QrCode;
  11. //using UnityEngine.UI;
  12. using Button = UnityEngine.UIElements.Button;
  13. //using Image = UnityEngine.UIElements.Image;
  14. /* 这个controller 是用于控制 Status UI菜单的
  15. * 包含显示狗的最新状态
  16. * 添加狗,把狗送给朋友,删除狗
  17. */
  18. public class StatusController : MonoBehaviour
  19. {
  20. private Button backButton, cancelButton;
  21. private Label nameLabel, genderLabel, breedLabel, hostLabel, hostnameLabel, ageLabel, ageValueLabel, commandLabel, commandValueLabel, statusLabel, statusValueLabel, resetVoice;
  22. private Label leftArrow, rightArrow;
  23. private Label addLabel, transfer, remove, callback;
  24. private float transferCountStartTime;
  25. DogProperty puppy;
  26. private VisualElement selectElement, statusElement, transferElement, QRcode;
  27. private StausUIPage currentPage = StausUIPage.Status;
  28. // 转移狗使用的变量
  29. private Label transferMsgLabel;
  30. private string transferMsgOrigin;
  31. private string transferCode;
  32. // Start is called before the first frame update
  33. void OnEnable()
  34. {
  35. var root = GetComponent<UIDocument>().rootVisualElement;
  36. // 状态相关的控件
  37. statusElement = root.Q<VisualElement>("statusUI");
  38. backButton = root.Q<Button>("back");
  39. nameLabel = root.Q<Label>("name");
  40. genderLabel = root.Q<Label>("gender");
  41. breedLabel = root.Q<Label>("breed");
  42. hostLabel = root.Q<Label>("host");
  43. hostnameLabel = root.Q<Label>("hostname");
  44. ageLabel = root.Q<Label>("age");
  45. ageValueLabel = root.Q<Label>("ageValue");
  46. commandLabel = root.Q<Label>("command");
  47. commandValueLabel = root.Q<Label>("commandValue");
  48. resetVoice = root.Q<Label>("resetVoice");
  49. statusLabel = root.Q<Label>("status");
  50. statusValueLabel = root.Q<Label>("statusValue");
  51. selectElement = root.Q("selectElement");
  52. leftArrow = root.Q<Label>("leftArrow");
  53. rightArrow = root.Q<Label>("rightArrow");
  54. addLabel = root.Q<Label>("add");
  55. transfer = root.Q<Label>("transfer");
  56. remove = root.Q<Label>("remove");
  57. callback = root.Q<Label>("callback");
  58. // 转移狗的相关控件
  59. transferMsgLabel = root.Q<Label>("transferMsg");
  60. QRcode = root.Q<VisualElement>("QRcode");
  61. cancelButton = root.Q<Button>("cancel");
  62. transferElement = root.Q<VisualElement>("transferElement");
  63. // 绑定事件
  64. backButton.clicked += BackBtnClick;
  65. cancelButton.clicked += CancelTransferBtnClick;
  66. leftArrow.RegisterCallback<ClickEvent>(e => LeftArrowClicked(e));
  67. rightArrow.RegisterCallback<ClickEvent>(e => RightArrowClicked(e));
  68. addLabel.RegisterCallback<ClickEvent>(e => AddClick(e));
  69. remove.RegisterCallback<ClickEvent>(e => RemoveClick(e));
  70. transfer.RegisterCallback<ClickEvent>(e => TransferClick(e));
  71. resetVoice.RegisterCallback<ClickEvent>(e => ResetVoiceClick(e));
  72. // 箭头是否显示
  73. if (UserProperty.dogs.Count > 1)
  74. {
  75. leftArrow.visible = true;
  76. rightArrow.visible = true;
  77. }
  78. else
  79. {
  80. leftArrow.visible = false;
  81. rightArrow.visible = false;
  82. }
  83. // 根据用户名下狗的数量判断是否显示transfer按键
  84. if (UserProperty.dogs.Count > 1)
  85. {
  86. transfer.style.display = DisplayStyle.Flex;
  87. }
  88. else
  89. {
  90. transfer.style.display = DisplayStyle.None;
  91. }
  92. // 如果用户狗的数量达到系统规定上限,则隐藏add按键
  93. if (UserProperty.dogs.Count >= EnviromentSetting.maxDogQty)
  94. {
  95. addLabel.style.display = DisplayStyle.None;
  96. }
  97. else
  98. {
  99. addLabel.style.display = DisplayStyle.Flex;
  100. }
  101. }
  102. //private void Start()
  103. //{
  104. //}
  105. // Update is called once per frame
  106. void Update()
  107. {
  108. // 刷新狗的数据
  109. // puppy = UserProperty.dogs[GameData.focusDog];
  110. // StatusPageUpdate();
  111. // LabelLanguageSetting();
  112. // StatusSummary();
  113. if (currentPage == StausUIPage.Transfer)
  114. {
  115. float ts = Time.time - transferCountStartTime;
  116. if (ts > 120f)
  117. {
  118. // todo 超过120秒,关闭二维码
  119. transferElement.style.display = DisplayStyle.None;
  120. statusElement.style.display = DisplayStyle.Flex;
  121. currentPage = StausUIPage.Status;
  122. }
  123. else
  124. {
  125. // todo 未超过120秒,保持二维码显示
  126. transferElement.style.display = DisplayStyle.Flex;
  127. statusElement.style.display = DisplayStyle.None;
  128. currentPage = StausUIPage.Transfer;
  129. string remainingTime = Mathf.RoundToInt(120 - ts).ToString();
  130. string transferMsg = transferMsgOrigin.Replace("<<second>>", remainingTime);
  131. transferMsgLabel.text = transferMsg;
  132. }
  133. }
  134. if (currentPage == StausUIPage.Status)
  135. {
  136. // 刷新狗的数据
  137. puppy = UserProperty.dogs[GameData.focusDog];
  138. StatusPageUpdate();
  139. LabelLanguageSetting();
  140. StatusSummary();
  141. CommandSummary();
  142. }
  143. }
  144. //void BackPressed()
  145. //{
  146. // if (backButton != null)
  147. // {
  148. // var root = GetComponent<UIDocument>();
  149. // Destroy(GameObject.Find(root.GetComponentInParent<Canvas>().name));
  150. // }
  151. //}
  152. void StatusPageUpdate()
  153. {
  154. //backButton.clicked += BackPressed;
  155. nameLabel.text = puppy.dog_name;
  156. if (puppy.sex == 1)
  157. {
  158. genderLabel.text = "♂";
  159. }
  160. else
  161. {
  162. genderLabel.text = "♀";
  163. }
  164. breedLabel.text = puppy.breed;
  165. foreach (var breed in EnviromentSetting.dogBreeds)
  166. {
  167. if (breed.breed == puppy.breed)
  168. {
  169. breedLabel.text = breed.name[EnviromentSetting.languageCode];
  170. break;
  171. }
  172. }
  173. hostnameLabel.text = UserProperty.name;
  174. // 计算狗生日和现在时间差
  175. TimeSpan ts = System.DateTime.Now - puppy.birthday;
  176. ageValueLabel.text = ts.Days.ToString();
  177. }
  178. void LabelLanguageSetting()
  179. {
  180. // 设置status UI界面里面label和按键的语言显示
  181. string textValue = GameTool.GetValueAtPath(EnviromentSetting.languageData, new string[] { "statusUI", "button", "back", EnviromentSetting.languageCode });
  182. backButton.text = textValue;
  183. textValue = GameTool.GetValueAtPath(EnviromentSetting.languageData, new string[] { "statusUI", "button", "cancel", EnviromentSetting.languageCode });
  184. cancelButton.text = textValue;
  185. textValue = GameTool.GetValueAtPath(EnviromentSetting.languageData, new string[] { "statusUI", "label", "host", EnviromentSetting.languageCode });
  186. hostLabel.text = textValue;
  187. textValue = GameTool.GetValueAtPath(EnviromentSetting.languageData, new string[] { "statusUI", "label", "days", EnviromentSetting.languageCode });
  188. ageLabel.text = textValue;
  189. textValue = GameTool.GetValueAtPath(EnviromentSetting.languageData, new string[] { "statusUI", "label", "status", EnviromentSetting.languageCode });
  190. statusLabel.text = textValue;
  191. textValue = GameTool.GetValueAtPath(EnviromentSetting.languageData, new string[] { "statusUI", "label", "command", EnviromentSetting.languageCode });
  192. commandLabel.text = textValue;
  193. textValue = GameTool.GetValueAtPath(EnviromentSetting.languageData, new string[] { "statusUI", "label", "resetVoice", EnviromentSetting.languageCode });
  194. resetVoice.text = textValue;
  195. textValue = GameTool.GetValueAtPath(EnviromentSetting.languageData, new string[] { "statusUI", "message", "scan_QRcode", EnviromentSetting.languageCode });
  196. transferMsgOrigin = textValue;
  197. }
  198. void CommandSummary()
  199. {
  200. // 先清空状态文字,应对切换多只狗
  201. commandValueLabel.text = null;
  202. // 汇总宠物状态
  203. string summary = String.Empty;
  204. if (puppy.commandSit)
  205. {
  206. summary += GameTool.GetValueAtPath(EnviromentSetting.languageData, new string[] { "statusUI", "command", "Sit", EnviromentSetting.languageCode });
  207. summary += ", ";
  208. }
  209. if (puppy.commandStand)
  210. {
  211. summary += GameTool.GetValueAtPath(EnviromentSetting.languageData, new string[] { "statusUI", "command", "Stand", EnviromentSetting.languageCode });
  212. summary += ", ";
  213. }
  214. if (puppy.commandBark)
  215. {
  216. summary += GameTool.GetValueAtPath(EnviromentSetting.languageData, new string[] { "statusUI", "command", "Bark", EnviromentSetting.languageCode });
  217. summary += ", ";
  218. }
  219. if (puppy.commandShake)
  220. {
  221. summary += GameTool.GetValueAtPath(EnviromentSetting.languageData, new string[] { "statusUI", "command", "Shake", EnviromentSetting.languageCode });
  222. summary += ", ";
  223. }
  224. if (puppy.commandLieDown)
  225. {
  226. summary += GameTool.GetValueAtPath(EnviromentSetting.languageData, new string[] { "statusUI", "command", "LieDown", EnviromentSetting.languageCode });
  227. summary += ", ";
  228. }
  229. if (puppy.commandTouch)
  230. {
  231. summary += GameTool.GetValueAtPath(EnviromentSetting.languageData, new string[] { "statusUI", "command", "Touch", EnviromentSetting.languageCode });
  232. summary += ", ";
  233. }
  234. if (puppy.commandDeath)
  235. {
  236. summary += GameTool.GetValueAtPath(EnviromentSetting.languageData, new string[] { "statusUI", "command", "Death", EnviromentSetting.languageCode });
  237. summary += ", ";
  238. }
  239. if (puppy.commandTurnL)
  240. {
  241. summary += GameTool.GetValueAtPath(EnviromentSetting.languageData, new string[] { "statusUI", "command", "TurnL", EnviromentSetting.languageCode });
  242. summary += ", ";
  243. }
  244. if (puppy.commandTurnR)
  245. {
  246. summary += GameTool.GetValueAtPath(EnviromentSetting.languageData, new string[] { "statusUI", "command", "TurnR", EnviromentSetting.languageCode });
  247. summary += ", ";
  248. }
  249. if (summary == String.Empty)
  250. {
  251. summary = GameTool.GetValueAtPath(EnviromentSetting.languageData, new string[] { "statusUI", "command", "none", EnviromentSetting.languageCode });
  252. }
  253. else
  254. {
  255. // 去掉最后一个逗号
  256. summary = summary.Substring(0, summary.Length - 2);
  257. commandValueLabel.text = summary;
  258. }
  259. }
  260. void StatusSummary()
  261. {
  262. // 先清空状态文字,应对切换多只狗
  263. statusValueLabel.text = null;
  264. // 汇总宠物状态
  265. string summary = "";
  266. if (puppy.satiety < 30)
  267. {
  268. if (puppy.satiety < 10)
  269. {
  270. // 小于10,达到L2警告
  271. summary += GameTool.GetValueAtPath(EnviromentSetting.languageData, new string[] { "statusUI", "status", "satiety_2", EnviromentSetting.languageCode });
  272. }
  273. else
  274. {
  275. // 不小于10,触发L1警告
  276. summary += GameTool.GetValueAtPath(EnviromentSetting.languageData, new string[] { "statusUI", "status", "satiety_1", EnviromentSetting.languageCode });
  277. }
  278. summary += "<br>";
  279. }
  280. if (puppy.stamina < 30)
  281. {
  282. if (puppy.stamina < 10)
  283. {
  284. // 小于10,达到L2警告
  285. summary += GameTool.GetValueAtPath(EnviromentSetting.languageData, new string[] { "statusUI", "status", "stamina_2", EnviromentSetting.languageCode });
  286. }
  287. else
  288. {
  289. // 不小于10,触发L1警告
  290. summary += GameTool.GetValueAtPath(EnviromentSetting.languageData, new string[] { "statusUI", "status", "stamina_1", EnviromentSetting.languageCode });
  291. }
  292. summary += "<br>";
  293. }
  294. if (puppy.thirsty < 30)
  295. {
  296. if (puppy.thirsty < 10)
  297. {
  298. // 小于10,达到L2警告
  299. summary += GameTool.GetValueAtPath(EnviromentSetting.languageData, new string[] { "statusUI", "status", "thirsty_2", EnviromentSetting.languageCode });
  300. }
  301. else
  302. {
  303. // 不小于10,触发L1警告
  304. summary += GameTool.GetValueAtPath(EnviromentSetting.languageData, new string[] { "statusUI", "status", "thirsty_1", EnviromentSetting.languageCode });
  305. }
  306. summary += "<br>";
  307. }
  308. if (puppy.healthy < 30)
  309. {
  310. if (puppy.healthy < 10)
  311. {
  312. // 小于10,达到L2警告
  313. summary += GameTool.GetValueAtPath(EnviromentSetting.languageData, new string[] { "statusUI", "status", "healthy_2", EnviromentSetting.languageCode });
  314. }
  315. else
  316. {
  317. // 不小于10,触发L1警告
  318. summary += GameTool.GetValueAtPath(EnviromentSetting.languageData, new string[] { "statusUI", "status", "healthy_1", EnviromentSetting.languageCode });
  319. }
  320. summary += "<br>";
  321. }
  322. if (puppy.clean < 30)
  323. {
  324. if (puppy.clean < 10)
  325. {
  326. // 小于10,达到L2警告
  327. summary += GameTool.GetValueAtPath(EnviromentSetting.languageData, new string[] { "statusUI", "status", "clean_2", EnviromentSetting.languageCode });
  328. }
  329. else
  330. {
  331. // 不小于10,触发L1警告
  332. summary += GameTool.GetValueAtPath(EnviromentSetting.languageData, new string[] { "statusUI", "status", "clean_1", EnviromentSetting.languageCode });
  333. }
  334. summary += "<br>";
  335. }
  336. if (puppy.obesity > 70)
  337. {
  338. if (puppy.obesity > 90)
  339. {
  340. // 小于10,达到L2警告
  341. summary += GameTool.GetValueAtPath(EnviromentSetting.languageData, new string[] { "statusUI", "status", "obesity_2", EnviromentSetting.languageCode });
  342. }
  343. else
  344. {
  345. // 不小于10,触发L1警告
  346. summary += GameTool.GetValueAtPath(EnviromentSetting.languageData, new string[] { "statusUI", "status", "obesity_1", EnviromentSetting.languageCode });
  347. }
  348. summary += "<br>";
  349. }
  350. // 如果没有任何异常,返回正常的状态
  351. if (summary.Length == 0)
  352. {
  353. summary = GameTool.GetValueAtPath(EnviromentSetting.languageData, new string[] { "statusUI", "status", "normal", EnviromentSetting.languageCode });
  354. }
  355. statusValueLabel.text = summary;
  356. }
  357. void RightArrowClicked(ClickEvent e)
  358. {
  359. GameData.focusDog++;
  360. if (GameData.focusDog == UserProperty.dogs.Count)
  361. {
  362. GameData.focusDog = 0;
  363. }
  364. }
  365. void LeftArrowClicked(ClickEvent e)
  366. {
  367. GameData.focusDog--;
  368. if (GameData.focusDog == -1)
  369. {
  370. GameData.focusDog = UserProperty.dogs.Count - 1;
  371. }
  372. }
  373. void ResetVoiceClick(ClickEvent e)
  374. {
  375. // todo 重置狗的语音训练数据提示
  376. string msg = GameTool.GetValueAtPath(EnviromentSetting.languageData, new string[] { "game_message", "reset_voice_reminder", EnviromentSetting.languageCode });
  377. msg = msg.Replace("<<dog_name>>", UserProperty.dogs[GameData.focusDog].dog_name);
  378. MessageBoxController.YorN_Message(msg, ResetVoiceRequest);
  379. }
  380. void ResetVoiceRequest()
  381. {
  382. // todo 重置狗的声音提交
  383. string url = "/api/voice/reset/";
  384. Dictionary<string, string> formData = new();
  385. WWWForm form = new();
  386. form.AddField("user_id", UserProperty.userId);
  387. form.AddField("dog_id", UserProperty.GetDogIdByIndex(GameData.focusDog));
  388. form.AddField("type", "all");
  389. StartCoroutine(WebController.PostRequest(url, form, callback: ResetVoiceCallback));
  390. }
  391. void ResetVoiceCallback(string json)
  392. {
  393. // todo 重置狗的声音提交成功
  394. var data = JsonConvert.DeserializeObject<Dictionary<string, object>>(json);
  395. if (data != null && data["status"].ToString() == "success")
  396. {
  397. // 跳转login场景,重新登录
  398. MaskTransitions.TransitionManager.Instance.LoadLevel("Login");
  399. }
  400. else
  401. {
  402. Debug.Log(data["message"]);
  403. }
  404. }
  405. // 点击返回按钮
  406. void BackBtnClick()
  407. {
  408. var uiPlaceholder = GameObject.Find("UI Placeholder");
  409. if (uiPlaceholder != null)
  410. {
  411. var shoppingUI = uiPlaceholder.transform.Find("Status").gameObject;
  412. var vamUI = uiPlaceholder.transform.Find("VoiceAndMenu").gameObject;
  413. shoppingUI.SetActive(false);
  414. vamUI.SetActive(true);
  415. }
  416. }
  417. void CancelTransferBtnClick()
  418. {
  419. CancelTransferDogRequest();
  420. statusElement.style.display = DisplayStyle.Flex;
  421. transferElement.style.display = DisplayStyle.None;
  422. currentPage = StausUIPage.Status;
  423. }
  424. void AddClick(ClickEvent e)
  425. {
  426. // if (UserProperty.level == "basic")
  427. // {
  428. // string msg = GameTool.GetValueAtPath(EnviromentSetting.languageData, new string[] { "game_message", "add_dog_fail_account_level", EnviromentSetting.languageCode });
  429. // MessageBoxController.ShowMessage(msg);
  430. // }
  431. if (UserProperty.dogs.Count >= EnviromentSetting.maxDogQty)
  432. {
  433. string msg = GameTool.GetValueAtPath(EnviromentSetting.languageData, new string[] { "game_message", "add_dog_fail_no_more", EnviromentSetting.languageCode });
  434. MessageBoxController.ShowMessage(msg);
  435. }
  436. else
  437. {
  438. string msg = GameTool.GetValueAtPath(EnviromentSetting.languageData, new string[] { "game_message", "add_dog_prompt", EnviromentSetting.languageCode });
  439. MessageBoxController.YorN_Message(msg, SwitchAddNewDog);
  440. }
  441. }
  442. // 跳转login 场景添加新的狗
  443. void SwitchAddNewDog()
  444. {
  445. GameData.subScene = "Login_InitDog";
  446. MaskTransitions.TransitionManager.Instance.LoadLevel("Login");
  447. }
  448. void RemoveClick(ClickEvent e)
  449. {
  450. string msg = GameTool.GetValueAtPath(EnviromentSetting.languageData, new string[] { "game_message", "foster_dog_prompt", EnviromentSetting.languageCode });
  451. msg = msg.Replace("<<dog name>>", UserProperty.dogs[GameData.focusDog].dog_name);
  452. MessageBoxController.YorN_Message(msg, FosterDog);
  453. }
  454. // 点击确认remove后调用寄养的程序
  455. void FosterDog()
  456. {
  457. // 检测用户是否有200金币
  458. if (UserProperty.coin >= 200)
  459. {
  460. // todo 寄养某一只狗,并扣除金币
  461. }
  462. }
  463. // 找回寄养的狗
  464. void CallbackDogClick(ClickEvent e)
  465. {
  466. }
  467. void TransferClick(ClickEvent e)
  468. {
  469. // TODO 添加代码增加面对面赠送狗的功能
  470. string msg = GameTool.GetValueAtPath(EnviromentSetting.languageData, new string[] { "game_message", "transfer_dog_prompt", EnviromentSetting.languageCode });
  471. msg = msg.Replace("<<dog name>>", UserProperty.dogs[GameData.focusDog].dog_name);
  472. MessageBoxController.YorN_Message(msg, TransferDogRequest);
  473. }
  474. void TransferDogRequest()
  475. {
  476. string url = "/api/transfer_dog/send/";
  477. Dictionary<string, string> formData = new();
  478. WWWForm form = new();
  479. form.AddField("user_id", UserProperty.userId);
  480. form.AddField("dog_id", UserProperty.GetDogIdByIndex(GameData.focusDog));
  481. StartCoroutine(WebController.PostRequest(url, form, callback: TransferDogCallback));
  482. }
  483. void TransferDogCallback(string json)
  484. {
  485. var data = JsonConvert.DeserializeObject<Dictionary<string, object>>(json);
  486. if (data != null && data["status"].ToString() == "success")
  487. {
  488. transferCountStartTime = Time.time;
  489. currentPage = StausUIPage.Transfer;
  490. transferCode = data["transfer_code"].ToString();
  491. transferCode = "ARdog://transfer/" + transferCode;
  492. Texture2D qrCodeTexture = GenerateQRCode(transferCode);
  493. QRcode.style.backgroundImage = new StyleBackground(qrCodeTexture);
  494. }
  495. else
  496. {
  497. Debug.Log(data["message"]);
  498. }
  499. }
  500. void CancelTransferDogRequest()
  501. {
  502. string url = "/api/transfer_dog/cancel/";
  503. Dictionary<string, string> formData = new();
  504. WWWForm form = new();
  505. form.AddField("user_id", UserProperty.userId);
  506. form.AddField("transfer_code", transferCode);
  507. StartCoroutine(WebController.PostRequest(url, form, callback: CancelTransferDogCallback));
  508. }
  509. void CancelTransferDogCallback(string json)
  510. {
  511. var data = JsonConvert.DeserializeObject<Dictionary<string, object>>(json);
  512. if (data != null && data["status"].ToString() == "success")
  513. {
  514. Debug.Log("取消转移成功");
  515. }
  516. else
  517. {
  518. Debug.Log(data["message"]);
  519. }
  520. }
  521. Texture2D GenerateQRCode(string text)
  522. {
  523. // 创建二维码编码器
  524. BarcodeWriter barcodeWriter = new BarcodeWriter
  525. {
  526. Format = BarcodeFormat.QR_CODE,
  527. Options = new QrCodeEncodingOptions
  528. {
  529. Width = 256,
  530. Height = 256
  531. }
  532. };
  533. // 生成二维码
  534. Color32[] color32 = barcodeWriter.Write(text);
  535. // 创建纹理并设置像素
  536. Texture2D qrCodeTexture = new Texture2D(256, 256);
  537. qrCodeTexture.SetPixels32(color32);
  538. qrCodeTexture.Apply();
  539. return qrCodeTexture;
  540. // 将纹理转换为Sprite
  541. // Sprite qrCodeSprite = Sprite.Create(qrCodeTexture, new Rect(0, 0, qrCodeTexture.width, qrCodeTexture.height), new Vector2(0.5f, 0.5f));
  542. // return qrCodeSprite;
  543. }
  544. }
  545. enum StausUIPage
  546. {
  547. Status,
  548. Transfer,
  549. }