1.之前的拖拽都是直接拖拽图片
2.现在可以添加一个层,拖拽哪个图片在该层实时实例化一个对相应的图片即可,然后使图片跟随鼠标移动。
这样原始图片就不需要移动。
脚本准备:
1.DragItem.cs
该脚本挂预制件元素中,用来实际处理拖拽操作。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
public class DragItem : MonoBehaviour , IDragHandler,IBeginDragHandler,IEndDragHandler
{
// Use this for initialization
public DragItemPanel dragItemPanel;
void Start () {
}
// Update is called once per frame
void Update () {
}
public void OnDrag(PointerEventData eventData)
{
Debug.Log("Item Drag");
if(dragItemPanel != null)
{
dragItemPanel.moveItem(eventData);
}
}
public void OnEndDrag(PointerEventData eventData)
{
Debug.Log("EndDrag");
if(dragItemPanel != null)
{
dragItemPanel.hideItem();
}
}
public void OnBeginDrag(PointerEventData eventData)
{
Debug.Log