Created
October 30, 2019 14:34
-
-
Save tsubaki/7864fff05e66f7ef5af30bad4c44b552 to your computer and use it in GitHub Desktop.
縦のノッチ一つ前提、ノッチの位置で安全マージンを設定する
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
[ExecuteAlways] | |
public class NotchPadding : MonoBehaviour | |
{ | |
[SerializeField] RectTransform left, right; | |
void Update() | |
{ | |
if (Screen.cutouts == null || Screen.cutouts[0] == null || left == null || right == null) | |
return; | |
var resolition = Screen.currentResolution; | |
left.anchorMin = new Vector2(0, Screen.cutouts[0].yMin / resolition.height); | |
left.anchorMax = new Vector2(Screen.cutouts[0].xMin / resolition.width, 1); | |
right.anchorMin = new Vector2(Screen.cutouts[0].xMax / resolition.width, Screen.cutouts[0].yMin / resolition.height); | |
right.anchorMax = new Vector2(1, 1); | |
} | |
} |
Author
tsubaki
commented
Oct 30, 2019
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment