拖动UI

第一种:

using UnityEngine;
using UnityEngine.EventSystems;public class test : MonoBehaviour, IDragHandler
{private RectTransform rt;// Start is called before the first frame updatevoid Start(){rt = GetComponent<RectTransform>();}public void OnDrag(PointerEventData eventData){Vector3 pos;if (RectTransformUtility.ScreenPointToWorldPointInRectangle(rt, eventData.position, eventData.pressEventCamera,out pos)){rt.position = pos;}}
」

当鼠标位置需要在ui的左上角时

private Vector3 v3;void Start(){v3 = new Vector3(rt.rect.width / 2, -rt.rect.height / 2);}//在ui重新赋值的时候加上v3即可

第二种:
点在哪ui跟随到哪


using UnityEngine;
using UnityEngine.EventSystems;public class DragUI : MonoBehaviour, IDragHandler, IPointerDownHandler {private Vector2 offsetPos;  public void OnDrag(PointerEventData eventData){transform.position = eventData.position - offsetPos;}public void OnPointerDown(PointerEventData eventData){offsetPos = eventData.position - (Vector2)transform.position;}
}

Unity 鼠标拖动UI相关推荐

  1. unity 鼠标拖动UI 滚轮缩放大小

    using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using U ...

  2. Unity鼠标拖动物体、按下鼠标左键旋转观察物体、鼠标滚轮缩放视野

    如题目所示,本文实现这三个效果.所有代码都在pc端成功运行,移植到手机端改变相应的判断条件即可,核心算法没有问题. 一. 鼠标拖拽移动物体 效果演示 源代码 public class mousedra ...

  3. Unity鼠标拖动3D物体移动,并限制拖动范围

    using UnityEngine; using System.Collections;public class DragObject : MonoBehaviour {/// <summary ...

  4. unity 鼠标进入UI和退出UI

    UGUI button 鼠标悬浮打印` using UnityEngine; using UnityEngine.UI; using UnityEngine.EventSystems; public ...

  5. unity 鼠标放置 ui_ui层次结构以及不常见但至关重要的任务放置在哪里

    unity 鼠标放置 ui Modern technology is complex. It's not always complicated though, thanks to our consta ...

  6. Unity 拖动UI物体(干货)

    Unity 拖动UI物体(超级干货) 首先我们先创建一个C#脚本 名字就叫MyMove 代码如下 using System.Collections; using System.Collections. ...

  7. jquery 鼠标拖动排序Li或Table

    1.前端页面 <%@ Page Language="C#" AutoEventWireup="true" CodeFile="拖动排序Li或Ta ...

  8. Qt 自定义标题栏,最小化、最大化、关闭窗口,双击最大化,鼠标拖动等效果实现

    文章目录 前言 效果 代码 .pro文件 widget.h widget.cpp widget.ui title.h title.cpp title.ui 前言 本次实验内容为Qt自定义标题栏,最小化 ...

  9. 【QT 5 设置自定义标题栏+学习:《QT实现鼠标拖动调整窗口大小》+基础样例】

    [QT 5 设置自定义标题栏+学习:<QT实现鼠标拖动调整窗口大小>+基础样例] 1.说明 2.实验环境 3.实验目的 4.参考文章 5.实验步骤 (1)下载代码,运行没有错误. (2)加 ...

最新文章

  1. HGOI 20190709 题解
  2. python语言的数据类型有哪些_Python语言有哪些数据类型
  3. 用CORS 解决vue.js django跨域调用
  4. Cannot assign to 'self' outside of a method in the init family
  5. 遇到attemp to invoke virtual method
  6. 新增或编辑保存时出错后,页面无法再次编辑
  7. 最短路径——dj+floyd+spfa(hdu2544)
  8. Aizu0189 Convenient Location【Floyd算法】
  9. Ansible Loops
  10. 【测试】echo发送和接收TCP/UDP数据包|shell 发送TCP/UDP数据包
  11. 【软件开发架构平台】CH2 Spring IoC和Bean管理
  12. 手机号码归属地查询接口大全(七种)
  13. Linux_常用的磁盘列阵(RAID)
  14. Java中Map详解
  15. 9.11 myl模拟赛
  16. 社区专家谈12306
  17. Vena Network CEO朱清:寒冬中的守夜人
  18. OpenCV笔记_1.cvtColor()Bayer色彩空间
  19. matplotlib绘制极坐标图
  20. 随机接入流程 - 4 Step RA

热门文章

  1. C++-二分查找库函数
  2. 哪一种验证方法最好?形式验证、硬件加速还是动态仿真?
  3. 佐治亚大学计算机工程本科课程,美国大学本科专业排名:计算机工程.docx
  4. 如何用CSS实现角标
  5. xheditor form java_xheditor 上传图片 Jfinal处理 出现异常
  6. 抓取中国天气网当前时段所有城市的天气数据(python+xpath)
  7. 解决升级Flutter3.0后出现警告Operand of null-aware operation ‘!‘ has type ‘WidgetsBinding‘ which excludes null
  8. 【Arduino 连接DHT11 湿度和温度传感器】
  9. 从上帝视角看进程调度
  10. 网络协议 一 MAC地址、IP地址、子网掩码