UserInfoCheck.cs 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using LitJson;
  4. using UnityEngine;
  5. using UnityEngine.UI;
  6. using static Manager;
  7. public class UserInfoCheck : MonoBehaviour
  8. {
  9. public GameObject savesuccess;
  10. public GameObject savefail;
  11. public Text tacc;
  12. public InputField iname;
  13. public InputField ibumen;
  14. public InputField izhiwu;
  15. public InputField ibeizhu;
  16. UserInfo uinfo ;
  17. private void OnEnable()
  18. {
  19. if (DataManager.Instance)
  20. {
  21. DataManager.Instance.getuserinfo((msg) => {
  22. uinfo =msg;
  23. Invoke("updatedata",0.5f);
  24. });
  25. }
  26. }
  27. void updatedata()
  28. {
  29. tacc.text = uinfo.count;
  30. iname.text = uinfo.name;
  31. ibumen.text = uinfo.position;
  32. izhiwu.text = uinfo.dept;
  33. ibeizhu.text = uinfo.notes;
  34. }
  35. public void changeInfo()
  36. {
  37. UserInfo uinfo =new UserInfo();
  38. uinfo.name = iname.text;
  39. uinfo.dept = izhiwu.text;
  40. uinfo.position = ibumen.text;
  41. uinfo.notes = ibeizhu.text;
  42. DataManager.Instance.setuserinfo(uinfo,(msg) => {
  43. JsonData d = JsonMapper.ToObject(msg);
  44. try{
  45. if(d["data"]==null)
  46. {
  47. savefail.GetComponentInChildren<Text>().text = d["message"].ToString();
  48. savefail.SetActive(true);
  49. }
  50. else
  51. {
  52. savesuccess.SetActive(true);
  53. Invoke("savecloes",2f);
  54. }
  55. }
  56. catch{
  57. savefail.GetComponentInChildren<Text>().text = "失败";
  58. savefail.SetActive(true);
  59. }
  60. });
  61. }
  62. void savecloes()
  63. {
  64. savesuccess.SetActive(false);
  65. MainCenterManager.Instance.showMain();
  66. }
  67. }