Chrome 扩展程序:Unity3D 启动器 - 从新标签页打开和运行 Unity3D 游戏
Unity3D 启动器 Chrome 扩展程序
这个 Chrome 扩展程序可以让你从一个新的标签页打开和运行 Unity3D 游戏。
插件名称: Unity3D 启动器
打开新标签页的脚本:
function openNewTab(url) {
var win = window.open(url, '_blank');
win.focus();
}
chrome.browserAction.onClicked.addListener(function(tab) {
openNewTab('chrome-extension://' + chrome.runtime.id + '/unity3d.html');
});
启动游戏的脚本:
var gameUrl = 'https://example.com/game.unity3d';
function launchUnity3D() {
var config = {
'attributes': {
'width': 800,
'height': 600
}
};
var unityObject = new UnityObject2(config);
unityObject.embedUnity('unityPlayer', gameUrl, 800, 600, function(result) {
if (!result.success) {
console.log('Failed to launch Unity3D game:', result);
}
});
}
document.addEventListener('DOMContentLoaded', function() {
launchUnity3D();
});
unity3d.html 文件:
<!DOCTYPE html>
<html>
<head>
<title>Unity3D Game</title>
<script src='https://ssl-webplayer.unity3d.com/download_webplayer-3.x/3.0/uo/UnityObject2.js'></script>
</head>
<body>
<div id='unityPlayer'></div>
<script src='unity3d.js'></script>
</body>
</html>
manifest.json 文件:
{
"manifest_version": 2,
"name": "Unity3D Launcher",
"version": "1.0",
"description": "Open and launch Unity3D games from a new tab",
"icons": {
"16": "icon16.png",
"48": "icon48.png",
"128": "icon128.png"
},
"browser_action": {
"default_icon": "icon48.png",
"default_title": "Launch Unity3D Game"
},
"permissions": [
"activeTab",
"tabs",
"https://example.com/*"
],
"background": {
"scripts": ["background.js"],
"persistent": false
}
}
使用说明:
- 将以上代码复制到相应的文件中。
- 将
gameUrl变量的值替换为你的 Unity3D 游戏的 URL。 - 将
icon16.png,icon48.png,icon128.png替换为你的图标文件。 - 使用 Chrome 扩展程序打包工具打包你的扩展程序。
- 在 Chrome 浏览器中加载你的扩展程序。
- 点击浏览器工具栏中的扩展程序图标即可打开一个新的标签页并运行你的 Unity3D 游戏。
注意:
- 确保你的 Unity3D 游戏的 URL 正确。
- Unity Web Player 需要在你的浏览器中安装才能运行 Unity3D 游戏。
- 如果你遇到问题,请查看 Unity Web Player 的文档。
祝你玩得开心!
原文地址: http://www.cveoy.top/t/topic/nnD7 著作权归作者所有。请勿转载和采集!