diff --git a/Assets/GameScripts/HotFix/GameLogic/UI.meta b/Assets/GameScripts/HotFix/GameLogic/UI.meta new file mode 100644 index 00000000..3d56f3a5 --- /dev/null +++ b/Assets/GameScripts/HotFix/GameLogic/UI.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 12517ef95f49a9144b18989aa8097420 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/GameScripts/HotFix/GameLogic/UI/Common.meta b/Assets/GameScripts/HotFix/GameLogic/UI/Common.meta new file mode 100644 index 00000000..5e90fb86 --- /dev/null +++ b/Assets/GameScripts/HotFix/GameLogic/UI/Common.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 0468386ed52c42b46a0b6df1601bc5e1 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/GameScripts/HotFix/GameLogic/UI/Common/ImageBackGroundStretch.cs b/Assets/GameScripts/HotFix/GameLogic/UI/Common/ImageBackGroundStretch.cs new file mode 100644 index 00000000..96ca55e2 --- /dev/null +++ b/Assets/GameScripts/HotFix/GameLogic/UI/Common/ImageBackGroundStretch.cs @@ -0,0 +1,30 @@ +using UnityEngine; + +namespace GameMain +{ + /// + /// 背景图片等比拉伸 + /// + public class ImageBackGroundStretch : MonoBehaviour + { + protected virtual void Start() + { + DoImageStretch(9/16f); + } + + private void DoImageStretch(float standardAspect) + { + float deviceAspect = Screen.width / (float)Screen.height; + if (standardAspect > deviceAspect) + { + float scale = standardAspect / deviceAspect; + transform.localScale = new Vector3(scale, scale, 1f); + } + else if (standardAspect < deviceAspect) + { + float scale = deviceAspect / standardAspect; + transform.localScale = new Vector3(scale, scale, 1f); + } + } + } +} diff --git a/Assets/GameScripts/HotFix/GameLogic/UI/Common/ImageBackGroundStretch.cs.meta b/Assets/GameScripts/HotFix/GameLogic/UI/Common/ImageBackGroundStretch.cs.meta new file mode 100644 index 00000000..6e6caf47 --- /dev/null +++ b/Assets/GameScripts/HotFix/GameLogic/UI/Common/ImageBackGroundStretch.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 4e6e63472f81d39499f4bf79b27eaf44 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/GameScripts/HotFix/GameLogic/UI/Common/SafeTop.cs b/Assets/GameScripts/HotFix/GameLogic/UI/Common/SafeTop.cs new file mode 100644 index 00000000..92ca76d2 --- /dev/null +++ b/Assets/GameScripts/HotFix/GameLogic/UI/Common/SafeTop.cs @@ -0,0 +1,21 @@ +using UnityEngine; +using TEngine; + +namespace GameMain +{ + public class SafeTop : MonoBehaviour + { + void Start() + { + var topRect = (gameObject.transform as RectTransform); + var safeArea = UnityEngine.Screen.safeArea; + if (topRect != null) + { + var anchoredPosition = topRect.anchoredPosition; + anchoredPosition = new Vector2(anchoredPosition.x,anchoredPosition.y - safeArea.y); + topRect.anchoredPosition = anchoredPosition; + } + Log.Debug(safeArea); + } + } +} diff --git a/Assets/GameScripts/HotFix/GameLogic/UI/Common/SafeTop.cs.meta b/Assets/GameScripts/HotFix/GameLogic/UI/Common/SafeTop.cs.meta new file mode 100644 index 00000000..cf1849a6 --- /dev/null +++ b/Assets/GameScripts/HotFix/GameLogic/UI/Common/SafeTop.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: c0a563c3e931db74f94f9991270a2dee +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/GameScripts/HotFix/GameLogic/UI/Common/UIExtension.cs b/Assets/GameScripts/HotFix/GameLogic/UI/Common/UIExtension.cs new file mode 100644 index 00000000..a6de80bc --- /dev/null +++ b/Assets/GameScripts/HotFix/GameLogic/UI/Common/UIExtension.cs @@ -0,0 +1,122 @@ +using System; +using System.Collections; +using UnityEngine; +using UnityEngine.UI; +using TEngine; + +public enum EUIGroup +{ + Root, + UI, + Dialog, + Tips, + System +} + +public static class UIExtension +{ + #region SetActive + public static void SetActive(this GameObject go, bool value, ref bool cacheValue) + { + if (go != null && value != cacheValue) + { + cacheValue = value; + go.SetActive(value); + } + } + #endregion + + public static IEnumerator FadeToAlpha(this CanvasGroup canvasGroup, float alpha, float duration, + Action callback = null) + { + float time = 0f; + float originalAlpha = canvasGroup.alpha; + while (time < duration) + { + time += Time.deltaTime; + canvasGroup.alpha = Mathf.Lerp(originalAlpha, alpha, time / duration); + yield return new WaitForEndOfFrame(); + } + + canvasGroup.alpha = alpha; + + callback?.Invoke(); + } + + public static IEnumerator SmoothValue(this Slider slider, float value, float duration, Action callback = null) + { + float time = 0f; + float originalValue = slider.value; + while (time < duration) + { + time += Time.deltaTime; + slider.value = Mathf.Lerp(originalValue, value, time / duration); + yield return new WaitForEndOfFrame(); + } + + slider.value = value; + + callback?.Invoke(); + } + + public static IEnumerator SmoothValue(this Scrollbar slider, float value, float duration, Action callback = null) + { + float time = 0f; + float originalValue = slider.size; + while (time < duration) + { + time += Time.deltaTime; + slider.size = Mathf.Lerp(originalValue, value, time / duration); + yield return new WaitForEndOfFrame(); + } + + slider.size = value; + + callback?.Invoke(); + } + + public static IEnumerator SmoothValue(this Image image, float value, float duration, Action callback = null) + { + float time = 0f; + float originalValue = image.fillAmount; + while (time < duration) + { + time += Time.deltaTime; + image.fillAmount = Mathf.Lerp(originalValue, value, time / duration); + yield return new WaitForEndOfFrame(); + } + + image.fillAmount = value; + + callback?.Invoke(); + } + + public static bool GetMouseDownUiPos(this UIModule uiModule, out Vector3 screenPos) + { + bool hadMouseDown = false; + Vector3 mousePos = Vector3.zero; + +#if UNITY_EDITOR || PLATFORM_STANDALONE_WIN + mousePos = Input.mousePosition; + hadMouseDown = Input.GetMouseButton(0); +#else + if (Input.touchCount > 0) + { + mousePos = Input.GetTouch(0).position; + hadMouseDown = true; + } + else + { + hadMouseDown = false; + } +#endif + + RectTransformUtility.ScreenPointToLocalPointInRectangle( + uiModule.UIRoot as RectTransform, + Input.mousePosition, + uiModule.UICamera, out var pos); + screenPos = uiModule.UIRoot.TransformPoint(pos); + + return hadMouseDown; + } +} \ No newline at end of file diff --git a/Assets/GameScripts/HotFix/GameLogic/UI/Common/UIExtension.cs.meta b/Assets/GameScripts/HotFix/GameLogic/UI/Common/UIExtension.cs.meta new file mode 100644 index 00000000..5405d388 --- /dev/null +++ b/Assets/GameScripts/HotFix/GameLogic/UI/Common/UIExtension.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: d376f2d7d7324712998e19cfa2e03039 +timeCreated: 1680161323 \ No newline at end of file