58 lines
1.7 KiB
C#
58 lines
1.7 KiB
C#
using System;
|
|
using Unity.VisualScripting;
|
|
using UnityEngine;
|
|
using UnityEngine.EventSystems;
|
|
|
|
namespace ZXL.Scripts.UI
|
|
{
|
|
/// <summary>
|
|
/// 弃用
|
|
/// </summary>
|
|
public class DragItem : MonoBehaviour, IDragHandler, IPointerUpHandler, IPointerDownHandler
|
|
{
|
|
RectTransform rectTransform;
|
|
// public GameObject go;
|
|
|
|
private void Awake()
|
|
{
|
|
rectTransform = GetComponent<RectTransform>();
|
|
var boxCollider2D = gameObject.AddComponent<BoxCollider2D>();
|
|
boxCollider2D.isTrigger = true;
|
|
boxCollider2D.size = new Vector2(rectTransform.rect.width, rectTransform.rect.height);
|
|
}
|
|
|
|
private void Start()
|
|
{
|
|
ZMouse.Instance.MouseUp0 += MouseUp;
|
|
}
|
|
|
|
private void MouseUp(object arg1, object arg2)
|
|
{
|
|
if (arg1 != null && arg2 != null && (GameObject)arg2 == this.gameObject)
|
|
{
|
|
var o = (GameObject)arg1;
|
|
o.transform.SetParent(transform);
|
|
o.transform.SetLocalPositionAndRotation(Vector3.zero, Quaternion.identity);
|
|
}
|
|
}
|
|
|
|
public void OnDrag(PointerEventData eventData)
|
|
{
|
|
// rectTransform.anchoredPosition += eventData.delta;
|
|
}
|
|
|
|
public void OnPointerUp(PointerEventData eventData)
|
|
{
|
|
// if (go != null)
|
|
// {
|
|
// go.GetComponent<AssetItem>();
|
|
// transform.SetParent(go.transform);
|
|
// transform.SetLocalPositionAndRotation(Vector3.zero, Quaternion.identity);
|
|
// }
|
|
}
|
|
|
|
public void OnPointerDown(PointerEventData eventData)
|
|
{
|
|
}
|
|
}
|
|
} |