106 lines
2.4 KiB
C#
106 lines
2.4 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class SchGame_DragControl : MonoBehaviour
|
|
{
|
|
public Vector3 startingPos;
|
|
bool goingBack;
|
|
|
|
public bool havebeenSet = false;
|
|
public string className;
|
|
|
|
bool drag = false;
|
|
|
|
Transform originalParent;
|
|
// Start is called before the first frame update
|
|
void Start()
|
|
{
|
|
startingPos = transform.position;
|
|
originalParent = transform.parent;
|
|
}
|
|
|
|
public void StartDragging()
|
|
{
|
|
if (havebeenSet)
|
|
{
|
|
return;
|
|
}
|
|
|
|
GetComponentInChildren<Text>().raycastTarget = false;
|
|
GetComponent<Image>().raycastTarget = false;
|
|
|
|
transform.SetParent(transform.parent.parent);
|
|
|
|
drag = true;
|
|
StartCoroutine(GetBigger());
|
|
}
|
|
|
|
public void FollowMouse()
|
|
{
|
|
if (goingBack || havebeenSet)
|
|
{
|
|
return;
|
|
}
|
|
|
|
transform.position = Input.mousePosition;
|
|
}
|
|
|
|
public void EndDragging()
|
|
{
|
|
StartCoroutine(GoBackCor());
|
|
drag = false;
|
|
}
|
|
|
|
IEnumerator GetBigger()
|
|
{
|
|
while(transform.localScale.x < 1.2f && drag)
|
|
{
|
|
transform.localScale += new Vector3(.7f, .7f, 0) * Time.deltaTime;
|
|
|
|
yield return new WaitForEndOfFrame();
|
|
}
|
|
|
|
transform.localScale = new Vector3(1.2f, 1.2f, 1);
|
|
|
|
while (drag)
|
|
{
|
|
yield return new WaitForEndOfFrame();
|
|
}
|
|
|
|
while (transform.localScale.x > 1f)
|
|
{
|
|
transform.localScale -= new Vector3(.8f, .8f, 0) * Time.deltaTime;
|
|
|
|
yield return new WaitForEndOfFrame();
|
|
}
|
|
|
|
transform.localScale = new Vector3(1, 1, 1);
|
|
}
|
|
IEnumerator GoBackCor()
|
|
{
|
|
yield return new WaitForEndOfFrame();
|
|
|
|
if (!havebeenSet)
|
|
{
|
|
GetComponentInChildren<Text>().raycastTarget = true;
|
|
GetComponent<Image>().raycastTarget = true;
|
|
transform.SetParent(originalParent);
|
|
}
|
|
|
|
goingBack = true;
|
|
while (Vector2.Distance(transform.position, startingPos) > 10)
|
|
{
|
|
transform.position = Vector3.Lerp(transform.position, startingPos, 10 * Time.deltaTime);
|
|
|
|
yield return new WaitForEndOfFrame();
|
|
}
|
|
transform.position = startingPos;
|
|
goingBack = false;
|
|
|
|
|
|
yield break;
|
|
}
|
|
}
|