UpdateInfoComp.cs 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using Api;
  5. using Plugins.CxShine.page;
  6. using Plugins.CxShine.UIUtil;
  7. using UI;
  8. using UI.Common;
  9. using UI.Hall;
  10. using Unity.VisualScripting;
  11. using UnityEngine;
  12. using UnityEngine.UI;
  13. public class UpdateInfoComp : MonoBehaviour
  14. {
  15. public Text NickName;
  16. public InputField NameInput;
  17. public Text UserId;
  18. public Image Avatar;
  19. public Transform AvatarsContainer;
  20. public GameObject AvatarItem;
  21. private string _avatar;
  22. private void Start()
  23. {
  24. initAvatars();
  25. RefreshSelfUI();
  26. }
  27. private void initAvatars()
  28. {
  29. ContainerUtil.RemoveAllChild(this, AvatarsContainer);
  30. for (int i = 0; i < 20; i++)
  31. {
  32. int a = i;
  33. var o = Instantiate(AvatarItem, AvatarsContainer, false);
  34. var innerImage = o.GetComponent<Transform>().GetChild(0)
  35. .GetComponent<Image>();
  36. o.GetOrAddComponent<Button>().onClick.AddListener(() =>
  37. {
  38. _avatar = a + "";
  39. AvatarUtil.DisplayAvatar(Avatar, _avatar);
  40. });
  41. AvatarUtil.DisplayAvatar(innerImage, i + "");
  42. }
  43. }
  44. public void A__ClickSave()
  45. {
  46. string name = NameInput.text;
  47. if (String.IsNullOrEmpty(name))
  48. {
  49. name = AccountManager.Instance.selfInfo.name;
  50. }
  51. ApiComp.Instance.UpdateSelfInfo(_avatar, name, data =>
  52. {
  53. TipsComp.ShowTips("Success!");
  54. HallComp.Instance.BackToHallAndRefreshUI();
  55. gameObject.GetComponent<PageComp>().A__ClosePage();
  56. },
  57. (errCode, errMsg) => { TipsComp.ShowTips(errMsg); });
  58. }
  59. public void RefreshSelfUI()
  60. {
  61. AccountManager.Instance.requestSelfInfo(data =>
  62. {
  63. _avatar = AccountManager.Instance.selfInfo.avatar;
  64. NickName.text = AccountManager.Instance.selfInfo.name + "";
  65. UserId.text = "ID:" + AccountManager.Instance.selfInfo.playerId + "";
  66. AvatarUtil.DisplayAvatar(Avatar, AccountManager.Instance.selfInfo.avatar);
  67. }, (code, msg) => { TipsComp.ShowTips(msg); });
  68. }
  69. }