备份CatanBuilding瘦身独立工程
This commit is contained in:
80
Assets/Scripts/UIExtend/UIDrag.cs
Normal file
80
Assets/Scripts/UIExtend/UIDrag.cs
Normal file
@@ -0,0 +1,80 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
public class UIDrag : MonoBehaviour, IBeginDragHandler, IDragHandler, IEndDragHandler, IPointerDownHandler, IPointerUpHandler
|
||||
{
|
||||
//按下回调
|
||||
public System.Action OnPointerDownCall;
|
||||
public System.Action OnPointerUpCall;
|
||||
//开始拖动回调
|
||||
public System.Action OnBeginDragCall;
|
||||
|
||||
//拖动中回调
|
||||
public System.Action<PointerEventData> OnDragCall;
|
||||
|
||||
//拖动结束回调
|
||||
public System.Action OnEndDragCall;
|
||||
bool isdrag = false;
|
||||
public bool isTouchTwo = false;
|
||||
|
||||
public void OnPointerDown(PointerEventData eventData)
|
||||
{
|
||||
OnPointerDownCall?.Invoke();
|
||||
}
|
||||
|
||||
public void OnPointerUp(PointerEventData eventData)
|
||||
{
|
||||
OnPointerUpCall?.Invoke();
|
||||
}
|
||||
|
||||
public void OnBeginDrag(PointerEventData eventData)
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
if (Input.GetMouseButton(0))
|
||||
#else
|
||||
if (Input.touchCount == 1 || Input.touchCount == 2)
|
||||
#endif
|
||||
{
|
||||
OnBeginDragCall?.Invoke();
|
||||
isdrag = true;
|
||||
}
|
||||
}
|
||||
|
||||
public void OnDrag(PointerEventData eventData)
|
||||
{
|
||||
OnDragCall?.Invoke(eventData);
|
||||
if (isTouchTwo)
|
||||
{
|
||||
#if !UNITY_EDITOR
|
||||
//if (Input.touchCount == 1)
|
||||
//{
|
||||
// if (!isdrag)
|
||||
// {
|
||||
// OnBeginDragCall?.Invoke();
|
||||
// isdrag = true;
|
||||
// }
|
||||
//}
|
||||
//else
|
||||
if (Input.touchCount == 2)
|
||||
{
|
||||
//双指操作
|
||||
if (isdrag)
|
||||
{
|
||||
OnEndDragCall?.Invoke();
|
||||
isdrag = false;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
public void OnEndDrag(PointerEventData eventData)
|
||||
{
|
||||
if (isdrag)
|
||||
{
|
||||
OnEndDragCall?.Invoke();
|
||||
isdrag = false;
|
||||
}
|
||||
}
|
||||
//双指操作
|
||||
}
|
||||
Reference in New Issue
Block a user