版权申明:

  • 本文原创首发于以下网站:
  1. 博客园『优梦创客』的空间:https://www.cnblogs.com/raymondking123
  2. 优梦创客的官方博客:https://91make.top
  3. 优梦创客的游戏讲堂:https://91make.ke.qq.com
  4. 『优梦创客』的微信公众号:umaketop
  • 您可以自由转载,但必须加入完整的版权声明

窗口拖动限制在一个特定的区域

public class Scene : MonoBehaviour, IDragHandler, IPointerDownHandler
{
public RectTransform RtTransform;
public RectTransform RTParent;
Vector2 downpos;
Vector2 newpos;
public void OnPointerDown(PointerEventData eventData)
{
RectTransformUtility.ScreenPointToLocalPointInRectangle
(RtTransform, eventData.position
,eventData.pressEventCamera, out downpos);
//print(downpos);
} public void OnDrag(PointerEventData eventData)
{
if (RectTransformUtility.ScreenPointToLocalPointInRectangle
(RtTransform, eventData.position
, eventData.pressEventCamera, out newpos))
{ Vector2 offset = newpos - downpos;
transform.parent.position = (Vector2)transform.parent.position + offset;
downpos = newpos;
} if (RTParent.position.x < 0)
{
Vector2 tmp = RTParent.position;
tmp.x = 0;
RTParent.position = tmp;
}
else if (RTParent.position.x > RtTransform.rect.width - RTParent.rect.width)
{
Vector2 tmp = RTParent.position;
tmp.x = RtTransform.rect.width - RTParent.rect.width;
RTParent.position = tmp;
} if (RTParent.position.y < 0)
{
Vector2 tmp = RTParent.position;
tmp.y = 0;
RTParent.position = tmp;
}
else if (RTParent.position.y > RtTransform.rect.height - RTParent.rect.height)
{
Vector2 tmp = RTParent.position;
tmp.y = RtTransform.rect.height - RTParent.rect.height;
RTParent.position = tmp;
} }

窗口缩放

public class Zoom : MonoBehaviour,IPointerDownHandler,IDragHandler
{
public RectTransform canvasWindow;
public RectTransform parentWinfow;
Vector2 downpos;
Vector2 newpos;
Vector2 origsize; public void OnPointerDown(PointerEventData eventData)
{
origsize = parentWinfow.sizeDelta;
RectTransformUtility.ScreenPointToLocalPointInRectangle
(canvasWindow, eventData.position, eventData.pressEventCamera, out downpos);
} public void OnDrag(PointerEventData eventData)
{ if (RectTransformUtility.ScreenPointToLocalPointInRectangle
(canvasWindow, eventData.position, eventData.pressEventCamera, out newpos))
{
Vector2 offpos=newpos-downpos;
// offpos.y *= -1;
parentWinfow.sizeDelta =origsize + offpos;
}
}
}

UGUI:窗口限制以及窗口缩放的更多相关文章

  1. JQuery-Dialog(弹出窗口,遮蔽窗口)

    在Ajax中经常用到的弹出窗口和遮蔽窗口.自己写肯定是一个最佳方案,但时间和成本上,还是决定了寻找现成的吧.大概罗列一下.需要我满足我几个条件 一定要简洁方便 拥有遮蔽功能,Model Dialog ...

  2. TCP滑动窗口(发送窗口和接受窗口)

    TCP窗口机制 TCP header中有一个Window Size字段,它其实是指接收端的窗口,即接收窗口.用来告知发送端自己所能接收的数据量,从而达到一部分流控的目的. 其实TCP在整个发送过程中, ...

  3. JavaScript子窗口调用父窗口变量和函数的方法

    在做一个父窗口开启子窗口并且在子窗口关闭的时候调用父窗口的方法,达到局部刷新的目的. 父窗口: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 ...

  4. UI: 窗口全屏, 窗口尺寸

    窗口全屏 窗口尺寸 示例1.窗口全屏UI/FullScreen.xaml <Page x:Class="Windows10.UI.FullScreen" xmlns=&quo ...

  5. tcp协议头窗口,滑动窗口,流控制,拥塞控制关系

    参考文章 TCP 的那些事儿(下) http://coolshell.cn/articles/11609.html tcp/ip详解--拥塞控制 & 慢启动 快恢复 拥塞避免 http://b ...

  6. 背水一战 Windows 10 (3) - UI: 窗口全屏, 窗口尺寸

    [源码下载] 背水一战 Windows 10 (3) - UI: 窗口全屏, 窗口尺寸 作者:webabcd 介绍背水一战 Windows 10 之 UI 窗口全屏 窗口尺寸 示例1.窗口全屏UI/F ...

  7. HTML中IFrame父窗口与子窗口相互操作

    一.Iframe篇 //&&&&&&&&&&&&&&&&&&am ...

  8. Win32编程:窗口类样式+窗口外观样式+窗口显示样式

    1.窗口类样式WNDCLASS.style CS_VREDRAW 提供窗口位置变化事件和高度变化事件的处理程序,功能是重绘窗口 CS_HREDRAW 提供窗口位置变化事件和宽度变化事件的处理程序,功能 ...

  9. JavaScript(Iframe、window.open、window.showModalDialog)父窗口与子窗口之间的操作

    一.Iframe 篇 公共部分 //父对象得到子窗口的值 //ObjectID是窗口标识,ContentID是元素ID function GetValue(ObjectID,ContentID) { ...

  10. js window.open() 父窗口与子窗口的互相调用(未必有用)

    javascript 父窗口与子窗口的互相调用 <html> <head></head> <body> 主要实现父子关系的页面 window.opene ...

随机推荐

  1. windows 7输入regedit 打不开注册表

    Win 10 win 7 Win7 regedit 打不开 怎么打不开 打不开了怎么办 没反应 不能打开 注册表? 1.使用键盘快捷键 win+r,打开运行工具. 2.在输入框内输入gepedit.m ...

  2. Linux record

    1.设置ubuntu密码刚安装好的ubuntu系统,没有root密码,需要用户去手动设置的. sudo passwd root 输入2次密码即可. 2. Linux下is not in the sud ...

  3. 论文阅读: Building a 3-D Line-Based Map Using Stereo SLAM

    Abstract 一个把直线用作feature的SLAM系统. 跟点相比, 直线对于环境的结构提供了更丰富的信息, 也让其鞥有可能推断地图的空间语义. 使用了Plucker line coordian ...

  4. myeclipse配置springmvc教程

    之前一直是使用Eclipse创建Web项目,用IDEA和MyEclipse的创建SpringMVC项目的时候时不时会遇到一些问题,这里把这个过程记录一下,希望能帮助到那些有需要的朋友.我是用的是MyE ...

  5. Prometheus 监控目标运行状态并邮件通知

    Prometheus 监控目标运行状态并邮件通知 邮件服务安装:https://www.cnblogs.com/xiangsikai/p/9809654.html 告警规则示例:https://pro ...

  6. Web应急:管理员账号被篡改

    你是某一个网站的管理员,有一天,你的管理员账号admin却登录不了,进入数据库查看,原来管理员账号用户名不存在了,却多了另外一个管理员用户名.不对,不是新增了管理员,而是你的管理员用户名被篡改了. 现 ...

  7. 【模板整合计划】DP动态规划

    [模板整合计划]DP动态规划 一:[背包] 1.[01背包] 采药 \([P1048]\) #include<algorithm> #include<cstdio> int T ...

  8. Windows下使用grep命令

    一.可供选择的工具列表: Grep for Windows – 轻量级选项 GNU utilities for Win32 – 本地港口 Cash – 重量轻,建于Node.js之上 Cygwin – ...

  9. Linux进程启动/指令执行方式研究

    1. 通过glibc api执行系统指令 0x1:system() glibc api system是linux系统提供的函数调用之一,glibc也提供了对应的封装api. system函数的原型为: ...

  10. 《 .NET并发编程实战》阅读指南 - 第3章

    先发表生成URL以印在书里面.等书籍正式出版销售后会公开内容.