Skip to content

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

Description

@Cavy666

在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来赋值

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions