// ***********************************************************************
// Assembly : Game
// Author : Kimch
// Created : 2021-11-23
// Description :
// Last Modified By :
// Last Modified On :
// ***********************************************************************
//
//
// ***********************************************************************
using UnityEngine;
using UnityEngine.UI;
namespace G.UI
{
///
///
///
public class AvatarItemWidget : KUIWidget
{
#region Field
#pragma warning disable CS0649 // 从未对字段赋值,字段将一直保持其默认值 null
[KUIFlag]
Image _imgSelected;
[KUIFlag]
Image _imgIcon;
[KUIFlag]
GameObject _goUsed;
#pragma warning restore CS0649 // 从未对字段赋值,字段将一直保持其默认值 null
public static AvatarItemWidget SelectedWidget;
public static AvatarItemWidget UsedWidget;
#endregion
#region Method
public override void Refresh()
{
if (this.data is ItemChaAvatar chaAvatar)
{
IconProxy.Instance.SetSprite(_imgIcon, chaAvatar.icon);
_goUsed.SetActive(this == UsedWidget);
var color = _imgSelected.color;
color.a = this == SelectedWidget ? 1f : 0f;
_imgSelected.color = color;//
}
}
public void OnSelected()
{
if (this == SelectedWidget)
return;
if (SelectedWidget != null)
SelectedWidget._imgSelected.CrossFadeAlpha(0f, 0.2f, true);
var color = _imgSelected.color;
color.a = 1f;
_imgSelected.color = color;//
//_imgSelected.CrossFadeColor(color, 0.2f, true, true);
_imgSelected.CrossFadeAlpha(1f, 0.2f, true);
SelectedWidget = this;
}
public void OnUsed()
{
if (this == UsedWidget)
return;
if (UsedWidget != null)
UsedWidget._goUsed.SetActive(false);
_goUsed.SetActive(true);
UsedWidget = this;
}
void OnClick()
{
OnSelected();
PostNotification(GlobalDefine.EVENT_PLAYER_AVATAR_SELECTED, this.data);
}
#endregion
#region Unity
///
///
///
private void Awake()
{
SetViewData();
_imgSelected.GetComponent