62 lines
1.5 KiB
C#
62 lines
1.5 KiB
C#
using UnityEngine;
|
|
using UnityEngine.EventSystems;
|
|
using UnityEngine.UI;
|
|
|
|
public class RQNA_Dragger : MonoBehaviour, IBeginDragHandler, IDragHandler, IEndDragHandler
|
|
{
|
|
public RQNA_AnswerClass thisAnswer;
|
|
private Text thisTxt;
|
|
public bool isAnswered;
|
|
public Transform defaultParent;
|
|
public int index;
|
|
private Animator anim;
|
|
|
|
private void Awake()
|
|
{
|
|
isAnswered = false;
|
|
thisTxt = GetComponentInChildren<Text>();
|
|
anim = GetComponent<Animator>();
|
|
defaultParent = GameObject.Find("GameCanvas").transform;
|
|
}
|
|
|
|
public void Setup(RQNA_AnswerClass thisA, int ind)
|
|
{
|
|
thisAnswer = thisA;
|
|
thisTxt.text = thisAnswer.answerStr;
|
|
index = ind;
|
|
}
|
|
|
|
public void OnDrag(PointerEventData data)
|
|
{
|
|
Vector2 vz = Vector2.zero;
|
|
if (!isAnswered)
|
|
{
|
|
thisTxt.transform.position = Vector2.SmoothDamp(thisTxt.transform.position, data.position, ref vz, .015f);
|
|
}
|
|
}
|
|
|
|
public void OnBeginDrag(PointerEventData data)
|
|
{
|
|
anim.SetBool("Dragging",true);
|
|
if (!isAnswered)
|
|
{
|
|
thisTxt.raycastTarget = false;
|
|
thisTxt.transform.parent = defaultParent;
|
|
}
|
|
}
|
|
|
|
public void OnEndDrag(PointerEventData data)
|
|
{
|
|
thisTxt.transform.parent = transform;
|
|
if (!isAnswered)
|
|
{
|
|
thisTxt.raycastTarget = true;
|
|
anim.SetBool("Dragging",false);
|
|
}
|
|
else
|
|
{
|
|
thisTxt.text = "";
|
|
}
|
|
}
|
|
}
|