You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
97 lines
2.4 KiB
97 lines
2.4 KiB
|
|
using UnityEngine;
|
|
using UnityEngine.Events;
|
|
using UnityEngine.EventSystems;
|
|
|
|
public class DragItem : MonoBehaviour, IPointerDownHandler, IPointerUpHandler, IDragHandler
|
|
{
|
|
|
|
|
|
[Header("鼠标按下事件")]
|
|
public UnityEvent _Downevent;
|
|
|
|
[Header("鼠标松开事件")]
|
|
public UnityEvent _UpEvent;
|
|
|
|
[Header("鼠标拖拽事件")]
|
|
public UnityEvent _DragEvent;
|
|
|
|
public float checkDistance = 60;
|
|
|
|
|
|
private bool canDrag = false;
|
|
private Vector3 tempPos;
|
|
private Vector3 resetPos;
|
|
|
|
private void OnEnable()
|
|
{
|
|
resetPos = transform.localPosition;
|
|
|
|
// _UpEvent.AddListener(CheckDragAear);
|
|
}
|
|
|
|
public void OnDrag(PointerEventData eventData)
|
|
{
|
|
if (canDrag)
|
|
{
|
|
_DragEvent.Invoke();
|
|
this.transform.position = Input.mousePosition;
|
|
}
|
|
}
|
|
|
|
public void OnPointerDown(PointerEventData eventData)
|
|
{
|
|
canDrag = true;
|
|
_Downevent.Invoke();
|
|
}
|
|
|
|
public void OnPointerUp(PointerEventData eventData)
|
|
{
|
|
canDrag = false;
|
|
tempPos = transform.position;
|
|
transform.localPosition = resetPos;
|
|
CheckDragAear();
|
|
_UpEvent.Invoke();
|
|
//GameManagerForZhuanWan.Instance.StartTimeAction(0.25f, () => { });
|
|
|
|
}
|
|
|
|
|
|
private void CheckDragAear()
|
|
{
|
|
DragCheck[] checks = GameObject.FindObjectsOfType<DragCheck>();
|
|
for (int i = 0; i < checks.Length; i++)
|
|
{
|
|
|
|
if (Vector2.Distance(this.tempPos, checks[i].transform.position) <= checkDistance)
|
|
{
|
|
|
|
if (checks[i].isMainAear)
|
|
{
|
|
//检测是否已经放置过设备
|
|
if (!GameManagerForZhuanWan.Instance.CheckAearHaveItem(checks[i].gameObject.name))
|
|
{
|
|
string value = GameManagerForZhuanWan.Instance.mainAearTxt.text.ToString();
|
|
int num = int.Parse(value);
|
|
num++;
|
|
GameManagerForZhuanWan.Instance.mainAearTxt.text = num.ToString();
|
|
|
|
GameManagerForZhuanWan.Instance.ShowTip("已放置一处主要区域");
|
|
}
|
|
|
|
|
|
}
|
|
else
|
|
{
|
|
GameManagerForZhuanWan.Instance.ShowTip("已放置一处次要区域");
|
|
}
|
|
|
|
//放置
|
|
checks[i].ShowItem();
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
}
|