尝试打开本地 Unity WebGL 构建时,多个浏览器(Chrome、Firefox、Internet Explorer)会出现以下错误:
您的浏览器似乎不支持从 file:// url 运行 Unity WebGL 内容。请将其上传到 http 服务器,或尝试其他浏览器。
Microsoft Edge 能够运行它,但我想知道是否可以更改任何设置以使其在 Chrome/Firefox/其他浏览器上运行。
我有一个非常基本的Unity应用程序,它本质上是专有框架的测试工具.它在Chrome,Firefox和Safari中运行良好.Edge是一个不同的故事.
在Edge 12中,禁用asm.js,加载需要很长时间 - 大约90秒,而其他浏览器则需要15-20秒.
在启用了asm.js的Edge 12或13中,它会快速加载,但会在Unity应用程序启动时立即崩溃选项卡.我已经能够找出"preRun"回调被调用,但"postRun"回调没有.
我无法弄清楚如何开始调试 - 如果Dev Tools调试器打开,Edge会禁用asm.js,并且分离调试器也会禁用JS控制台.我无法附加Unity调试器,因为崩溃似乎发生在我到达那一点之前.
是否有来自Edge的某种日志,我可以找到有关崩溃的任何内容,甚至可能是JS堆栈跟踪?
我用webgl编写了简单的本机应用程序.我使用了https://github.com/JilvanPinheiro/reactive-native-unity-webgl
import Unity from 'react-native-unity-webgl';
...
render() {
return (
<Unity
width="500px"
height="350px"
onProgress={ this.onProgress }
src="http://192.168.1.101/Build/Ultimatum.json"
loader="http://192.168.1.101/Build/UnityLoader.js" />`
);
}
Run Code Online (Sandbox Code Playgroud)
但我有以下错误
ReferenceError: Can't find variable: document. This error is located at:
in Unity (at App.js:9)
in RCTView (at View.js:60)
in View (at App.js:8)
in App (at registerRootComponent.js:35)
in RootErrorBoundary (at registerRootComponent.js:34)
in ExpoRootComponent (at renderApplication.js:33)
in RCTView (at View.js:60)
in View (at AppContainer.js:102)
in RCTView (at View.js:60)
in View (at AppContainer.js:122)
in AppContainer (at renderApplication.js:32)
Run Code Online (Sandbox Code Playgroud)
有没有简单的方法将统一webgl放在我的反应原生中?
我正在统一webgl中使用以下功能加载和缓存资产捆绑包:
IEnumerator DownloadAndCacheAB(string assetName)
{
// Wait for the Caching system to be ready
while (!Caching.ready)
yield return null;
// Load the AssetBundle file from Cache if it exists with the same version or download and store it in the cache
using (WWW www = WWW.LoadFromCacheOrDownload(finalUrl, 1))
{
yield return www;
if (www.error != null)
{
Debug.Log("WWW download had an error:" + www.error);
}
AssetBundle bundle = www.assetBundle;
if (assetName == "")
{
GameObject abObject = …Run Code Online (Sandbox Code Playgroud) garbage-collection unity-game-engine assetbundle unity-webgl
当我尝试在本地服务器 IIS 或 Tomcat 上使用 WebGL 构建运行我的 Unity 项目时,它会像这样卡住:
(加载页面打开成功,但进度条不动)

我已经添加了IIS的配置文件,浏览器(火狐和Chrome)打开index.php没有报错。在浏览器中打开的加载页面似乎是相同的,有没有 localhost Web 服务器。
在某些情况下,加载可以成功:
1.在Unity Engine中直接选择“Build and Run”,网页就可以成功运行游戏了。
2.一旦构建过程失败并出现错误(无法删除文件)。我在项目根目录的Temp文件夹中尝试了半成品的搭建项目,成功了。但是后来我将该文件夹复制到另一个地方,它再次卡在加载页面上。
Unity 版本是 2020。
我该如何解决问题?
如何将我在 WebGL 中构建的 Unity 游戏放入 Laravel?
仅供参考,Unity WebGL,在构建时给了我这些文件:- Build(文件夹)- TemplateData(文件夹)- index.html
让我说一下我做了什么:
[我如何使用 XAMPP 测试游戏是否在 WebGL 中运行]
现在我想要的是,如何使用 Laravel 框架托管的服务器来测试游戏是否工作......
[ 我做了什么 ]
有任何想法吗?或者,如果您可以指导我学习如何将您的 Unity WebGL 游戏放入 Laravel 的教程,那就太好了。由于我试图搜索它,到目前为止我发现没有人将 Unity 放在他们的 Laravel 网站上。
--- 编辑:这是由 Unity WebGL 生成的 index.html 文件 …
我有一个嵌入rails静态页面的WEBGL播放器,如'demo_path',如下所示:
<% provide(:title, 'Sign up') %>
<h1>Sign up</h1>
<div class="row">
<div class="col-md-6 col-md-offset-3">
<%= form_for(@user, url: signup_path) do |f| %>
<%= render 'shared/error_messages' %>
<%= link_to "mindpass", demo_path, class: "btn btn-lg btn-primary"
%>
<%= f.submit "Create my account", class: "btn btn-primary" %>
<% end %>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
当用户单击该按钮时,它会加载webgl模板:
<!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 | MindPass_DEMO</title>
<script src="Build/UnityLoader.js"></script>
<script>
var gameInstance = UnityLoader.instantiate("gameContainer",
"/assets/Build/MindPass_WEBGL_RY2.json");
</script>
</head>
<body>
<div id="gameContainer" style="width: 90%; …Run Code Online (Sandbox Code Playgroud) 作为我们实习的一部分,我们的任务是使用Unity WebGL创建业务应用程序.在阅读了JS和C#代码之间的交互之后,我们就在一个角落里.
我们试图从C#中取回一个列表来填充我们网页上的选择,我们只是不知道该怎么做.我们遵循了Unity文档,可以轻松地与我们的网页上的C#进行通信并获取数据.
但是,我们无法在浏览器中访问C#数据.SendMessage()方法不允许返回.
到目前为止,这是我们的代码
的index.html
<select id="wallsSelect"></select>
Run Code Online (Sandbox Code Playgroud)
jsfile
function getWallsList() {
//function is called at the creation of our object
var wallsSelect = document.getElementById("wallsSelect");
index = 0;
var wallsList = gameInstance.SendMessage('WallCreator', 'GetGameObjects'); //would like to get back our list of walls and populate our Select with it
for (item in wallsList) {
var newOption = document.createElement("option");
newOption.value = index;
newOption.innerHTML = item;
wallsSelect.appendChild(newOption);
index++;
}
Run Code Online (Sandbox Code Playgroud)
最后是C#代码
public List<string> GetGameObjects()
{
List<string> goNames = new List<string>();
foreach (var item in …Run Code Online (Sandbox Code Playgroud) 我正在将 Unity 中构建的 WebGL 游戏嵌入到 Flask 中构建的 Web 应用程序中。我在后端使用 CSP 来实现安全目的,但即使wasm-eval在我的 CSP 中包含该指令后,我仍然仅在 Chrome 中收到这些错误:
UnityLoader.js:4 failed to asynchronously prepare wasm: CompileError: WebAssembly.instantiate(): Wasm code generation disallowed by embedder
printErr @ UnityLoader.js:4
UnityLoader.js:4 CompileError: WebAssembly.instantiate(): Wasm code generation disallowed by embedder
at blob:http://localhost:5000/510c750f-1181-4d80-926f-dc71e527c16b:8:31195
Uncaught (in promise) abort({}) at Error
at jsStackTrace (blob:http://localhost:5000/cd04e961-d5f5-490c-8869-fbc73dd40aa4:8:22295)
at Object.stackTrace (blob:http://localhost:5000/cd04e961-d5f5-490c-8869-fbc73dd40aa4:8:22466)
at Object.onAbort (http://localhost:5000/static/desert_run/Build/UnityLoader.js:4:11118)
at abort (blob:http://localhost:5000/cd04e961-d5f5-490c-8869-fbc73dd40aa4:8:446869)
at blob:http://localhost:5000/cd04e961-d5f5-490c-8869-fbc73dd40aa4:8:31316
Run Code Online (Sandbox Code Playgroud)
我不确定我需要修复什么,并且该unsafe-eval指令script-src也不起作用。这是我的 CSP 以及我在 _ init _.py 中使用的在后端实现它的代码:
from flask import …Run Code Online (Sandbox Code Playgroud) python google-chrome flask content-security-policy unity-webgl
一般来说,使用 Unity WebGL 构建时,默认模板如下所示
从文档中,我们可以看到,当我们想要在 Unity 中使用 WebGL 模板时,我们必须在 Assets 中创建一个名为WebGLTemplates的文件夹,以及一个名为 New Template(或任何您想要的名称)的文件夹,并在其中添加一个index.html。
另外,index.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 | %UNITY_WEB_NAME%</title>
<script src="%UNITY_WEBGL_LOADER_URL%"></script>
<script>
var unityInstance = UnityLoader.instantiate("unityContainer", "%UNITY_WEBGL_BUILD_URL%");
</script>
</head>
<body>
<div id="unityContainer" style="width: %UNITY_WIDTH%px; height: %UNITY_HEIGHT%px; margin: auto"></div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
然后,在播放器设置下,选择该模板
问题是,这并没有增加到全尺寸的选项。
unity-webgl ×10
asm.js ×1
assetbundle ×1
c# ×1
css ×1
flask ×1
html ×1
iframe ×1
javascript ×1
laravel ×1
php ×1
python ×1
react-native ×1
reactjs ×1
web ×1