1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using Api;
- using Plugins.CxShine.page;
- using Plugins.CxShine.UIUtil;
- using UI;
- using UI.Common;
- using UI.Hall;
- using Unity.VisualScripting;
- using UnityEngine;
- using UnityEngine.UI;
- public class UpdateInfoComp : MonoBehaviour
- {
- public Text NickName;
- public InputField NameInput;
- public Text UserId;
- public Image Avatar;
- public Transform AvatarsContainer;
- public GameObject AvatarItem;
- private string _avatar;
- private void Start()
- {
- initAvatars();
- RefreshSelfUI();
- }
- private void initAvatars()
- {
- ContainerUtil.RemoveAllChild(this, AvatarsContainer);
- for (int i = 0; i < 20; i++)
- {
- int a = i;
- var o = Instantiate(AvatarItem, AvatarsContainer, false);
- var innerImage = o.GetComponent<Transform>().GetChild(0)
- .GetComponent<Image>();
- o.GetOrAddComponent<Button>().onClick.AddListener(() =>
- {
- _avatar = a + "";
- AvatarUtil.DisplayAvatar(Avatar, _avatar);
- });
- AvatarUtil.DisplayAvatar(innerImage, i + "");
- }
- }
- public void A__ClickSave()
- {
- string name = NameInput.text;
- if (String.IsNullOrEmpty(name))
- {
- name = AccountManager.Instance.selfInfo.name;
- }
- ApiComp.Instance.UpdateSelfInfo(_avatar, name, data =>
- {
- TipsComp.ShowTips("Success!");
- HallComp.Instance.BackToHallAndRefreshUI();
- gameObject.GetComponent<PageComp>().A__ClosePage();
- },
- (errCode, errMsg) => { TipsComp.ShowTips(errMsg); });
- }
- public void RefreshSelfUI()
- {
- AccountManager.Instance.requestSelfInfo(data =>
- {
- _avatar = AccountManager.Instance.selfInfo.avatar;
- NickName.text = AccountManager.Instance.selfInfo.name + "";
- UserId.text = "ID:" + AccountManager.Instance.selfInfo.playerId + "";
- AvatarUtil.DisplayAvatar(Avatar, AccountManager.Instance.selfInfo.avatar);
- }, (code, msg) => { TipsComp.ShowTips(msg); });
- }
- }
|