只使用一个左键点击的方案
类:LearnButton
<
using UnityEngine;
using UnityEngine.UI;
using System;
using UnityEngine.EventSystems;
public class LearnButton : MonoBehaviour,IPointerClickHandler,IPointerExitHandler,IPointerUpHandler,IPointerDownHandler,IPointerEnterHandler{
/// <summary>
/// 划过选中
/// </summary>
public event Action HighlightedBtn;
/// <summary>
/// 点击选中
/// </summary>
public event Action<PointerEventData> PressedBtn;
public void OnPointerClick(PointerEventData eventData)
{
if (PressedBtn != null)
PressedBtn(eventData);
}
public void OnPointerEnter(PointerEventData eventData)
{
}
public void OnPointerExit(PointerEventData eventData)
{
if (HighlightedBtn != null)
HighlightedBtn();
}
public void OnPointerDown(PointerEventData eventData)
{
}
public void OnPointerUp(PointerEventData eventData)
{
}
}
>
类:CardUI
<
private void Btn_HighlightedBtn()
{
if (Input.GetMouseButton(0))
{
if (card.BelongTo == CharacterType.Player)
IsSelected = !IsSelected;
}
}
private void Btn_PressedBtn(PointerEventData eventData)
{
if (card.BelongTo == CharacterType.Player && eventData.button == PointerEventData.InputButton.Left)
IsSelected = !IsSelected;
}
>