首页 > 解决方案 > 如何在 itch.io 上增加 Unity WebGL 游戏窗口的大小?

问题描述

我刚刚将我的第一个 Unity WebGL 构建上传到 itch.io,但窗口非常小,所以你只能看到实际游戏视图中心的一小部分

有问题的游戏,以及 exe 下载和公共回购:https ://lower-third.itch.io/blackbox

在此处输入图像描述

HTML:

<!DOCTYPE html>
<html lang="en-us">
<head>
    <meta charset="utf-8">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>Unity WebGL Player | BlackBox</title>
    <link rel="shortcut icon" href="TemplateData/favicon.ico">
    <link rel="stylesheet" href="TemplateData/style.css">
    <script src="TemplateData/UnityProgress.js"></script>
    <script src="Build/UnityLoader.js"></script>
    <script>
        var unityInstance = UnityLoader.instantiate("unityContainer", "Build/WebGL.json", { onProgress: UnityProgress });
    </script>
</head>
<body>
    <div class="webgl-content">
        <div id="unityContainer" style="width: 1920px; height: 1080px"></div>
        <div class="footer">
            <div class="webgl-logo"></div>
            <div class="fullscreen" onclick="unityInstance.SetFullscreen(1)"></div>
            <div class="title">BlackBox</div>
        </div>
    </div>
</body>
</html>

CSS:

.webgl-content * {border: 0; margin: 0; padding: 0}
.webgl-content {position: absolute; top: 50%; left: 50%; -webkit-transform: translate(-50%, -50%); transform: translate(-50%, -50%);}

.webgl-content .logo, .progress {position: absolute; left: 50%; top: 50%; -webkit-transform: translate(-50%, -50%); transform: translate(-50%, -50%);}
.webgl-content .logo {background: url('progressLogo.Light.png') no-repeat center / contain; width: 154px; height: 130px;}
.webgl-content .progress {height: 18px; width: 141px; margin-top: 90px;}
.webgl-content .progress .empty {background: url('progressEmpty.Light.png') no-repeat right / cover; float: right; width: 100%; height: 100%; display: inline-block;}
.webgl-content .progress .full {background: url('progressFull.Light.png') no-repeat left / cover; float: left; width: 0%; height: 100%; display: inline-block;}

.webgl-content .logo.Dark {background-image: url('progressLogo.Dark.png');}
.webgl-content .progress.Dark .empty {background-image: url('progressEmpty.Dark.png');}
.webgl-content .progress.Dark .full {background-image: url('progressFull.Dark.png');}

.webgl-content .footer {margin-top: 5px; height: 38px; line-height: 38px; font-family: Helvetica, Verdana, Arial, sans-serif; font-size: 18px;}
.webgl-content .footer .webgl-logo, .title, .fullscreen {height: 100%; display: inline-block; background: transparent center no-repeat;}
.webgl-content .footer .webgl-logo {background-image: url('webgl-logo.png'); width: 204px; float: left;}
.webgl-content .footer .title {margin-right: 10px; float: right;}
.webgl-content .footer .fullscreen {background-image: url('fullscreen.png'); width: 38px; float: right;}

就像我说的,这是我第一次尝试使用这些东西,所以我不知道要更改什么 div 以及要应用什么 css,并且还没有在网上找到任何足够的答案。我所做的只是将 index.html 文件中 unityContainer 的样式更改为 1920x1080。这只是让我的游戏以更大的分辨率渲染,而不会改变游戏视图的大小,使视图更加无用。其他一切都与 Unity 为构建生成的一样。

作为参考,我在这个项目中使用了 URP 和 Unity 2019.3.0f6,但我怀疑这与我的问题有什么关系。游戏在我的浏览器中运行良好。我只是想让窗口尽可能大,并确保它显示整个游戏。

标签: htmlcssunity3dunity-webgl

解决方案


如果您在 itch.io 游戏仪表板中使用默认的 WebGL 构建设置,那么就会发现有一个自动检测选项。

解决方案


推荐阅读