Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/artstorm/ui-toolkit-safe-area
A Safe Area Container for Unity's UI Toolkit.
https://github.com/artstorm/ui-toolkit-safe-area
game-development safe-area safearea ui ui-toolkit uitoolkit unity unity3d
Last synced: 4 days ago
JSON representation
A Safe Area Container for Unity's UI Toolkit.
- Host: GitHub
- URL: https://github.com/artstorm/ui-toolkit-safe-area
- Owner: artstorm
- License: mit
- Created: 2023-01-21T09:33:21.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2024-03-22T03:19:01.000Z (8 months ago)
- Last Synced: 2024-11-02T02:42:08.825Z (11 days ago)
- Topics: game-development, safe-area, safearea, ui, ui-toolkit, uitoolkit, unity, unity3d
- Language: C#
- Homepage:
- Size: 396 KB
- Stars: 59
- Watchers: 3
- Forks: 5
- Open Issues: 1
-
Metadata Files:
- Readme: .github/readme/collapse-margin.png
- License: LICENSE
Awesome Lists containing this project
README
# UI Toolkit Safe Area
Provides a Safe Area Container for Unity's UI Toolkit.
## About
The goal of the safe area container is to provide a custom control to simplify handling safe areas with UI Toolkit on relevant devices.
- Option to collapse margins with the safe area.
- Option to exclude specific safe area edges.
- Option to exclude safe area on tvOS.## Usage
The SafeArea container is available in the Library in UI Builder and can be found under Project → Custom Controls and can be dragged into the UI hierarchy.
![UI Builder Hierarchy](https://raw.githubusercontent.com/artstorm/ui-toolkit-safe-area/main/.github/readme/ui-builder-hierarchy.png)
The SafeArea container should be added as the top element in the hierarchy to ensure that it can fill up the entire screen. All child elements dropped into the SafeArea container will live inside `safe-area-content-container` and be adjusted accordingly depending on the current device SafeArea.
Margins can be set on the SafeArea container, which can be useful when running on devices that does not utilize a safe area.
The SafeArea container has a selection of custom attributes that can be set in the UI Builder inspector.
![UI Builder Inspector](https://raw.githubusercontent.com/artstorm/ui-toolkit-safe-area/main/.github/readme/ui-builder-inspector.png)
### Collapse Margins
The container margins and the safe area is collapsed by default. That can be disabled in the inspector.
Take a look at these screenshots which helps illustrate the differences how margin, safe area and collapse comes together. In each example the margin is set to `10px 10px 0px 10px`.
![UI Builder Inspector](https://raw.githubusercontent.com/artstorm/ui-toolkit-safe-area/main/.github/readme/collapse-margin.png)
1. For a device without a safe area, the margin values are used as-is and collapse margins doesn't play a part as there is no safe area to collapse with.
2. For a device with a safe area the margins are collapsed with the safe area. The margin value is used if it would be larger than the safe area.
3. If `Collapse Margins` is disabled, the margin is added to the safe area.### Exclude Edges
With exclude edges, the safe area value of `left`, `right`, `top` and `bottom` edges can optionally be excluded from the calculations. If an edge is excluded, only the margin value for that edge will be used.
### Exclude tvOS
This option excludes the safe area values for all edges on tvOS. If selected, tvOS builds will not use safe area but only the margin values.
## Installation
Requires Unity 2021.3 LTS or higher.
### OpenUPM
The package is available on the [OpenUPM registry](https://openupm.com). It's recommended to install it via [openupm-cli](https://github.com/openupm/openupm-cli).
```sh
openupm add com.bitbebop.ui-toolkit-safe-area
```### Unity Package Manager and Git URL
Install the package directly in Unity Package Manger using this URL:
```
https://github.com/artstorm/ui-toolkit-safe-area.git?path=/Packages/com.bitbebop.ui-toolkit-safe-area
```Open Unity Package Manager → + → Add package from git URL:
![Add package from git URL](https://raw.githubusercontent.com/artstorm/ui-toolkit-safe-area/main/.github/readme/installation-git-1.png)
Paste URL:
![Paste git URL](https://raw.githubusercontent.com/artstorm/ui-toolkit-safe-area/main/.github/readme/installation-git-2.png)