From 4fd4d7f7cbf8ccd802f858af2186d6d763984b46 Mon Sep 17 00:00:00 2001 From: Shepherd Zhu Date: Sun, 27 Oct 2024 20:11:29 +0800 Subject: [PATCH 1/2] [feat] high res scale adjustment Allow user to set a reference resolution just like UGUI did. --- Unity/UnityWinForms.cs | 35 ++++++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/Unity/UnityWinForms.cs b/Unity/UnityWinForms.cs index edc2c39..207fb82 100644 --- a/Unity/UnityWinForms.cs +++ b/Unity/UnityWinForms.cs @@ -1,4 +1,4 @@ -namespace Unity.API +namespace Unity.API { using System; using System.Collections.Generic; @@ -8,8 +8,16 @@ using UE = UnityEngine; using SWF = System.Windows.Forms; - public sealed class UnityWinForms : UE.MonoBehaviour + public sealed class UnityWinForms : UE.MonoBehaviour { + [UE.Tooltip("Reference Screen Resolution")] + public int referScreenWidth; + public int referScreenHeight; + + [UE.Tooltip("Reference Screen Scale Factor")] + public float scaleFactorX = 1.0f; + public float scaleFactorY = 1.0f; + public AppResources Resources; [UE.Tooltip("Delay between first KeyDown event and following ones")] @@ -29,7 +37,7 @@ public sealed class UnityWinForms : UE.MonoBehaviour private float shiftDownTimer; private float shiftDownDelayTimer; // Shift pressing is really fast. private bool paused; - + internal static UE.Texture2D DefaultTexture { get { return defaultTexture; } @@ -54,6 +62,19 @@ internal static void Inspect(object obj) private void Awake() { + if(referScreenWidth <=0 || referScreenHeight <= 0) + { + referScreenWidth = UE.Screen.width; + referScreenHeight = UE.Screen.height; + } + + if(scaleFactorX > 0f && scaleFactorY > 0f) + { + // 高分辨率适应 + Application.ScaleX = (float)UE.Screen.width / (float)referScreenWidth * scaleFactorX; + Application.ScaleY = (float)UE.Screen.height / (float)referScreenHeight * scaleFactorY; + } + defaultTexture = new UE.Texture2D(1, 1); defaultTexture.SetPixel(0, 0, UE.Color.white); defaultTexture.Apply(); @@ -61,7 +82,7 @@ private void Awake() transparentTexture = new UE.Texture2D(1, 1); transparentTexture.SetPixel(0, 0, UE.Color.clear); transparentTexture.Apply(); - + ApiHolder.Graphics = new UnityGdi(); ApiHolder.Input = new UnityInput(); ApiHolder.System = new UnitySystem(); @@ -144,10 +165,10 @@ private void Update() var ueScreenWidth = UE.Screen.width; var ueScreenHeight = UE.Screen.height; - Screen.width = (int) (ueScreenWidth / Application.ScaleX); - Screen.height = (int) (ueScreenHeight / Application.ScaleY); + Screen.width = (int) (ueScreenWidth / Application.ScaleX); + Screen.height = (int) (ueScreenHeight / Application.ScaleY); - if (controller == null) return; + if (controller == null) return; if (lastWidth != ueScreenWidth || lastHeight != ueScreenHeight) { From 9ac2c2dab99f9e202983b793eaebc210383c75d2 Mon Sep 17 00:00:00 2001 From: Shepherd Zhu Date: Sun, 27 Oct 2024 20:14:36 +0800 Subject: [PATCH 2/2] [fix] MonthCalender may fail to get CurrentCulture --- Core/API/IApiSystem.cs | 4 ++-- System/Windows/Forms/Application.cs | 8 +++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/Core/API/IApiSystem.cs b/Core/API/IApiSystem.cs index 612bc8e..ec34757 100644 --- a/Core/API/IApiSystem.cs +++ b/Core/API/IApiSystem.cs @@ -1,10 +1,10 @@ -namespace System.Drawing +namespace System.Drawing { using System.Globalization; public interface IApiSystem { - CultureInfo CurrentCulture { get; } + CultureInfo CurrentCulture { get => CultureInfo.CurrentCulture; } Point MousePosition { get; } } } diff --git a/System/Windows/Forms/Application.cs b/System/Windows/Forms/Application.cs index b544259..2d0491a 100644 --- a/System/Windows/Forms/Application.cs +++ b/System/Windows/Forms/Application.cs @@ -1,4 +1,4 @@ -namespace System.Windows.Forms +namespace System.Windows.Forms { using System.Collections.Generic; using System.Drawing; @@ -35,8 +35,10 @@ public class Application static Application() { - if (ApiHolder.System != null) - CurrentCulture = ApiHolder.System.CurrentCulture; + //if (ApiHolder.System != null) + // CurrentCulture = ApiHolder.System.CurrentCulture; + + CurrentCulture = CultureInfo.CurrentCulture; } public Application()