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