版权申明:

  • 本文原创首发于以下网站:
  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. 洛谷 P1440 求m区间内的最小值

    传送门 思路 由于数据范围很大,所以使用单调队列,和滑动窗口这道题类似 首先第一个数输出\(0\),因为第一个数之前没有数 然后通过样例我们发现,最后一个数并没有派上什么用场,所以循环\(n-1\)轮 ...

  2. Attention篇(二)

    主要是对<Attention is all you need>的分析 结合:http://www.cnblogs.com/robert-dlut/p/8638283.html  以及自己的 ...

  3. A1041 Be Unique (20 分)

    一.技术总结 这题在思考的时候遇见了,不知道怎么处理输入顺序问题,虽然有记录每个的次数,事后再反过来需要出现一次的且在第一次出现, 这时我们其实可以使用另一个数组用来存储输入顺序的字符,然后再用另一个 ...

  4. 中移物联网Java面试-社招-三面(2019/07)

    个人情况 2017年毕业,普通本科,计算机科学与技术专业,毕业后在一个二三线小城市从事Java开发,2年Java开发经验.做过分布式开发,没有高并发的处理经验,平时做To G的项目居多.写下面经是希望 ...

  5. pom中更换阿里云仓库时不要忽略了pluginRepositories

    用maven也大几年了,也一直在用阿里云的中央仓库. 不喜欢在maven的settings.xml里改,更喜欢直接在pom.xml里改,因为受git管理,小伙伴们拉下来即可. 然而网上的大部分技术文章 ...

  6. pyspark 日常整理

    1  联表 df1.join(df2,连接条件,连接方式) 如:df1.join(df2,[df1.a==df2.a], "inner").show() 连接方式:字符串类型, 如 ...

  7. There is no getter for property named 'id' in 'class java.lang.Integer

    There is no getter for property named 'id' in 'class java.lang.Integer 问题描述: 使用mybatis传入参数, 当参数类型是St ...

  8. # Leetcode 67:Add Binary(二进制求和)

    Leetcode 67:Add Binary(二进制求和) (python.java) Given two binary strings, return their sum (also a binar ...

  9. jquery库与其他库(比如prototype)冲突的解决方法

    前端开发很容易会遇到jQuery库与其他库冲突的场景,比如和prototype库冲突. 实际上这种冲突是因为不同的第三方JS库争夺对$标识符的控制权引起的. 解决方法,就是使用jQuery提供的jQu ...

  10. MediaWiki上传文件大小设置

    一.概述 MediaWiki默认最大上传文件大小为2M,碰到文件较大需要修改这个限制,需要改为8M. 二.修改php.ini 使用docker运行的MediaWiki,默认是没有php.ini这个文件 ...