Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UIPanel在设置FitScreen为FitSize时产生的Game视图UI分辨率不对的BUG #243

Open
Cavy666 opened this issue Dec 17, 2024 · 0 comments

Comments

@Cavy666
Copy link

Cavy666 commented Dec 17, 2024

在UIPanel.cs中的399行和400行获取屏幕宽高的代码

int width = Screen.width;
int height = Screen.height;

在某些情况下(至少在我的两台电脑上)Screen.Width和ScreenHeight获取是设备的物理分辨率,而不是Game视图设定的分辨率(当然,游戏运行时会恢复正常,但就是每次编译脚本回来看这个界面不是我在FGUIEditor摆好的样子就属实有点难受)
可以通过修改

int width = (int) StageCamera.main.pixelWidth;
int height = (int) StageCamera.main.pixelHeight;

来修复这个bug,就是不知道在正式运行时StageCamera.main是不是会有改动导致有别的影响
如果上述有别的问题,可以用下面的方案

Rect GetRealScreen()
{
#if UNITY_EDITOR
            // 获取Game视图的实际大小
            System.Type unityEditor = System.Type.GetType("UnityEditor.GameView,UnityEditor");
            System.Reflection.MethodInfo getSizeOfMainGameView = unityEditor?.GetMethod("GetSizeOfMainGameView", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static);
            if (getSizeOfMainGameView != null)
            {
                UnityEngine.Vector2 res = (UnityEngine.Vector2) getSizeOfMainGameView.Invoke(null, null);
                return new Rect(0, 0, res.x, res.y);
            }
#endif
            return new Rect(0, 0, Screen.width, Screen.height);
 }

然后通过返回的Rect的width和height来赋值

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant