[=]SafeTop ImageBackGround

[=]SafeTop ImageBackGround
This commit is contained in:
ALEXTANG
2023-05-09 14:34:14 +08:00
parent edc83c8989
commit 079ff980a3
4 changed files with 37 additions and 3 deletions

View File

@@ -1,15 +1,17 @@
using UnityEngine;
namespace GameLogic
namespace TEngine
{
/// <summary>
/// 背景图片等比拉伸
/// 背景图片等比拉伸
/// </summary>
public class ImageBackGroundStretch : MonoBehaviour
{
public float standardAspectValue = 9 / 16f;
protected virtual void Start()
{
DoImageStretch(9/16f);
DoImageStretch(standardAspectValue);
}
private void DoImageStretch(float standardAspect)

View File

@@ -0,0 +1,32 @@
using UnityEngine;
using TEngine;
namespace TEngine
{
public class SafeTop : MonoBehaviour
{
void Start()
{
var topRect = gameObject.transform as RectTransform;
CheckNotch(true);
if (topRect != null)
{
var anchoredPosition = topRect.anchoredPosition;
anchoredPosition = new Vector2(anchoredPosition.x, anchoredPosition.y - _notchHeight);
topRect.anchoredPosition = anchoredPosition;
}
}
private static float _notchHeight;
public static void CheckNotch(bool applyEditorNotch = false)
{
#if UNITY_EDITOR
_notchHeight = applyEditorNotch ? Screen.safeArea.y > 0f ? Screen.safeArea.y : Screen.currentResolution.height - Screen.safeArea.height : 0f;
#else
_notchHeight = Screen.safeArea.y > 0f ? Screen.safeArea.y : Screen.currentResolution.height - Screen.currentResolution.height;
#endif
Debug.Log($"CheckNotch :{_notchHeight}");
}
}
}