34 lines
896 B
C#
34 lines
896 B
C#
|
|
using UnityEngine;
|
||
|
|
public class DragModel : IDrag
|
||
|
|
{
|
||
|
|
private Vector3 screenPoint;
|
||
|
|
public int distance = 4;
|
||
|
|
public override void Init()
|
||
|
|
{
|
||
|
|
Hide();
|
||
|
|
}
|
||
|
|
public override void Show()
|
||
|
|
{
|
||
|
|
gameObject.SetActive(true);
|
||
|
|
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
|
||
|
|
transform.position = ray.GetPoint(distance);
|
||
|
|
screenPoint = Camera.main.WorldToScreenPoint(transform.position);
|
||
|
|
}
|
||
|
|
private void Update()
|
||
|
|
{
|
||
|
|
if (Input.GetMouseButton(0))
|
||
|
|
{
|
||
|
|
Vector3 curWorldPoint = Camera.main.ScreenToWorldPoint(new(Input.mousePosition.x, Input.mousePosition.y, screenPoint.z));
|
||
|
|
transform.position = curWorldPoint;
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
Hide();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
public override void Hide()
|
||
|
|
{
|
||
|
|
gameObject.SetActive(false);
|
||
|
|
}
|
||
|
|
}
|