mirror of
https://github.com/Alex-Rachel/TEngine.git
synced 2025-08-07 16:45:10 +00:00
[=]SafeTop ImageBackGround
[=]SafeTop ImageBackGround
This commit is contained in:
@@ -1,15 +1,17 @@
|
|||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
namespace GameLogic
|
namespace TEngine
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 背景图片等比拉伸
|
/// 背景图片等比拉伸。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class ImageBackGroundStretch : MonoBehaviour
|
public class ImageBackGroundStretch : MonoBehaviour
|
||||||
{
|
{
|
||||||
|
public float standardAspectValue = 9 / 16f;
|
||||||
|
|
||||||
protected virtual void Start()
|
protected virtual void Start()
|
||||||
{
|
{
|
||||||
DoImageStretch(9/16f);
|
DoImageStretch(standardAspectValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void DoImageStretch(float standardAspect)
|
private void DoImageStretch(float standardAspect)
|
@@ -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}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user