From 079ff980a361fae50fa1be97926740dfe43dc07e Mon Sep 17 00:00:00 2001 From: ALEXTANG <574809918@qq.com> Date: Tue, 9 May 2023 14:34:14 +0800 Subject: [PATCH] [=]SafeTop ImageBackGround [=]SafeTop ImageBackGround --- .../MonoExtend}/ImageBackGroundStretch.cs | 8 +++-- .../ImageBackGroundStretch.cs.meta | 0 .../UGUIExtension/MonoExtend/SafeTop.cs | 32 +++++++++++++++++++ .../UGUIExtension/MonoExtend}/SafeTop.cs.meta | 0 4 files changed, 37 insertions(+), 3 deletions(-) rename Assets/{GameScripts/HotFix/GameLogic/UI/Common => TEngine/Runtime/Extension/UGUIExtension/MonoExtend}/ImageBackGroundStretch.cs (82%) rename Assets/{GameScripts/HotFix/GameLogic/UI/Common => TEngine/Runtime/Extension/UGUIExtension/MonoExtend}/ImageBackGroundStretch.cs.meta (100%) create mode 100644 Assets/TEngine/Runtime/Extension/UGUIExtension/MonoExtend/SafeTop.cs rename Assets/{GameScripts/HotFix/GameLogic/UI/Common => TEngine/Runtime/Extension/UGUIExtension/MonoExtend}/SafeTop.cs.meta (100%) diff --git a/Assets/GameScripts/HotFix/GameLogic/UI/Common/ImageBackGroundStretch.cs b/Assets/TEngine/Runtime/Extension/UGUIExtension/MonoExtend/ImageBackGroundStretch.cs similarity index 82% rename from Assets/GameScripts/HotFix/GameLogic/UI/Common/ImageBackGroundStretch.cs rename to Assets/TEngine/Runtime/Extension/UGUIExtension/MonoExtend/ImageBackGroundStretch.cs index 92c6cf21..f71a86ec 100644 --- a/Assets/GameScripts/HotFix/GameLogic/UI/Common/ImageBackGroundStretch.cs +++ b/Assets/TEngine/Runtime/Extension/UGUIExtension/MonoExtend/ImageBackGroundStretch.cs @@ -1,15 +1,17 @@ using UnityEngine; -namespace GameLogic +namespace TEngine { /// - /// 背景图片等比拉伸 + /// 背景图片等比拉伸。 /// public class ImageBackGroundStretch : MonoBehaviour { + public float standardAspectValue = 9 / 16f; + protected virtual void Start() { - DoImageStretch(9/16f); + DoImageStretch(standardAspectValue); } private void DoImageStretch(float standardAspect) diff --git a/Assets/GameScripts/HotFix/GameLogic/UI/Common/ImageBackGroundStretch.cs.meta b/Assets/TEngine/Runtime/Extension/UGUIExtension/MonoExtend/ImageBackGroundStretch.cs.meta similarity index 100% rename from Assets/GameScripts/HotFix/GameLogic/UI/Common/ImageBackGroundStretch.cs.meta rename to Assets/TEngine/Runtime/Extension/UGUIExtension/MonoExtend/ImageBackGroundStretch.cs.meta diff --git a/Assets/TEngine/Runtime/Extension/UGUIExtension/MonoExtend/SafeTop.cs b/Assets/TEngine/Runtime/Extension/UGUIExtension/MonoExtend/SafeTop.cs new file mode 100644 index 00000000..bfa79464 --- /dev/null +++ b/Assets/TEngine/Runtime/Extension/UGUIExtension/MonoExtend/SafeTop.cs @@ -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}"); + } + } +} \ No newline at end of file diff --git a/Assets/GameScripts/HotFix/GameLogic/UI/Common/SafeTop.cs.meta b/Assets/TEngine/Runtime/Extension/UGUIExtension/MonoExtend/SafeTop.cs.meta similarity index 100% rename from Assets/GameScripts/HotFix/GameLogic/UI/Common/SafeTop.cs.meta rename to Assets/TEngine/Runtime/Extension/UGUIExtension/MonoExtend/SafeTop.cs.meta