90 lines
2.4 KiB
C#
90 lines
2.4 KiB
C#
using System.Net;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.EventSystems;
|
|
using UnityEngine.UI;
|
|
using System;
|
|
|
|
namespace BF
|
|
{
|
|
public enum EliminationTouchEventType
|
|
{
|
|
Unknown = 0,
|
|
Enter,
|
|
Down,
|
|
Up,
|
|
Cancel,
|
|
Exit
|
|
}
|
|
|
|
[RequireComponent(typeof(Graphic))]
|
|
public class EliminationTouchEvent : MonoBehaviour, IPointerDownHandler, IPointerUpHandler, IPointerEnterHandler, IPointerExitHandler, ICancelHandler
|
|
{
|
|
protected Action<int, float, float> luaFunc;
|
|
#if UNITY_EDITOR
|
|
private EliminationTouchEventType touchEvent = EliminationTouchEventType.Unknown;
|
|
#endif
|
|
|
|
public void AddTouchEventListener(Action<int, float, float> func)
|
|
{
|
|
luaFunc = func;
|
|
}
|
|
|
|
public void RemoveEventListener()
|
|
{
|
|
luaFunc = null;
|
|
}
|
|
|
|
public void OnCancel(BaseEventData eventData)
|
|
{
|
|
if (luaFunc != null)
|
|
{
|
|
luaFunc((int)EliminationTouchEventType.Cancel, 0, 0);
|
|
}
|
|
}
|
|
|
|
public void OnPointerDown(PointerEventData eventData)
|
|
{
|
|
if (luaFunc != null)
|
|
{
|
|
luaFunc((int)EliminationTouchEventType.Down, eventData.position.x, eventData.position.y);
|
|
}
|
|
}
|
|
|
|
public void OnPointerEnter(PointerEventData eventData)
|
|
{
|
|
// if (!ReferenceEquals(eventData.pointerPress, eventData.pointerEnter))
|
|
// {
|
|
// return;
|
|
// }
|
|
// #if UNITY_EDITOR
|
|
// if (touchEvent != EliminationTouchEventType.Down)
|
|
// {
|
|
// return;
|
|
// }
|
|
// #endif
|
|
if (luaFunc != null)
|
|
{
|
|
luaFunc((int)EliminationTouchEventType.Enter, eventData.position.x, eventData.position.y);
|
|
}
|
|
}
|
|
|
|
public void OnPointerExit(PointerEventData eventData)
|
|
{
|
|
if (luaFunc != null)
|
|
{
|
|
luaFunc((int)EliminationTouchEventType.Exit, eventData.position.x, eventData.position.y);
|
|
}
|
|
}
|
|
|
|
public void OnPointerUp(PointerEventData eventData)
|
|
{
|
|
if (luaFunc != null)
|
|
{
|
|
luaFunc((int)EliminationTouchEventType.Up, eventData.position.x, eventData.position.y);
|
|
}
|
|
}
|
|
}
|
|
}
|