简体   繁体   English

如何填充屏幕上的空白区域?

[英]How do I fill white space on screen web gl unity?

whitespace image 空白图像

空白图像

hardcoded image 硬编码的图像

硬编码的图像

so this game we are making i want the game screen to fill up the white space (i think this is called making it the native resolution ?). 所以这个游戏我们正在制作我希望游戏画面填满白色空间(我认为这被称为使其成为原生分辨率 ?)。

the coder says "the container is just hardcoded to a certain size" and he doesn't know how to make it fill up the screen pefectly consistently for all computers for example if computers have different resolutions. 编码器说“容器只是硬编码到一定大小”,并且他不知道如何使所有计算机完全一致地填满屏幕,例如,如果计算机具有不同的分辨率。

the game is being made in unity and the guy said its in web gl. 游戏是统一制作的,那家伙在网络上说它。

sorry and thank you, new to this site. 对不起,谢谢你,这个网站的新手。

You need to make your own template by changing the HTML as documented here . 您需要通过更改此处记录的HTML来创建自己的模板。 You can choose either one of the defaults or create your own template. 您可以选择其中一个默认值或创建自己的模板。

According to those docs you create folder in Assets called WebGLTemplates and inside that create a new folder for your template like BetterTemplate . 根据这些文档,您在Assets创建名为WebGLTemplates文件夹,并在其中为您的模板创建一个新文件夹,如BetterTemplate Inside that put an index.html file and any other images, css, JavaScript files you want included with your game. 在里面放置一个index.html文件和你想要包含在游戏中的任何其他图像,CSS,JavaScript文件。

The index.html could look something like this index.html可能看起来像这样

<!DOCTYPE html>
<html lang="en-us">

  <head>
    <meta charset="utf-8">
    <title>%UNITY_WEB_NAME%</title>
    <style>
      body { margin: 0; }
      #gameContainer { width: 100vw; height: 100vh; }
      canvas { width: 100%; height: 100%; }
    </style>
    <script src="Build/UnityLoader.js"></script>
    <script>
    var gameInstance = UnityLoader.instantiate("gameContainer", "Build/dist.json");
    </script>
  </head>

  <body>
    <div id="gameContainer"></div>
  </body>

</html>

Then you pick Edit->Project Settings->Player from the menus and under the WebGL tab choose your template 然后从菜单中选择Edit-> Project Settings-> Player,在WebGL选项卡下选择您的模板

Here's an example that fills the window . 这是填充窗口的示例

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM