72 lines
1.8 KiB
C#
72 lines
1.8 KiB
C#
using Cysharp.Threading.Tasks;
|
|
using SepCore.Event;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
namespace SepCore.UI
|
|
{
|
|
public class DisplayItem : MonoBehaviour
|
|
{
|
|
[SerializeField] private IconArea _iconArea;
|
|
|
|
[SerializeField] private RectTransform _itemRect;
|
|
|
|
private DisplayItemContext _context;
|
|
|
|
private int _index = -1;
|
|
|
|
public void SetIndex(int index)
|
|
{
|
|
_index = index;
|
|
}
|
|
|
|
public async UniTaskVoid OnInit(DisplayItemContext context, int index)
|
|
{
|
|
if (context == null) return;
|
|
|
|
_context = context;
|
|
_index = index;
|
|
|
|
if (_iconArea != null)
|
|
{
|
|
var sprite = await GameEntry.SpriteCache.GetSprite(_context.IconAssetName);
|
|
_iconArea.OnInit(sprite, context.Rarity);
|
|
}
|
|
}
|
|
|
|
public void OnReset()
|
|
{
|
|
_context = null;
|
|
_index = -1;
|
|
|
|
if (_iconArea != null)
|
|
{
|
|
_iconArea.OnReset();
|
|
}
|
|
}
|
|
|
|
public void OnItemInfoShow()
|
|
{
|
|
if (_index < 0) return;
|
|
if (_itemRect == null) return;
|
|
|
|
Rect rect = _itemRect.rect;
|
|
Vector3 targetPos = _itemRect.TransformPoint(new Vector3(
|
|
(rect.xMin + rect.xMax) / 2,
|
|
rect.yMax,
|
|
0f)
|
|
);
|
|
GameEntry.Event.Fire(this, DisplayItemHoverEventArgs.Create(_index, _context.IsWeapon, targetPos));
|
|
}
|
|
|
|
public void OnItemInfoLock()
|
|
{
|
|
GameEntry.Event.Fire(this, DisplayItemLockEventArgs.Create());
|
|
}
|
|
|
|
public void OnItemInfoHide()
|
|
{
|
|
GameEntry.Event.Fire(this, DisplayItemHideEventArgs.Create());
|
|
}
|
|
}
|
|
} |