- Mastering UI Development with Unity
- Ashley Godbold
- 336字
- 2021-08-27 18:43:14
Anchor and Pivot Point
Every UI object has a set of Anchor Handles and a Pivot Point. These objects used together will help ensure that your UI is positioned appropriately and scales appropriately if the resolution or aspect ratio of your game changes.
The Anchor Handles are represented by four triangles in the form of an X, as shown in the following diagram:

The Anchors can be in a group together forming a single Anchor, as shown in the preceding diagram, or they can be split in to multiple Anchors, as follows:

The Anchors will always form a rectangle. So, the sides will always line up.
The Rect Transform has properties for Anchor Min and Anchor Max points. These represent the position of the Anchor Handles relative to the parent's Rect Transform, as percentages. So, for example, a 0 in an x value represents all the way to the left, and a 1 represents all the way to the right. You can see from the following screenshot how adjusting the x value will move it left and right, relative to the parent:

The Rect Transform has a Property for Anchor Presets and Anchors Min and Max Points. The Anchor represents the point at which the UI element is connected to its parent's Rect Transform:

As a Canvas has no parent, you'll see that the Anchor Preset is empty. This is true, regardless of the Canvas Render Mode chosen:

Click on the box holding representing the Anchor Presets icon will display a list of all the possible Anchor Presets.

If you click on one of the presets, it will move the anchors to the position displayed in the screenshot. You can also adjust the position and pivot point using the anchor preset. The images will change if you hold down Shift and/or Alt. Holding Shift will show positions for the pivot point represented by blue dots, holding Alt will show how the position will change, and holding both will show the pivot point and the position change.

- 自然語言處理實戰:預訓練模型應用及其產品化
- ReSharper Essentials
- 少年輕松趣編程:用Scratch創作自己的小游戲
- Instant QlikView 11 Application Development
- TypeScript圖形渲染實戰:基于WebGL的3D架構與實現
- C程序設計案例教程
- 小程序開發原理與實戰
- Learning Laravel's Eloquent
- Python圖形化編程(微課版)
- C++20高級編程
- MINECRAFT編程:使用Python語言玩轉我的世界
- SwiftUI極簡開發
- 玩轉.NET Micro Framework移植:基于STM32F10x處理器
- Building Slack Bots
- iOS開發項目化入門教程