窗口的拖移的实现
代码:
要使用事件,需要先引用UnityEngine.EventSystems 命名空间,并实现对应的接口(关于对应的接口会单独发文介绍),这里用到的是拖拽(IDragHandler),开始拖拽(IBeginDragHandler),结束拖拽(IEndDragHandler)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;
/*
* 作者:
* 日期:
* 代码作用:
*/
public class DragTest : MonoBehaviour,IDragHandler,IBeginDragHandler,IEndDragHandler
{
Vector3 offest;
bool CanDrag = false;
//刚开始拖拽时第一下触发这个函数
public void OnBeginDrag(PointerEventData eventData)
{
if(RectTransformUtility.RectangleContainsScreenPoint(transform as RectTransform, Input.mousePosition))
{
//1、计算所有需要的数据 im