UNITY的UI之Pivot与Anchor区别

Pivot

Rotations, size, and scale modifications occur around the pivot so the position of the pivot affects the outcome of a rotation, resizing, or scaling. When the toolbar Pivot button is set to Pivot mode, the pivot of a Rect Transform can be moved in the Scene View.

Anchors

Rect Transforms include a layout concept called anchors. Anchors are shown as four small triangular handles in the Scene View and anchor information is also shown in the Inspector.

If the parent of a Rect Transform is also a Rect Transform, the child Rect Transform can be anchored to the parent Rect Transform in various ways. For example, the child can be anchored to the center of the parent, or to one of the corners.

UI element anchored to the center of the parent. The element maintains a fixed offset to the center.UI element anchored to the lower right corner of the parent. The element maintains a fixed offset to the lower right corner.

The anchoring also allows the child to stretch together with the width or height of the parent. Each corner of the rectangle has a fixed offset to its corresponding anchor, i.e. the top left corner of the rectangle has a fixed offset to the top left anchor, etc. This way the different corners of the rectangle can be anchored to different points in the parent rectangle.

UI element with left corners anchored to lower left corner of the parent and right corners anchored to lower right. The corners of the element maintains fixed offsets to their respective anchors.

The positions of the anchors are defined in fractions (or percentages) of the parent rectangle width and height. 0.0 (0%) corresponds to the left or bottom side, 0.5 (50%) to the middle, and 1.0 (100%) to the right or top side. But anchors are not limited to the sides and middle; they can be anchored to any point within the parent rectangle.

UI element with left corners anchored to a point a certain percentage from the left side of the parent and right corners anchored to a point a certain percentage from the right side of the parent rectangle.

You can drag each of the anchors individually, or if they are together, you can drag them together by clicking in the middle in between them and dragging. If you hold down Shift key while dragging an anchor, the corresponding corner of the rectangle will move together with the anchor.

A useful feature of the anchor handles is that they automatically snap to the anchors of sibling rectangles to allow for precise positioning.

Anchor presets

In the Inspector, the Anchor Preset button can be found in the upper left corner of the Rect Transform component. Clicking the button brings up the Anchor Presets dropdown. From here you can quickly select from some of the most common anchoring options. You can anchor the UI element to the sides or middle of the parent, or stretch together with the parent size. The horizontal and vertical anchoring is independent.

The Anchor Presets buttons displays the currently selected preset option if there is one. If the anchors on either the horizontal or vertical axis are set to different positions than any of the presets, the custom options is shown.

Anchor and position fields in the Inspector

You can click the Anchors expansion arrow to reveal the anchor number fields if they are not already visible. Anchor Min corresponds to the lower left anchor handle in the Scene View, and Anchor Max corresponds to the upper right handle.

The position fields of rectangle are shown differently depending on whether the anchors are together (which produces a fixed width and height) or separated (which causes the rectangle to stretch together with the parent rectangle).

When all the anchor handles are together the fields displayed are Pos X, Pos Y, Width and Height. The Pos X and Pos Y values indicate the position of the pivot relative to the anchors.

When the anchors are separated the fields can change partially or completely to Left, Right, Top and Bottom. These fields define the padding inside the rectangle defined by the anchors. The Left and Right fields are used if the anchors are separated horizontally and the Top and Bottom fields are used if they are separated vertically.

Note that changing the values in the anchor or pivot fields will normally counter-adjust the positioning values in order to make the rectangle stay in place. If cases where this is not desired, the Raw Mode can be enabled using a small button in the Inspector. This causes the anchor and pivot value to be able to be changed without any other values changing as a result. This will likely cause the rectangle to be visually moved or resized, since its position and size is dependent on the anchor and pivot values.

时间: 2024-08-28 21:16:08

UNITY的UI之Pivot与Anchor区别的相关文章

UI设计师与美工的区别

对于不了解UI设计师的人来说,很多人都会认为UI设计师就是设计图片的,那不就是美工吗?大部分人对UI的理解还停留在美术设计方面,认为UI的工作只是描边画线,缺乏对用户交互重要性的理解.其实这两个职位有着很大的区别,今天就来浅谈一下UI设计师与美工的区别. 第一.定义上的区别.UI设计师简称UID,指从事对软件的人机交互.操作逻辑.界面美观的整体设计工作的人.美工指对平面,色彩 ,基调,创意等进行加工和创作的技术人才,分为平面美工.网页美工和三维美工.一般需要精通Photoshop等设计软件.从定

【TGUI】从零开始搭建一个基于Unity的UI库 01

作为一个初学Unity3D一个来月的小菜鸟,要想自己搭建一个UI库也是挺疯狂的,但是老大不给用NGUI,然后那时候Unity4.6正式版还没发布(或者说我还不知道Unity4.6有自带UI),然后就无所畏惧的写下来了,目前虽然功能很简陋,实现的控件也非常少,但是作为练手的目的已经达成了,所以放上来给大家分享. -------------------------------------------------- 分割线 ---------------------------------------

关于Unity中UI中的Button节点

Button是最常用的UI节点,包含的组件有 1.Image组件 显示Button的纹理,把Image贴图拖进Image组件中后,记得点击Set Native Size,显示贴图原始大小 2.Button组件 Interatable:打钩表示按钮可以被点击和交互,取消钩表示不能被点击和交互. Transition:过度效果,A.默认状态  B.鼠标划过效果Highlighted Sprite  C.按钮按下效果Pressed Sprite  D.按钮禁用状态Disabled Sprite 这里有

unity中UI的屏幕自适应代码

public void ScreenUISelfAdptation(Transform scaleUI) { float widthrate = UnityEngine.Screen.width / 1920.0f; float heightrate = UnityEngine.Screen.height / 1080.0f; float postion_x = scaleUI.GetComponent<RectTransform>().anchoredPosition.x * widthra

Unity 协程与调用函数的区别以及示例应用

Coroutine:协同程序(简称:协程),参考网络给出以下两个定义供参考. 1> 协同程序,即在主程序运行时同时开启另一段逻辑处理,来协同当前程序的执行.换句话说,开启协同程序就是开启一个模拟线程. [作者注: 不是真正的线程] 2> 是一种很古老的编程模型,以前的操作系统里进程调度里用到过,现在操作系统的进程调度都是根据时间片和优先级来进行轮换,以前是要程序自己来释放cpu的控制权,一直不释放一直也就占用着cpu,这种要求程序自己来进行调度的编程模型应该就叫"协程".

Unity中UI界面颤抖解决方法

将Render Mode中属性改为Screen Space - Camera 摄像机挂在Canvas属性下会出现UI界面颤抖的效果. UI界面颤抖解决方式:将Render Mode中属性改为Screen Space - Overlay,如下图所示:

Unity UGUI——Rect Transform包裹(Anchor Presets)

Anchor Presets使用演示样品物业 watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvTXJfQUhhbw==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" > 版权声明:本文博主原创文章.博客,未经同意不得转载.

关于Unity中NGUI的Pivot和锚点

Pivot 创建一个Sprite1节点,关联一个图集和一张贴图,用图中的六个按钮调整这个贴图的Pivot点,一共有八个点可以选择 再创建一个Sprite2节点,作为Sprite1节点的子节点,关联一个图集和一张贴图,用图中的六个按钮调整这个贴图的Pivot点,一共有八个点可以选择,当Sprite2坐标设置为(0,0)的时候,子节点Sprite2的Pivot会和父节点Sprite1的Pivot位置重合. 这就是Pivot的作用

Unity中的Object和object的区别

Object是UnityEngine.Object,是Unity所有组件Component和GameObject的父类: object在Unity中是System.Object 举个简单的例子: Debug.Log(gameObject is Object); Debug.Log(gameObject is object); 前者返回true,后者也返回true: int num = 5; Debug.Log(num is Object); Debug.Log(num is object); 前