using System;
using AX.InputSystem;
using UnityEngine;
using UnityEngine.EventSystems;
///
/// UI拖拽脚本,想拖拽谁就挂在谁身上。必须保证该UI有Raycast Target组件,并使其保持开启状态。
///
[RequireComponent(typeof(CreateStaticObjID))]
[RequireComponent(typeof(BaseGameObjInfo))]
public class OnDragPanel : MonoBehaviour, IDragHandler, IBeginDragHandler, IEndDragHandler
{
private RectTransform canvasRect;
private RectTransform transRect;
private Vector2 localPos;
private Vector2 offSet;
public bool limit;
private Vector2 anchoredPosition;
private void Start()
{
canvasRect = GameObject.Find("Canvas").GetComponent();
transRect = GetComponent();
offSet = localPos = Vector3.zero;
anchoredPosition = transRect.anchoredPosition;
}
public void OnBeginDrag(PointerEventData eventData)
{
if (eventData.button != PointerEventData.InputButton.Left) return;//不是左键按下就不能拖拽
if (RectTransformUtility.ScreenPointToLocalPointInRectangle(canvasRect, eventData.position, canvasRect.GetComponent