114 lines
3.2 KiB
C#
114 lines
3.2 KiB
C#
|
|
using System.Collections;
|
|||
|
|
using System.Collections.Generic;
|
|||
|
|
using UnityEngine;
|
|||
|
|
using UnityEngine.Events;
|
|||
|
|
using UnityEngine.EventSystems;
|
|||
|
|
/*******************************************************************************
|
|||
|
|
*Create By CG
|
|||
|
|
*Function image˫<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ
|
|||
|
|
*******************************************************************************/
|
|||
|
|
namespace CG.UTility
|
|||
|
|
{
|
|||
|
|
public class ButtonExtension : MonoBehaviour,IPointerEnterHandler, IPointerClickHandler, IPointerDownHandler, IPointerUpHandler, IPointerExitHandler
|
|||
|
|
{
|
|||
|
|
public float pressDurationTime = 1;
|
|||
|
|
public bool responseOnceByPress = false;
|
|||
|
|
public float doubleClickIntervalTime = 0.25f;
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// ˫<><CBAB>
|
|||
|
|
/// </summary>
|
|||
|
|
public UnityEvent onDoubleClick = new UnityEvent();
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20><><EFBFBD><EFBFBD>
|
|||
|
|
/// </summary>
|
|||
|
|
public UnityEvent onPress = new UnityEvent();
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20><><EFBFBD><EFBFBD>
|
|||
|
|
/// </summary>
|
|||
|
|
public UnityEvent onClick = new UnityEvent();
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20><><EFBFBD><EFBFBD>
|
|||
|
|
/// </summary>
|
|||
|
|
public UnityEvent onCover = new UnityEvent();
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20>뿪
|
|||
|
|
/// </summary>
|
|||
|
|
public UnityEvent onExit = new UnityEvent();
|
|||
|
|
|
|||
|
|
private bool isDown = false;
|
|||
|
|
private bool isPress = false;
|
|||
|
|
private float downTime = 0;
|
|||
|
|
|
|||
|
|
private float clickIntervalTime = 0;
|
|||
|
|
private int clickTimes = 0;
|
|||
|
|
|
|||
|
|
void Update()
|
|||
|
|
{
|
|||
|
|
if (isDown)
|
|||
|
|
{
|
|||
|
|
if (responseOnceByPress && isPress)
|
|||
|
|
{
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
downTime += Time.deltaTime;
|
|||
|
|
if (downTime > pressDurationTime)
|
|||
|
|
{
|
|||
|
|
isPress = true;
|
|||
|
|
onPress.Invoke();
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
if (clickTimes >= 1)
|
|||
|
|
{
|
|||
|
|
clickIntervalTime += Time.deltaTime;
|
|||
|
|
if (clickIntervalTime >= doubleClickIntervalTime)
|
|||
|
|
{
|
|||
|
|
if (clickTimes >= 2)
|
|||
|
|
{
|
|||
|
|
onDoubleClick.Invoke();
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
onClick.Invoke();
|
|||
|
|
}
|
|||
|
|
clickTimes = 0;
|
|||
|
|
clickIntervalTime = 0;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
void IPointerEnterHandler.OnPointerEnter(PointerEventData eventData)
|
|||
|
|
{
|
|||
|
|
onCover?.Invoke();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void IPointerDownHandler.OnPointerDown(PointerEventData eventData)//<2F><><EFBFBD>갴<EFBFBD><EAB0B4>
|
|||
|
|
{
|
|||
|
|
isDown = true;
|
|||
|
|
downTime = 0;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void IPointerUpHandler.OnPointerUp(PointerEventData eventData)//<2F><><EFBFBD><EFBFBD>̧<EFBFBD><CCA7>
|
|||
|
|
{
|
|||
|
|
isDown = false;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void IPointerExitHandler.OnPointerExit(PointerEventData eventData)//ָ<><D6B8><EFBFBD><EFBFBD>ȥ
|
|||
|
|
{
|
|||
|
|
isDown = false;
|
|||
|
|
isPress = false;
|
|||
|
|
onExit?.Invoke();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void IPointerClickHandler.OnPointerClick(PointerEventData eventData)//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>
|
|||
|
|
{
|
|||
|
|
if (!isPress)
|
|||
|
|
{
|
|||
|
|
//onClick.Invoke();
|
|||
|
|
clickTimes += 1;
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
isPress = false;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
}
|