using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using UnityEngine.EventSystems;
public class UGUIForDrag : MonoBehaviour, IDragHandler, IBeginDragHandler, IEndDragHandler, IDropHandler
{
//创建一个Gameobject作为拖拽时被拖拽对象的代替品
private GameObject drag_icon;
//该物体是否可以进行拖拽
public bool isCanDrug;
//匹配信息
public string matching;
/// <summary>
/// 拖拽时为新生成的拖拽图片进行位置更新
/// </summary>
/// <param name="eventData"></param>
public void OnDrag(PointerEventData eventData)
{
if (!isCanDrug) return;
//并将拖拽时的坐标给予被拖拽对象的代替品
Vector3 pos;
if (RectTransformUtility.ScreenPointToWorldPointInRectangle(drag_icon.GetComponent<RectTransform>(), eventData.position, eventData.pressEventCamera, out pos))
{
drag_icon.transform.position = pos;
}
}
/// <summary>
/// 拖拽图片初始
/// </summary>
///
Ugui中的图片拖拽
最新推荐文章于 2024-04-12 10:26:21 发布