107 lines
2.7 KiB
C#
107 lines
2.7 KiB
C#
using System;
|
|
using UnityEngine;
|
|
using UnityEngine.EventSystems;
|
|
using UnityEngine.Events;
|
|
using UnityEngine.UI;
|
|
|
|
namespace UIWidgets
|
|
{
|
|
[RequireComponent(typeof(Image))]
|
|
public class ListViewItem : UIBehaviour, IPointerClickHandler, IPointerEnterHandler, IPointerExitHandler, ISubmitHandler, ICancelHandler, ISelectHandler, IDeselectHandler, IMoveHandler, IComparable<ListViewItem>, IEventSystemHandler
|
|
{
|
|
[HideInInspector]
|
|
public int Index = -1;
|
|
|
|
public UnityEvent onClick = new UnityEvent();
|
|
|
|
public ListViewItemSelect onSubmit = new ListViewItemSelect();
|
|
|
|
public ListViewItemSelect onCancel = new ListViewItemSelect();
|
|
|
|
public ListViewItemSelect onSelect = new ListViewItemSelect();
|
|
|
|
public ListViewItemSelect onDeselect = new ListViewItemSelect();
|
|
|
|
public ListViewItemMove onMove = new ListViewItemMove();
|
|
|
|
public PointerUnityEvent onPointerClick = new PointerUnityEvent();
|
|
|
|
public PointerUnityEvent onPointerEnter = new PointerUnityEvent();
|
|
|
|
public PointerUnityEvent onPointerExit = new PointerUnityEvent();
|
|
|
|
[NonSerialized]
|
|
public ImageAdvanced Background;
|
|
|
|
protected override void Awake()
|
|
{
|
|
Background = GetComponent<ImageAdvanced>();
|
|
}
|
|
|
|
public virtual void OnMove(AxisEventData eventData)
|
|
{
|
|
onMove.Invoke(eventData, this);
|
|
}
|
|
|
|
public virtual void OnSubmit(BaseEventData eventData)
|
|
{
|
|
onSubmit.Invoke(this);
|
|
}
|
|
|
|
public virtual void OnCancel(BaseEventData eventData)
|
|
{
|
|
onCancel.Invoke(this);
|
|
}
|
|
|
|
public virtual void OnSelect(BaseEventData eventData)
|
|
{
|
|
Select();
|
|
onSelect.Invoke(this);
|
|
}
|
|
|
|
public virtual void OnDeselect(BaseEventData eventData)
|
|
{
|
|
onDeselect.Invoke(this);
|
|
}
|
|
|
|
public virtual void OnPointerClick(PointerEventData eventData)
|
|
{
|
|
AudioController.Play("btn_pressed");
|
|
onPointerClick.Invoke(eventData);
|
|
onClick.Invoke();
|
|
Select();
|
|
}
|
|
|
|
public virtual void OnPointerEnter(PointerEventData eventData)
|
|
{
|
|
AudioController.Play("btn_hover");
|
|
onPointerEnter.Invoke(eventData);
|
|
}
|
|
|
|
public virtual void OnPointerExit(PointerEventData eventData)
|
|
{
|
|
onPointerExit.Invoke(eventData);
|
|
}
|
|
|
|
public virtual void Select()
|
|
{
|
|
if (!EventSystem.current.alreadySelecting)
|
|
{
|
|
ListViewItemEventData listViewItemEventData = new ListViewItemEventData(EventSystem.current);
|
|
listViewItemEventData.NewSelectedObject = base.gameObject;
|
|
ListViewItemEventData listViewItemEventData2 = listViewItemEventData;
|
|
EventSystem.current.SetSelectedGameObject(listViewItemEventData2.NewSelectedObject, listViewItemEventData2);
|
|
}
|
|
}
|
|
|
|
public int CompareTo(ListViewItem compareItem)
|
|
{
|
|
return (compareItem == null) ? 1 : Index.CompareTo(compareItem.Index);
|
|
}
|
|
|
|
public virtual void MovedToCache()
|
|
{
|
|
}
|
|
}
|
|
}
|