Unity 鼠标拖动UI
拖动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相关推荐
- unity 鼠标拖动UI 滚轮缩放大小
using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using U ...
- Unity鼠标拖动物体、按下鼠标左键旋转观察物体、鼠标滚轮缩放视野
如题目所示,本文实现这三个效果.所有代码都在pc端成功运行,移植到手机端改变相应的判断条件即可,核心算法没有问题. 一. 鼠标拖拽移动物体 效果演示 源代码 public class mousedra ...
- Unity鼠标拖动3D物体移动,并限制拖动范围
using UnityEngine; using System.Collections;public class DragObject : MonoBehaviour {/// <summary ...
- unity 鼠标进入UI和退出UI
UGUI button 鼠标悬浮打印` using UnityEngine; using UnityEngine.UI; using UnityEngine.EventSystems; public ...
- unity 鼠标放置 ui_ui层次结构以及不常见但至关重要的任务放置在哪里
unity 鼠标放置 ui Modern technology is complex. It's not always complicated though, thanks to our consta ...
- Unity 拖动UI物体(干货)
Unity 拖动UI物体(超级干货) 首先我们先创建一个C#脚本 名字就叫MyMove 代码如下 using System.Collections; using System.Collections. ...
- jquery 鼠标拖动排序Li或Table
1.前端页面 <%@ Page Language="C#" AutoEventWireup="true" CodeFile="拖动排序Li或Ta ...
- Qt 自定义标题栏,最小化、最大化、关闭窗口,双击最大化,鼠标拖动等效果实现
文章目录 前言 效果 代码 .pro文件 widget.h widget.cpp widget.ui title.h title.cpp title.ui 前言 本次实验内容为Qt自定义标题栏,最小化 ...
- 【QT 5 设置自定义标题栏+学习:《QT实现鼠标拖动调整窗口大小》+基础样例】
[QT 5 设置自定义标题栏+学习:<QT实现鼠标拖动调整窗口大小>+基础样例] 1.说明 2.实验环境 3.实验目的 4.参考文章 5.实验步骤 (1)下载代码,运行没有错误. (2)加 ...
最新文章
- HGOI 20190709 题解
- python语言的数据类型有哪些_Python语言有哪些数据类型
- 用CORS 解决vue.js django跨域调用
- Cannot assign to 'self' outside of a method in the init family
- 遇到attemp to invoke virtual method
- 新增或编辑保存时出错后,页面无法再次编辑
- 最短路径——dj+floyd+spfa(hdu2544)
- Aizu0189 Convenient Location【Floyd算法】
- Ansible Loops
- 【测试】echo发送和接收TCP/UDP数据包|shell 发送TCP/UDP数据包
- 【软件开发架构平台】CH2 Spring IoC和Bean管理
- 手机号码归属地查询接口大全(七种)
- Linux_常用的磁盘列阵(RAID)
- Java中Map详解
- 9.11 myl模拟赛
- 社区专家谈12306
- Vena Network CEO朱清:寒冬中的守夜人
- OpenCV笔记_1.cvtColor()Bayer色彩空间
- matplotlib绘制极坐标图
- 随机接入流程 - 4 Step RA
热门文章
- C++-二分查找库函数
- 哪一种验证方法最好?形式验证、硬件加速还是动态仿真?
- 佐治亚大学计算机工程本科课程,美国大学本科专业排名:计算机工程.docx
- 如何用CSS实现角标
- xheditor form java_xheditor 上传图片 Jfinal处理 出现异常
- 抓取中国天气网当前时段所有城市的天气数据(python+xpath)
- 解决升级Flutter3.0后出现警告Operand of null-aware operation ‘!‘ has type ‘WidgetsBinding‘ which excludes null
- 【Arduino 连接DHT11 湿度和温度传感器】
- 从上帝视角看进程调度
- 网络协议 一 MAC地址、IP地址、子网掩码