133 lines
2.7 KiB
C#
133 lines
2.7 KiB
C#
using System;
|
||
using UnityEngine;
|
||
using UnityEngine.UI;
|
||
|
||
public class UIVehicleHeadNode: UINode
|
||
{
|
||
public Image imgBg;
|
||
public Image imgHead;
|
||
public Image imgPro;
|
||
public Button button;
|
||
public ButtonUpDrag buttonUpDrag;
|
||
|
||
private UIVehicleHeadInfo _data;
|
||
private VehicleCultivateData _vehicleInfo;
|
||
|
||
#region FrameWork
|
||
|
||
private void _GetComponents()
|
||
{
|
||
imgBg = _GetComponent<Image>("ImageBg");
|
||
imgHead = _GetComponent<Image>("ImageHeadPic");
|
||
imgPro = _GetComponent<Image>("ImageProfession");
|
||
button = _GetComponent<Button>("Button");
|
||
buttonUpDrag = button.GetComponent<ButtonUpDrag>();
|
||
}
|
||
|
||
private void _Refresh(bool isAsync = true)
|
||
{
|
||
if (isAsync)
|
||
{
|
||
_RefreshAsync();
|
||
}
|
||
}
|
||
|
||
private void _RefreshAsync()
|
||
{
|
||
_RefreshHeadAsync();
|
||
_RefreshProAsync();
|
||
_AddButton();
|
||
}
|
||
|
||
private async void _RefreshHeadAsync()
|
||
{
|
||
var sprite = await LoadAssetAsync<Sprite>(VehicleDataHelper.GetVehiclePicPath((int)_data.Uid));
|
||
imgHead.sprite = sprite;
|
||
}
|
||
|
||
private async void _RefreshProAsync()
|
||
{
|
||
//_AddButton();
|
||
}
|
||
|
||
private void _AddButton()
|
||
{
|
||
ClearBind(button);
|
||
var clickFunc = _data.ClickFunc;
|
||
if (clickFunc != null)
|
||
{
|
||
if (clickFunc is Action act)
|
||
{
|
||
BindButton(button, act);
|
||
}
|
||
}
|
||
}
|
||
|
||
private void _AddButton<T>(T param)
|
||
{
|
||
ClearBind(button);
|
||
var clickFunc = _data.ClickFunc;
|
||
if (clickFunc != null)
|
||
{
|
||
if (clickFunc is Action<T> actT)
|
||
{
|
||
BindButton(button, actT, param);
|
||
}
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
|
||
#region Unity EventFunction
|
||
|
||
private void Update()
|
||
{
|
||
|
||
}
|
||
|
||
private void OnDestroy()
|
||
{
|
||
OnRelease();
|
||
}
|
||
|
||
#endregion
|
||
|
||
#region API
|
||
|
||
public void SetData(UIVehicleHeadInfo data)
|
||
{
|
||
_data = data;
|
||
if (!VehicleCultivateDataManager.Instance.DataDic.ContainsKey(_data.Uid))
|
||
{
|
||
DebugUtil.LogError("加载头像时出现错误,未拥有该载具,载具ID:" + _data.Uid);
|
||
return;
|
||
}
|
||
_vehicleInfo = VehicleCultivateDataManager.Instance.DataDic[_data.Uid];
|
||
}
|
||
|
||
public void SetClickFuncParam<T>(T param)
|
||
{
|
||
_AddButton(param);
|
||
}
|
||
|
||
public void Refresh()
|
||
{
|
||
_Refresh();
|
||
}
|
||
#endregion
|
||
}
|
||
|
||
public class UIVehicleHeadInfo
|
||
{
|
||
private uint _uid;
|
||
|
||
public uint Uid => _uid;
|
||
public bool IsShowBg = false;
|
||
public bool IsShowPro;
|
||
public Delegate ClickFunc;
|
||
|
||
public UIVehicleHeadInfo(uint uid)
|
||
{
|
||
_uid = uid;
|
||
}
|
||
} |