init
This commit is contained in:
8
Assets/Game/UIManger/DDZ/Scripts.meta
Normal file
8
Assets/Game/UIManger/DDZ/Scripts.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b77513f8238ead942839e555b41e7005
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
50
Assets/Game/UIManger/DDZ/Scripts/SafeAreaController.cs
Normal file
50
Assets/Game/UIManger/DDZ/Scripts/SafeAreaController.cs
Normal file
@@ -0,0 +1,50 @@
|
||||
using UnityEngine;
|
||||
|
||||
[ExecuteAlways]
|
||||
public class SafeAreaController : MonoBehaviour
|
||||
{
|
||||
RectTransform Panel;
|
||||
Rect LastSafeArea = new Rect(0, 0, 0, 0);
|
||||
|
||||
void Awake()
|
||||
{
|
||||
Panel = GetComponent<RectTransform>();
|
||||
Refresh();
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
// Refresh();
|
||||
}
|
||||
|
||||
void Refresh()
|
||||
{
|
||||
Rect safeArea = GetSafeArea();
|
||||
|
||||
if (safeArea != LastSafeArea)
|
||||
ApplySafeArea(safeArea);
|
||||
}
|
||||
|
||||
public Rect GetSafeArea()
|
||||
{
|
||||
return Screen.safeArea;
|
||||
}
|
||||
|
||||
void ApplySafeArea(Rect r)
|
||||
{
|
||||
LastSafeArea = r;
|
||||
|
||||
// Convert safe area rectangle from absolute pixels to normalised anchor coordinates
|
||||
Vector2 anchorMin = r.position;
|
||||
Vector2 anchorMax = r.position + r.size;
|
||||
anchorMin.x /= Screen.width;
|
||||
anchorMin.y /= Screen.height;
|
||||
anchorMax.x /= Screen.width;
|
||||
anchorMax.y /= Screen.height;
|
||||
Panel.anchorMin = anchorMin;
|
||||
Panel.anchorMax = anchorMax;
|
||||
|
||||
// Debug.LogFormat("New safe area applied to {0}: x={1}, y={2}, w={3}, h={4} on full extents w={5}, h={6}",
|
||||
// name, r.x, r.y, r.width, r.height, Screen.width, Screen.height);
|
||||
}
|
||||
}
|
||||
11
Assets/Game/UIManger/DDZ/Scripts/SafeAreaController.cs.meta
Normal file
11
Assets/Game/UIManger/DDZ/Scripts/SafeAreaController.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 795ac1b8089e2df4eb37c4c260322d7d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user