122 lines
3.1 KiB
C#
122 lines
3.1 KiB
C#
|
using Axibug;
|
|||
|
using Game;
|
|||
|
using System.Collections;
|
|||
|
using System.Collections.Generic;
|
|||
|
using UnityEngine;
|
|||
|
using UnityEngine.EventSystems;
|
|||
|
using UnityEngine.UI;
|
|||
|
|
|||
|
public enum BtnInputNumChangeType
|
|||
|
{
|
|||
|
AddBtn,
|
|||
|
ReduceBtn,
|
|||
|
}
|
|||
|
|
|||
|
public class UILongClickButton : Button
|
|||
|
{
|
|||
|
public BtnInputNumChangeType mBtnType = BtnInputNumChangeType.AddBtn;
|
|||
|
|
|||
|
public bool IsLongClick = false;//<2F>Ƿ<C7B7>
|
|||
|
private bool IsDown = false;
|
|||
|
private float Delay = 1f;//<2F>ӳ<EFBFBD><D3B3>൱<EFBFBD>ڰ<EFBFBD><DAB0>³<EFBFBD><C2B3><EFBFBD>ʱ<EFBFBD><CAB1>
|
|||
|
private float LastDownTime;
|
|||
|
|
|||
|
|
|||
|
//<2F>¼<EFBFBD><C2BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>,<2C><><EFBFBD>ѷ<EFBFBD><D1B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӻ<EFBFBD><D3BB><EFBFBD><DFBC><EFBFBD><EFBFBD>¼<EFBFBD>,<2C><>ֹͣ<CDA3><D6B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD>ͬ<EFBFBD>¼<EFBFBD>
|
|||
|
private bool IsSendEvent = false;
|
|||
|
|
|||
|
public System.Action NumberChange;
|
|||
|
public System.Action NumberChangeCancel;
|
|||
|
|
|||
|
public System.Action ButtonDownAction;
|
|||
|
|
|||
|
private void Update()
|
|||
|
{
|
|||
|
//<2F>ж<EFBFBD><D0B6>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD>ڳ<EFBFBD><DAB3><EFBFBD>
|
|||
|
if (IsDown)
|
|||
|
{
|
|||
|
if (Time.time - LastDownTime >= Delay)
|
|||
|
{
|
|||
|
//AxibugLog.Debug("<22><><EFBFBD><EFBFBD>");
|
|||
|
IsLongClick = true;
|
|||
|
LastDownTime = Time.time;
|
|||
|
}
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
IsLongClick = false;
|
|||
|
}
|
|||
|
|
|||
|
if(!IsSendEvent && IsLongClick)
|
|||
|
{
|
|||
|
|
|||
|
NumberChange?.Invoke();
|
|||
|
/*
|
|||
|
switch (mBtnType)
|
|||
|
{
|
|||
|
case BtnInputNumChangeType.AddBtn:
|
|||
|
//AppEntry.Event.Fire(this, NumChangeAddEvent.Create());
|
|||
|
break;
|
|||
|
case BtnInputNumChangeType.ReduceBtn:
|
|||
|
NumChangeReduceEvent?.Invoke();
|
|||
|
//AppEntry.Event.Fire(this, NumChangeReduceEvent.Create());
|
|||
|
break;
|
|||
|
default:
|
|||
|
break;
|
|||
|
}
|
|||
|
*/
|
|||
|
|
|||
|
IsSendEvent = true;
|
|||
|
}
|
|||
|
}
|
|||
|
/// <summary>
|
|||
|
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ťһ<C5A5><D2BB>
|
|||
|
/// </summary>
|
|||
|
/// <param name="eventData"></param>
|
|||
|
public override void OnPointerDown(PointerEventData eventData)
|
|||
|
{
|
|||
|
//AxibugLog.Debug("<22><>ť<EFBFBD><C5A5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
|
|||
|
base.OnPointerDown(eventData);
|
|||
|
IsDown = true;
|
|||
|
LastDownTime = Time.time;
|
|||
|
|
|||
|
ButtonDownAction?.Invoke();
|
|||
|
}
|
|||
|
/// <summary>
|
|||
|
/// <20><>ţ̌<C5A5><CCA7>
|
|||
|
/// </summary>
|
|||
|
/// <param name="eventData"></param>
|
|||
|
public override void OnPointerUp(PointerEventData eventData)
|
|||
|
{
|
|||
|
//AxibugLog.Debug("<22><>ţ̌<C5A5><CCA7>");
|
|||
|
base.OnPointerUp(eventData);
|
|||
|
IsDown = false;
|
|||
|
IsSendEvent = false;
|
|||
|
|
|||
|
NumberChangeCancel?.Invoke();
|
|||
|
/*
|
|||
|
switch (mBtnType)
|
|||
|
{
|
|||
|
case BtnInputNumChangeType.AddBtn:
|
|||
|
AppEntry.Event.Fire(this, NumChangeAddCancelEvent.Create());
|
|||
|
break;
|
|||
|
case BtnInputNumChangeType.ReduceBtn:
|
|||
|
AppEntry.Event.Fire(this, NumChangeReduceCancelEvent.Create());
|
|||
|
break;
|
|||
|
default:
|
|||
|
break;
|
|||
|
}*/
|
|||
|
}
|
|||
|
/// <summary>
|
|||
|
/// <20><><EFBFBD><EFBFBD><EFBFBD>뿪<EFBFBD><EBBFAA>ť<EFBFBD><C5A5><EFBFBD><EFBFBD>
|
|||
|
/// </summary>
|
|||
|
/// <param name="eventData"></param>
|
|||
|
public override void OnPointerExit(PointerEventData eventData)
|
|||
|
{
|
|||
|
//AxibugLog.Debug("<22><><EFBFBD><EFBFBD><EFBFBD>뿪<EFBFBD><EBBFAA>ť");
|
|||
|
base.OnPointerExit(eventData);
|
|||
|
IsDown = false;
|
|||
|
IsSendEvent = false;
|
|||
|
}
|
|||
|
}
|