81 lines
1.6 KiB
C#
81 lines
1.6 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using Turing.Samples;
|
|
using Turing.Core.EventSystems;
|
|
using UnityEngine.EventSystems;
|
|
using QFramework;
|
|
using UnityEngine.Events;
|
|
using DG.Tweening;
|
|
public class TuringDraggableEx : Draggable, IObjDrag
|
|
{
|
|
bool isOn = false;
|
|
UnityEvent<GameObject> OnDragEnd;
|
|
bool IObjDrag.isOn { get => isOn; set => isOn = value; }
|
|
|
|
Vector3 beginPos;
|
|
UnityEvent<GameObject> IObjDrag.OnDragEnd
|
|
{
|
|
get
|
|
{
|
|
if (OnDragEnd == null)
|
|
{
|
|
OnDragEnd = new UnityEvent<GameObject>();
|
|
}
|
|
return OnDragEnd;
|
|
}
|
|
}
|
|
|
|
|
|
Vector3 startPosition;
|
|
private void Start()
|
|
{
|
|
startPosition = gameObject.transform.position;
|
|
}
|
|
public override void OnBeginDrag(PointerEventData eventData)
|
|
{
|
|
beginPos = gameObject.Position();
|
|
if (isOn == false)
|
|
{
|
|
gameObject.transform.position = beginPos;
|
|
}
|
|
else
|
|
{
|
|
base.OnBeginDrag(eventData);
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public override void OnDrag(PointerEventData eventData)
|
|
{
|
|
if (isOn)
|
|
{
|
|
base.OnDrag(eventData);
|
|
}
|
|
else
|
|
{
|
|
gameObject.transform.position = beginPos;
|
|
}
|
|
}
|
|
|
|
public override void OnEndDrag(PointerEventData eventData)
|
|
{
|
|
if (isOn)
|
|
{
|
|
base.OnEndDrag(eventData);
|
|
OnDragEnd?.Invoke(gameObject);
|
|
}
|
|
}
|
|
|
|
|
|
public void OnDoubleClick()
|
|
{
|
|
transform.DOMove(startPosition, 0.1f);
|
|
}
|
|
|
|
|
|
|
|
}
|