651 lines
23 KiB
C#
651 lines
23 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Globalization;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using UObject = UnityEngine.Object;
|
|
|
|
namespace XGame
|
|
{
|
|
public sealed class PlayerProfileModule : MonoBehaviour
|
|
{
|
|
private const string HudPrefabPath = "Assets/Game/Art/UI/Prefab/UI_PlayerProfileHud.prefab";
|
|
private const string PanelPrefabPath = "Assets/Game/Art/UI/Prefab/UI_PlayerProfilePanel.prefab";
|
|
private const string AvatarPickerPrefabPath = "Assets/Game/Art/UI/Prefab/UI_PlayerAvatarPicker.prefab";
|
|
private const float PreviewAvatarFrameFill = 0.58f;
|
|
|
|
private GameObject hudView;
|
|
private GameObject detailView;
|
|
private GameObject avatarPickerView;
|
|
private bool openingHud;
|
|
private bool openingDetail;
|
|
private bool openingAvatarPicker;
|
|
private int openVersion;
|
|
private int avatarPickerVersion;
|
|
private int pendingAvatarId;
|
|
|
|
private TMP_Text hudNicknameText;
|
|
private TMP_Text hudLevelText;
|
|
private TMP_Text hudExpText;
|
|
private Image hudAvatarImage;
|
|
private Image detailAvatarImage;
|
|
private RectTransform hudExpFill;
|
|
private RectTransform hudExpTrack;
|
|
|
|
private Image avatarPickerPreviewImage;
|
|
private TMP_Text avatarPickerHintText;
|
|
private readonly Dictionary<int, Sprite> avatarSpriteCache = new Dictionary<int, Sprite>();
|
|
private readonly HashSet<int> loadingAvatarIds = new HashSet<int>();
|
|
private readonly Dictionary<int, Image> avatarPickerAvatarImages = new Dictionary<int, Image>();
|
|
private readonly Dictionary<int, GameObject> avatarPickerSelectedStates = new Dictionary<int, GameObject>();
|
|
|
|
private void OnEnable()
|
|
{
|
|
PlayerProfileStore.Changed += OnProfileChanged;
|
|
}
|
|
|
|
private void OnDisable()
|
|
{
|
|
PlayerProfileStore.Changed -= OnProfileChanged;
|
|
}
|
|
|
|
public bool IsOpen => hudView != null;
|
|
|
|
public IEnumerator OpenAsync()
|
|
{
|
|
if (hudView != null || openingHud)
|
|
{
|
|
RefreshAll(PlayerProfileStore.Current);
|
|
yield break;
|
|
}
|
|
|
|
openingHud = true;
|
|
int version = ++openVersion;
|
|
UObject loaded = null;
|
|
yield return XResLoader.coLoadRes(HudPrefabPath, typeof(GameObject), obj => loaded = obj);
|
|
openingHud = false;
|
|
|
|
if (version != openVersion)
|
|
{
|
|
yield break;
|
|
}
|
|
|
|
GameObject prefab = loaded as GameObject;
|
|
if (prefab == null)
|
|
{
|
|
Debug.LogError("[PlayerProfileModule] load HUD prefab failed: " + HudPrefabPath);
|
|
yield break;
|
|
}
|
|
|
|
hudView = Instantiate(prefab);
|
|
UIManager.AttachTo(UILayer.HUD, hudView);
|
|
CacheHudControls();
|
|
BindHudEvents();
|
|
RefreshHud(PlayerProfileStore.Current);
|
|
}
|
|
|
|
public void Close()
|
|
{
|
|
openVersion++;
|
|
openingHud = false;
|
|
openingDetail = false;
|
|
openingAvatarPicker = false;
|
|
avatarPickerVersion++;
|
|
if (hudView != null)
|
|
{
|
|
Destroy(hudView);
|
|
}
|
|
if (detailView != null)
|
|
{
|
|
Destroy(detailView);
|
|
}
|
|
if (avatarPickerView != null)
|
|
{
|
|
Destroy(avatarPickerView);
|
|
}
|
|
hudView = null;
|
|
detailView = null;
|
|
hudNicknameText = null;
|
|
hudLevelText = null;
|
|
hudExpText = null;
|
|
hudExpFill = null;
|
|
hudExpTrack = null;
|
|
hudAvatarImage = null;
|
|
detailAvatarImage = null;
|
|
avatarPickerView = null;
|
|
avatarPickerPreviewImage = null;
|
|
avatarPickerHintText = null;
|
|
pendingAvatarId = 0;
|
|
avatarPickerAvatarImages.Clear();
|
|
avatarPickerSelectedStates.Clear();
|
|
loadingAvatarIds.Clear();
|
|
avatarSpriteCache.Clear();
|
|
}
|
|
|
|
private void OnProfileChanged(PlayerProfileData profile)
|
|
{
|
|
RefreshAll(profile);
|
|
}
|
|
|
|
private void RefreshAll(PlayerProfileData profile)
|
|
{
|
|
RefreshHud(profile);
|
|
RefreshDetail(profile);
|
|
}
|
|
|
|
private void CacheHudControls()
|
|
{
|
|
if (hudView == null)
|
|
{
|
|
return;
|
|
}
|
|
hudNicknameText = FindComponent<TMP_Text>(hudView, "Txt_Nickname");
|
|
hudLevelText = FindComponent<TMP_Text>(hudView, "Txt_Level");
|
|
hudExpText = FindComponent<TMP_Text>(hudView, "Txt_Exp");
|
|
hudAvatarImage = FindComponent<Image>(hudView, "Img_AvatarIcon");
|
|
ArrangeAvatarIconBehindFrame(hudView);
|
|
hudExpTrack = FindRect(hudView, "Img_ExpBg");
|
|
hudExpFill = FindRect(hudView, "Img_ExpFill");
|
|
}
|
|
|
|
private void BindHudEvents()
|
|
{
|
|
Button button = FindComponent<Button>(hudView, "Btn_Profile");
|
|
if (button == null)
|
|
{
|
|
return;
|
|
}
|
|
button.onClick.RemoveAllListeners();
|
|
button.onClick.AddListener(OpenDetail);
|
|
}
|
|
|
|
private void RefreshHud(PlayerProfileData profile)
|
|
{
|
|
if (hudView == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
profile = profile ?? PlayerProfileStore.Current;
|
|
if (hudNicknameText != null) hudNicknameText.text = profile.Nickname;
|
|
if (hudLevelText != null) hudLevelText.text = "Lv." + profile.Lv;
|
|
if (hudExpText != null) hudExpText.text = profile.Exp + "/" + profile.RequiredExp;
|
|
RefreshAvatarImage(hudAvatarImage, profile.AvatarId);
|
|
|
|
if (hudExpTrack != null && hudExpFill != null)
|
|
{
|
|
float width = Mathf.Max(0f, hudExpTrack.rect.width);
|
|
hudExpFill.sizeDelta = new Vector2(width * profile.Experience01, hudExpFill.sizeDelta.y);
|
|
}
|
|
}
|
|
|
|
private void OpenDetail()
|
|
{
|
|
if (detailView != null || openingDetail)
|
|
{
|
|
RefreshDetail(PlayerProfileStore.Current);
|
|
return;
|
|
}
|
|
XWCoroutine.StartCo(CoOpenDetail());
|
|
}
|
|
|
|
private IEnumerator CoOpenDetail()
|
|
{
|
|
openingDetail = true;
|
|
UObject loaded = null;
|
|
yield return XResLoader.coLoadRes(PanelPrefabPath, typeof(GameObject), obj => loaded = obj);
|
|
openingDetail = false;
|
|
|
|
GameObject prefab = loaded as GameObject;
|
|
if (prefab == null)
|
|
{
|
|
Debug.LogError("[PlayerProfileModule] load detail prefab failed: " + PanelPrefabPath);
|
|
yield break;
|
|
}
|
|
|
|
detailView = Instantiate(prefab);
|
|
UIManager.AttachTo(UILayer.Dialog, detailView);
|
|
detailAvatarImage = FindComponent<Image>(detailView, "Img_AvatarIcon");
|
|
ArrangeAvatarIconBehindFrame(detailView);
|
|
BindDetailEvents();
|
|
RefreshDetail(PlayerProfileStore.Current);
|
|
}
|
|
|
|
private void BindDetailEvents()
|
|
{
|
|
BindCloseButton("Btn_Close");
|
|
BindCloseButton("Img_Mask");
|
|
Button avatarButton = FindComponent<Button>(detailView, "Img_AvatarFrame");
|
|
if (avatarButton != null)
|
|
{
|
|
avatarButton.onClick.RemoveAllListeners();
|
|
avatarButton.onClick.AddListener(OpenAvatarPicker);
|
|
}
|
|
}
|
|
|
|
private void BindCloseButton(string nodeName)
|
|
{
|
|
Button button = FindComponent<Button>(detailView, nodeName);
|
|
if (button == null)
|
|
{
|
|
return;
|
|
}
|
|
button.onClick.RemoveAllListeners();
|
|
button.onClick.AddListener(CloseDetail);
|
|
}
|
|
|
|
private void CloseDetail()
|
|
{
|
|
CloseAvatarPicker();
|
|
if (detailView != null)
|
|
{
|
|
Destroy(detailView);
|
|
}
|
|
detailView = null;
|
|
}
|
|
|
|
private void RefreshDetail(PlayerProfileData profile)
|
|
{
|
|
if (detailView == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
profile = profile ?? PlayerProfileStore.Current;
|
|
ArrangeAvatarIconBehindFrame(detailView);
|
|
SetText("Txt_Nickname", profile.Nickname);
|
|
SetText("Txt_Uid", "UID: " + profile.Uid);
|
|
SetText("Txt_RoleType", profile.RoleType.ToString());
|
|
SetText("Txt_Gold", profile.Gold.ToString());
|
|
SetText("Txt_Diamond", profile.Diamond.ToString());
|
|
SetText("Txt_Lv", profile.Lv.ToString());
|
|
SetText("Txt_Exp", profile.Exp + "/" + profile.RequiredExp);
|
|
SetText("Txt_Hp", profile.Hp + "/" + profile.HpMax);
|
|
SetText("Txt_Mp", profile.Mp + "/" + profile.MpMax);
|
|
SetText("Txt_Ad", profile.Ad.ToString());
|
|
SetText("Txt_Ap", profile.Ap.ToString());
|
|
SetText("Txt_AtkSpeed", profile.AtkSpeed.ToString("0.##"));
|
|
SetText("Txt_MoveSpeed", profile.MoveSpeed.ToString("0.##"));
|
|
RefreshAvatarImage(detailAvatarImage, profile.AvatarId);
|
|
}
|
|
|
|
private void ArrangeAvatarIconBehindFrame(GameObject root)
|
|
{
|
|
ArrangeGraphicBehindFrame(root, "Img_AvatarFrame", "Img_AvatarIcon");
|
|
}
|
|
|
|
private void ArrangeGraphicBehindFrame(GameObject root, string frameName, string graphicName)
|
|
{
|
|
Transform frame = FindTransform(root, frameName);
|
|
Transform graphic = FindTransform(root, graphicName);
|
|
if (frame == null || graphic == null || frame.parent == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
RectTransform frameRect = frame as RectTransform;
|
|
RectTransform graphicRect = graphic as RectTransform;
|
|
Vector2 graphicSize = graphicRect == null ? Vector2.zero : graphicRect.sizeDelta;
|
|
|
|
if (graphic.parent != frame.parent)
|
|
{
|
|
graphic.SetParent(frame.parent, true);
|
|
}
|
|
|
|
if (frameRect != null && graphicRect != null)
|
|
{
|
|
graphicRect.anchorMin = frameRect.anchorMin;
|
|
graphicRect.anchorMax = frameRect.anchorMax;
|
|
graphicRect.pivot = frameRect.pivot;
|
|
graphicRect.anchoredPosition = frameRect.anchoredPosition;
|
|
graphicRect.sizeDelta = graphicSize;
|
|
}
|
|
|
|
if (graphic.GetSiblingIndex() > frame.GetSiblingIndex())
|
|
{
|
|
graphic.SetSiblingIndex(frame.GetSiblingIndex());
|
|
}
|
|
}
|
|
|
|
private void RefreshAvatarImage(Image image, int avatarId)
|
|
{
|
|
if (image == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
int normalizedId = PlayerAvatarCatalog.NormalizeId(avatarId);
|
|
if (avatarSpriteCache.TryGetValue(normalizedId, out Sprite cachedSprite))
|
|
{
|
|
image.sprite = cachedSprite;
|
|
return;
|
|
}
|
|
|
|
if (loadingAvatarIds.Add(normalizedId))
|
|
{
|
|
XWCoroutine.StartCo(CoLoadAvatarSprite(normalizedId, image));
|
|
}
|
|
}
|
|
|
|
private IEnumerator CoLoadAvatarSprite(int avatarId, Image target)
|
|
{
|
|
Sprite sprite = null;
|
|
if (XResLoader.m_ABMode == 1)
|
|
{
|
|
yield return CoCacheAvatarSpritesFromPickerPrefab();
|
|
avatarSpriteCache.TryGetValue(avatarId, out sprite);
|
|
}
|
|
|
|
if (sprite == null)
|
|
{
|
|
string path = PlayerAvatarCatalog.GetAssetPath(avatarId);
|
|
UObject loaded = null;
|
|
yield return XResLoader.coLoadRes(path, typeof(Sprite), obj => loaded = obj);
|
|
sprite = loaded as Sprite;
|
|
}
|
|
|
|
if (sprite == null)
|
|
{
|
|
yield return CoCacheAvatarSpritesFromPickerPrefab();
|
|
avatarSpriteCache.TryGetValue(avatarId, out sprite);
|
|
}
|
|
|
|
loadingAvatarIds.Remove(avatarId);
|
|
|
|
if (sprite == null)
|
|
{
|
|
Debug.LogError("[PlayerProfileModule] load avatar failed: " + PlayerAvatarCatalog.GetAssetPath(avatarId));
|
|
yield break;
|
|
}
|
|
|
|
avatarSpriteCache[avatarId] = sprite;
|
|
if (PlayerAvatarCatalog.NormalizeId(PlayerProfileStore.Current.AvatarId) != avatarId)
|
|
{
|
|
yield break;
|
|
}
|
|
|
|
ApplyAvatarSprite(target, sprite);
|
|
ApplyAvatarSprite(hudAvatarImage, sprite);
|
|
ApplyAvatarSprite(detailAvatarImage, sprite);
|
|
}
|
|
|
|
private IEnumerator CoCacheAvatarSpritesFromPickerPrefab()
|
|
{
|
|
if (avatarPickerView != null)
|
|
{
|
|
CacheAvatarSpritesFromRoot(avatarPickerView);
|
|
yield break;
|
|
}
|
|
|
|
UObject loaded = null;
|
|
yield return XResLoader.coLoadRes(AvatarPickerPrefabPath, typeof(GameObject), obj => loaded = obj);
|
|
CacheAvatarSpritesFromRoot(loaded as GameObject);
|
|
}
|
|
|
|
private static void ApplyAvatarSprite(Image target, Sprite sprite)
|
|
{
|
|
if (target != null)
|
|
{
|
|
target.sprite = sprite;
|
|
}
|
|
}
|
|
|
|
private void OpenAvatarPicker()
|
|
{
|
|
if (avatarPickerView != null || openingAvatarPicker)
|
|
{
|
|
RefreshAvatarPicker();
|
|
return;
|
|
}
|
|
XWCoroutine.StartCo(CoOpenAvatarPicker());
|
|
}
|
|
|
|
private IEnumerator CoOpenAvatarPicker()
|
|
{
|
|
openingAvatarPicker = true;
|
|
int version = ++avatarPickerVersion;
|
|
UObject loaded = null;
|
|
yield return XResLoader.coLoadRes(AvatarPickerPrefabPath, typeof(GameObject), obj => loaded = obj);
|
|
openingAvatarPicker = false;
|
|
|
|
if (version != avatarPickerVersion || detailView == null)
|
|
{
|
|
yield break;
|
|
}
|
|
|
|
GameObject prefab = loaded as GameObject;
|
|
if (prefab == null)
|
|
{
|
|
Debug.LogError("[PlayerProfileModule] load avatar picker prefab failed: " + AvatarPickerPrefabPath);
|
|
yield break;
|
|
}
|
|
|
|
avatarPickerView = Instantiate(prefab);
|
|
UIManager.AttachTo(UILayer.Dialog, avatarPickerView);
|
|
pendingAvatarId = PlayerAvatarCatalog.NormalizeId(PlayerProfileStore.Current.AvatarId);
|
|
BindAvatarPickerEvents();
|
|
CacheAvatarPickerControls();
|
|
RefreshAvatarPicker();
|
|
}
|
|
|
|
private void BindAvatarPickerEvents()
|
|
{
|
|
BindAvatarPickerButton("Img_Mask", CancelAvatarPicker);
|
|
BindAvatarPickerButton("Btn_Close", CancelAvatarPicker);
|
|
BindAvatarPickerButton("Btn_Cancel", CancelAvatarPicker);
|
|
BindAvatarPickerButton("Btn_Confirm", ConfirmAvatarPicker);
|
|
|
|
for (int avatarId = 1; avatarId <= PlayerAvatarCatalog.Count; avatarId++)
|
|
{
|
|
int selectedId = avatarId;
|
|
Button button = FindComponent<Button>(avatarPickerView, AvatarButtonName(selectedId));
|
|
if (button == null)
|
|
{
|
|
continue;
|
|
}
|
|
button.onClick.RemoveAllListeners();
|
|
button.onClick.AddListener(() => SelectPendingAvatar(selectedId));
|
|
}
|
|
}
|
|
|
|
private void BindAvatarPickerButton(string nodeName, UnityEngine.Events.UnityAction action)
|
|
{
|
|
Button button = FindComponent<Button>(avatarPickerView, nodeName);
|
|
if (button == null)
|
|
{
|
|
return;
|
|
}
|
|
button.onClick.RemoveAllListeners();
|
|
button.onClick.AddListener(action);
|
|
}
|
|
|
|
private void CacheAvatarPickerControls()
|
|
{
|
|
avatarPickerPreviewImage = FindComponent<Image>(avatarPickerView, "Img_PreviewAvatar");
|
|
ArrangeGraphicBehindFrame(avatarPickerView, "Img_PreviewFrame", "Img_PreviewAvatar");
|
|
ClampGraphicToFrameFill(avatarPickerView, "Img_PreviewFrame", "Img_PreviewAvatar", PreviewAvatarFrameFill);
|
|
avatarPickerHintText = FindComponent<TMP_Text>(avatarPickerView, "Txt_PreviewHint");
|
|
avatarPickerAvatarImages.Clear();
|
|
avatarPickerSelectedStates.Clear();
|
|
|
|
for (int avatarId = 1; avatarId <= PlayerAvatarCatalog.Count; avatarId++)
|
|
{
|
|
Image avatarImage = FindComponent<Image>(avatarPickerView, AvatarImageName(avatarId));
|
|
avatarPickerAvatarImages[avatarId] = avatarImage;
|
|
if (avatarImage != null && avatarImage.sprite != null)
|
|
{
|
|
avatarSpriteCache[avatarId] = avatarImage.sprite;
|
|
}
|
|
|
|
Transform selected = FindTransform(avatarPickerView, AvatarSelectedName(avatarId));
|
|
if (selected != null)
|
|
{
|
|
MoveSelectedStateAboveAvatarFrame(selected);
|
|
avatarPickerSelectedStates[avatarId] = selected.gameObject;
|
|
}
|
|
}
|
|
}
|
|
|
|
private void CacheAvatarSpritesFromRoot(GameObject root)
|
|
{
|
|
if (root == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
for (int avatarId = 1; avatarId <= PlayerAvatarCatalog.Count; avatarId++)
|
|
{
|
|
Image avatarImage = FindComponent<Image>(root, AvatarImageName(avatarId));
|
|
if (avatarImage != null && avatarImage.sprite != null)
|
|
{
|
|
avatarSpriteCache[avatarId] = avatarImage.sprite;
|
|
}
|
|
}
|
|
}
|
|
|
|
private void MoveSelectedStateAboveAvatarFrame(Transform selected)
|
|
{
|
|
if (selected == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
selected.SetAsLastSibling();
|
|
}
|
|
|
|
private void ClampGraphicToFrameFill(GameObject root, string frameName, string graphicName, float fill)
|
|
{
|
|
Transform frame = FindTransform(root, frameName);
|
|
Transform graphic = FindTransform(root, graphicName);
|
|
RectTransform frameRect = frame as RectTransform;
|
|
RectTransform graphicRect = graphic as RectTransform;
|
|
if (frameRect == null || graphicRect == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
float frameWidth = Mathf.Abs(frameRect.rect.width) > 0f ? Mathf.Abs(frameRect.rect.width) : Mathf.Abs(frameRect.sizeDelta.x);
|
|
float frameHeight = Mathf.Abs(frameRect.rect.height) > 0f ? Mathf.Abs(frameRect.rect.height) : Mathf.Abs(frameRect.sizeDelta.y);
|
|
float maxSide = Mathf.Min(frameWidth, frameHeight) * Mathf.Clamp01(fill);
|
|
if (maxSide <= 0f)
|
|
{
|
|
return;
|
|
}
|
|
|
|
float currentWidth = Mathf.Abs(graphicRect.sizeDelta.x);
|
|
float currentHeight = Mathf.Abs(graphicRect.sizeDelta.y);
|
|
float currentSide = Mathf.Max(currentWidth, currentHeight);
|
|
float side = currentSide > 0f ? Mathf.Min(currentSide, maxSide) : maxSide;
|
|
graphicRect.sizeDelta = new Vector2(side, side);
|
|
}
|
|
|
|
private void SelectPendingAvatar(int avatarId)
|
|
{
|
|
pendingAvatarId = PlayerAvatarCatalog.NormalizeId(avatarId);
|
|
RefreshAvatarPicker();
|
|
}
|
|
|
|
private void ConfirmAvatarPicker()
|
|
{
|
|
int selectedId = PlayerAvatarCatalog.NormalizeId(pendingAvatarId);
|
|
if (avatarPickerAvatarImages.TryGetValue(selectedId, out Image selectedImage) &&
|
|
selectedImage != null &&
|
|
selectedImage.sprite != null)
|
|
{
|
|
avatarSpriteCache[selectedId] = selectedImage.sprite;
|
|
}
|
|
PlayerProfileStore.Update(profile => profile.AvatarId = selectedId);
|
|
CloseAvatarPicker();
|
|
}
|
|
|
|
private void CancelAvatarPicker()
|
|
{
|
|
CloseAvatarPicker();
|
|
}
|
|
|
|
private void CloseAvatarPicker()
|
|
{
|
|
avatarPickerVersion++;
|
|
openingAvatarPicker = false;
|
|
if (avatarPickerView != null)
|
|
{
|
|
Destroy(avatarPickerView);
|
|
}
|
|
avatarPickerView = null;
|
|
avatarPickerPreviewImage = null;
|
|
avatarPickerHintText = null;
|
|
avatarPickerAvatarImages.Clear();
|
|
avatarPickerSelectedStates.Clear();
|
|
}
|
|
|
|
private void RefreshAvatarPicker()
|
|
{
|
|
if (avatarPickerView == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
int selectedId = PlayerAvatarCatalog.NormalizeId(pendingAvatarId);
|
|
pendingAvatarId = selectedId;
|
|
for (int avatarId = 1; avatarId <= PlayerAvatarCatalog.Count; avatarId++)
|
|
{
|
|
if (avatarPickerSelectedStates.TryGetValue(avatarId, out GameObject selectedState) && selectedState != null)
|
|
{
|
|
selectedState.SetActive(avatarId == selectedId);
|
|
}
|
|
}
|
|
|
|
if (avatarPickerAvatarImages.TryGetValue(selectedId, out Image selectedImage) && selectedImage != null && avatarPickerPreviewImage != null)
|
|
{
|
|
avatarPickerPreviewImage.sprite = selectedImage.sprite;
|
|
}
|
|
if (avatarPickerHintText != null)
|
|
{
|
|
avatarPickerHintText.text = "已选择头像 " + selectedId.ToString("00", CultureInfo.InvariantCulture);
|
|
}
|
|
}
|
|
|
|
private static string AvatarButtonName(int avatarId)
|
|
{
|
|
return "Btn_Avatar_" + avatarId.ToString("00", CultureInfo.InvariantCulture);
|
|
}
|
|
|
|
private static string AvatarImageName(int avatarId)
|
|
{
|
|
return "Img_Avatar_" + avatarId.ToString("00", CultureInfo.InvariantCulture);
|
|
}
|
|
|
|
private static string AvatarSelectedName(int avatarId)
|
|
{
|
|
return "Img_Selected_" + avatarId.ToString("00", CultureInfo.InvariantCulture);
|
|
}
|
|
|
|
private void SetText(string nodeName, string value)
|
|
{
|
|
TMP_Text text = FindComponent<TMP_Text>(detailView, nodeName);
|
|
if (text != null)
|
|
{
|
|
text.text = value ?? string.Empty;
|
|
}
|
|
}
|
|
|
|
private static RectTransform FindRect(GameObject root, string nodeName)
|
|
{
|
|
Transform t = root == null ? null : root.transform.FindTransform(nodeName);
|
|
return t == null ? null : t.GetComponent<RectTransform>();
|
|
}
|
|
|
|
private static T FindComponent<T>(GameObject root, string nodeName) where T : Component
|
|
{
|
|
Transform t = root == null ? null : root.transform.FindTransform(nodeName);
|
|
return t == null ? null : t.GetComponent<T>();
|
|
}
|
|
|
|
private static Transform FindTransform(GameObject root, string nodeName)
|
|
{
|
|
return root == null ? null : root.transform.FindTransform(nodeName);
|
|
}
|
|
}
|
|
}
|