43 lines
1.1 KiB
C#
43 lines
1.1 KiB
C#
using CSNetwork.Protocols.RPCData;
|
|
using System;
|
|
using System.Data;
|
|
using System.Text;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class CharacterItemUI : MonoBehaviour
|
|
{
|
|
[SerializeField] private Button btnClick;
|
|
[SerializeField] private TextMeshProUGUI nameCharacter;
|
|
RoleInfo dataItem;
|
|
Action<RoleInfo> onClick;
|
|
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
|
void Start()
|
|
{
|
|
btnClick.onClick.AddListener(OnClickBtn);
|
|
}
|
|
|
|
public void InitItem(RoleInfo role, Action<RoleInfo> action)
|
|
{
|
|
dataItem = role;
|
|
onClick = action;
|
|
string roleName = "(Error decoding name)";
|
|
if (role.name != null && role.name.ByteArray != null)
|
|
{
|
|
// Be careful with encoding, assume UTF8 is correct
|
|
roleName = Encoding.UTF8.GetString(
|
|
role.name.ByteArray,
|
|
0,
|
|
role.name.Length
|
|
);
|
|
}
|
|
nameCharacter.text = roleName;
|
|
}
|
|
|
|
public void OnClickBtn()
|
|
{
|
|
onClick?.Invoke(dataItem);
|
|
}
|
|
}
|