diff --git a/Runtime/Type/Screen.meta b/Runtime/Type/Screen.meta new file mode 100644 index 0000000..68d84b4 --- /dev/null +++ b/Runtime/Type/Screen.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: cd531b4b89e02624cb1c5e28e82c927d +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Type/Screen/CanvasZoomAdjustmentBase.cs b/Runtime/Type/Screen/CanvasZoomAdjustmentBase.cs new file mode 100644 index 0000000..f370590 --- /dev/null +++ b/Runtime/Type/Screen/CanvasZoomAdjustmentBase.cs @@ -0,0 +1,67 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using UnityEngine.UI; + +namespace XericLibrary.Runtime.Type +{ + /// + /// 调整缩放以适配分辨率 + /// + public class CanvasZoomAdjustmentBase : WeaklyMonoBase + { + #region 字段属性 + + protected CanvasScaler _canvasScaler; + + /// + /// 当前目标屏幕的分辨率 + /// + public static Vector2Int CurrentScreenResolution + => new Vector2Int(Screen.currentResolution.width, Screen.currentResolution.height); + + /// + /// 常规标准屏幕 16:9 + /// + public static Vector2Int FullHDScreenResolution + => new Vector2Int(1920, 1080); + + /// + /// 常规标准屏幕 16:9 + /// + public static Vector2Int QHDScreenResolution + => new Vector2Int(2560, 1440); + + #endregion + + #region 生命周期 + + private void Awake() + { + _canvasScaler = transform.GetComponent(); + } + + #endregion + + #region MyRegion + + /// + /// 获取与给定的标准宽度的缩放比例 + /// + /// + /// + public static float ScreenScaleFactorWithWidth(int standardWidth = 1920) + => (float)Screen.currentResolution.width / standardWidth; + + /// + /// 获取与给定的标准高度的缩放比例 + /// + /// + /// + public static float ScreenScaleFactorWithHeight(int standardHeight = 1080) + => (float)Screen.currentResolution.height / standardHeight; + + #endregion + } +} diff --git a/Runtime/Type/Screen/CanvasZoomAdjustmentBase.cs.meta b/Runtime/Type/Screen/CanvasZoomAdjustmentBase.cs.meta new file mode 100644 index 0000000..596bc5e --- /dev/null +++ b/Runtime/Type/Screen/CanvasZoomAdjustmentBase.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: a9e4512923ba0d64cb475d93f7c9f055 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Type/Screen/CanvasZoomStart.cs b/Runtime/Type/Screen/CanvasZoomStart.cs new file mode 100644 index 0000000..b7e651e --- /dev/null +++ b/Runtime/Type/Screen/CanvasZoomStart.cs @@ -0,0 +1,15 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +namespace XericLibrary.Runtime.Type +{ + public class CanvasZoomStart : CanvasZoomAdjustmentBase + { + // Start is called before the first frame update + void Start() + { + _canvasScaler.scaleFactor = ScreenScaleFactorWithWidth(); + } + } +} diff --git a/Runtime/Type/Screen/CanvasZoomStart.cs.meta b/Runtime/Type/Screen/CanvasZoomStart.cs.meta new file mode 100644 index 0000000..4496b46 --- /dev/null +++ b/Runtime/Type/Screen/CanvasZoomStart.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 5e5e480bc8648214891d46b029219a27 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: