2025-07-08 10:46:31 +00:00
|
|
|
|
using UnityEngine;
|
|
|
|
|
using UnityEngine.EventSystems;
|
|
|
|
|
|
|
|
|
|
namespace Superlazy.UI
|
|
|
|
|
{
|
|
|
|
|
public class SLUIDrag : SLUIComponent, IBeginDragHandler, IDragHandler, IEndDragHandler
|
|
|
|
|
{
|
|
|
|
|
// 드래그 방향에 따라 상위 객체로 버블링
|
|
|
|
|
public enum DragDirection
|
|
|
|
|
{
|
|
|
|
|
All,
|
|
|
|
|
Horizontal,
|
|
|
|
|
Vertical,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string beginCommand;
|
|
|
|
|
public string endCommand;
|
|
|
|
|
public string dragCommand;
|
|
|
|
|
public DragDirection dragDirection;
|
|
|
|
|
public SLValueComparison comparison;
|
|
|
|
|
|
|
|
|
|
private IBeginDragHandler parentBeginDrag;
|
|
|
|
|
private IDragHandler parentDrag;
|
|
|
|
|
private IEndDragHandler parentEndDrag;
|
|
|
|
|
|
|
|
|
|
private bool draggable = true;
|
|
|
|
|
private bool toParent = false;
|
|
|
|
|
private bool dragging = false;
|
|
|
|
|
|
|
|
|
|
protected override void Validate()
|
|
|
|
|
{
|
|
|
|
|
if (dragDirection != DragDirection.All)
|
|
|
|
|
{
|
|
|
|
|
parentBeginDrag = transform.parent.GetComponentInParent<IBeginDragHandler>();
|
|
|
|
|
parentDrag = transform.parent.GetComponentInParent<IDragHandler>();
|
|
|
|
|
parentEndDrag = transform.parent.GetComponentInParent<IEndDragHandler>();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void Init()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void Enable()
|
|
|
|
|
{
|
|
|
|
|
if (comparison.useCheckValue) comparison.OnEnable(bindParent.BindPath, OnChange);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void Disable()
|
|
|
|
|
{
|
|
|
|
|
if (comparison.useCheckValue) comparison.OnDisable();
|
|
|
|
|
|
|
|
|
|
EndDrag(); // Dragged == false 체크 이미 되어있음
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnChange()
|
|
|
|
|
{
|
|
|
|
|
if (bindParent.Active == false) return;
|
|
|
|
|
|
|
|
|
|
var result = comparison.Result;//
|
|
|
|
|
|
|
|
|
|
if (draggable && comparison.useCheckValue && comparison.Result == false)
|
|
|
|
|
{
|
|
|
|
|
EndDrag();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
draggable = result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void BeginDrag()
|
|
|
|
|
{
|
|
|
|
|
if (comparison.useCheckValue && comparison.Result == false) return;
|
|
|
|
|
if (dragging == false) return;
|
|
|
|
|
if (beginCommand == string.Empty) return;
|
|
|
|
|
|
|
|
|
|
SLGame.Command(beginCommand, SLGame.SessionGet(bindParent.BindPath));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Drag()
|
|
|
|
|
{
|
|
|
|
|
if (comparison.useCheckValue && comparison.Result == false) return;
|
|
|
|
|
if (dragging == false) return;
|
|
|
|
|
if (dragCommand == string.Empty) return;
|
|
|
|
|
|
|
|
|
|
SLGame.Command(dragCommand, SLGame.SessionGet(bindParent.BindPath));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void EndDrag()
|
|
|
|
|
{
|
|
|
|
|
if (dragging == false) return;
|
|
|
|
|
dragging = false;
|
|
|
|
|
|
|
|
|
|
if (endCommand == string.Empty) return;
|
|
|
|
|
|
|
|
|
|
SLGame.Command(endCommand, SLGame.SessionGet(bindParent.BindPath));
|
|
|
|
|
|
|
|
|
|
SLGame.SessionGet(bindParent.BindPath)["Drag"] = false;
|
|
|
|
|
toParent = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void OnBeginDrag(PointerEventData eventData)
|
|
|
|
|
{
|
|
|
|
|
CheckDirection(eventData);
|
|
|
|
|
|
|
|
|
|
if (toParent || draggable == false)
|
|
|
|
|
{
|
|
|
|
|
parentBeginDrag?.OnBeginDrag(eventData);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
dragging = true;
|
|
|
|
|
//SLGame.SessionGet(sessionEntity.BindPath)["Drag"].MakeXYZToEntity(eventData.position);
|
|
|
|
|
BeginDrag();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void OnDrag(PointerEventData eventData)
|
|
|
|
|
{
|
|
|
|
|
if (toParent || draggable == false)
|
|
|
|
|
{
|
|
|
|
|
parentDrag?.OnDrag(eventData);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
//SLGame.SessionGet(sessionEntity.BindPath)["Drag"].MakeXYZToEntity(eventData.position);
|
|
|
|
|
Drag();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void OnEndDrag(PointerEventData eventData)
|
|
|
|
|
{
|
|
|
|
|
if (toParent || draggable == false)
|
|
|
|
|
{
|
|
|
|
|
parentEndDrag?.OnEndDrag(eventData);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
//SLGame.SessionGet(sessionEntity.BindPath)["Drag"].MakeXYZToEntity(eventData.position);
|
|
|
|
|
EndDrag();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void CheckDirection(PointerEventData eventData)
|
|
|
|
|
{
|
|
|
|
|
toParent = false;
|
|
|
|
|
if (dragDirection == DragDirection.Horizontal)
|
|
|
|
|
{
|
|
|
|
|
if (Mathf.Abs(eventData.delta.x) < Mathf.Abs(eventData.delta.y))
|
|
|
|
|
{
|
|
|
|
|
toParent = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (dragDirection == DragDirection.Vertical)
|
|
|
|
|
{
|
|
|
|
|
if (Mathf.Abs(eventData.delta.x) > Mathf.Abs(eventData.delta.y))
|
|
|
|
|
{
|
|
|
|
|
toParent = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|