fix:1、添加跳链接的webview的插件。2、修复bug
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d9e103622e8c14154a1cd918fb92795e
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,108 @@
|
||||
<!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 | {{{ PRODUCT_NAME }}}</title>
|
||||
<link rel="shortcut icon" href="TemplateData/favicon.ico">
|
||||
<link rel="stylesheet" href="TemplateData/style.css">
|
||||
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
|
||||
<script src="unity-webview.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div id="unity-container" class="unity-desktop">
|
||||
<canvas id="unity-canvas"></canvas>
|
||||
<div id="unity-loading-bar">
|
||||
<div id="unity-logo"></div>
|
||||
<div id="unity-progress-bar-empty">
|
||||
<div id="unity-progress-bar-full"></div>
|
||||
</div>
|
||||
</div>
|
||||
<div id="unity-footer">
|
||||
<div id="unity-webgl-logo"></div>
|
||||
<div id="unity-fullscreen-button"></div>
|
||||
<div id="unity-build-title">{{{ PRODUCT_NAME }}}</div>
|
||||
</div>
|
||||
</div>
|
||||
<script>
|
||||
var buildUrl = "Build";
|
||||
var loaderUrl = buildUrl + "/{{{ LOADER_FILENAME }}}";
|
||||
var config = {
|
||||
dataUrl: buildUrl + "/{{{ DATA_FILENAME }}}",
|
||||
frameworkUrl: buildUrl + "/{{{ FRAMEWORK_FILENAME }}}",
|
||||
codeUrl: buildUrl + "/{{{ CODE_FILENAME }}}",
|
||||
#if MEMORY_FILENAME
|
||||
memoryUrl: buildUrl + "/{{{ MEMORY_FILENAME }}}",
|
||||
#endif
|
||||
#if SYMBOLS_FILENAME
|
||||
symbolsUrl: buildUrl + "/{{{ SYMBOLS_FILENAME }}}",
|
||||
#endif
|
||||
streamingAssetsUrl: "StreamingAssets",
|
||||
companyName: "{{{ COMPANY_NAME }}}",
|
||||
productName: "{{{ PRODUCT_NAME }}}",
|
||||
productVersion: "{{{ PRODUCT_VERSION }}}",
|
||||
};
|
||||
|
||||
var container = document.querySelector("#unity-container");
|
||||
var canvas = document.querySelector("#unity-canvas");
|
||||
var loadingBar = document.querySelector("#unity-loading-bar");
|
||||
var progressBarFull = document.querySelector("#unity-progress-bar-full");
|
||||
var fullscreenButton = document.querySelector("#unity-fullscreen-button");
|
||||
var width0 = "{{{ WIDTH }}}px";
|
||||
var height0 = "{{{ HEIGHT }}}px";
|
||||
|
||||
if (/iPhone|iPad|iPod|Android/i.test(navigator.userAgent)) {
|
||||
container.className = "unity-mobile";
|
||||
config.devicePixelRatio = 1;
|
||||
} else {
|
||||
canvas.style.width = "{{{ WIDTH }}}px";
|
||||
canvas.style.height = "{{{ HEIGHT }}}px";
|
||||
}
|
||||
#if BACKGROUND_FILENAME
|
||||
canvas.style.background = "url('" + buildUrl + "/{{{ BACKGROUND_FILENAME.replace(/'/g, '%27') }}}') center / cover";
|
||||
#endif
|
||||
loadingBar.style.display = "block";
|
||||
|
||||
document.addEventListener(
|
||||
'fullscreenchange',
|
||||
function() {
|
||||
var p = document.getElementById('unity-container');
|
||||
var c = document.getElementById('unity-canvas');
|
||||
if (document.fullscreenElement) {
|
||||
width0 = c.style.width;
|
||||
height0 = c.style.height;
|
||||
setTimeout(
|
||||
function() {
|
||||
c.style.width = getComputedStyle(p).width;
|
||||
c.style.height = getComputedStyle(p).height;
|
||||
},
|
||||
250);
|
||||
} else {
|
||||
c.style.width = width0;
|
||||
c.style.height = height0;
|
||||
}
|
||||
});
|
||||
var script = document.createElement("script");
|
||||
script.src = loaderUrl;
|
||||
script.onload = () => {
|
||||
createUnityInstance(canvas, config, (progress) => {
|
||||
progressBarFull.style.width = 100 * progress + "%";
|
||||
}).then((unityInstance) => {
|
||||
window.unityInstance = unityInstance;
|
||||
loadingBar.style.display = "none";
|
||||
fullscreenButton.onclick = () => {
|
||||
var p = document.getElementById('unity-container');
|
||||
var c = document.getElementById('unity-canvas');
|
||||
c.requestFullscreen = () => {
|
||||
p.requestFullscreen();
|
||||
};
|
||||
unityInstance.SetFullscreen(1);
|
||||
};
|
||||
}).catch((message) => {
|
||||
alert(message);
|
||||
});
|
||||
};
|
||||
document.body.appendChild(script);
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7be04fa587d934a5c958c8fc02a10c40
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,103 @@
|
||||
var unityWebView =
|
||||
{
|
||||
loaded: [],
|
||||
|
||||
init : function (name) {
|
||||
$containers = $('.webviewContainer');
|
||||
if ($containers.length === 0) {
|
||||
$('<div style="position: absolute; left: 0px; width: 100%; height: 100%; top: 0px; pointer-events: none;"><div class="webviewContainer" style="overflow: hidden; position: relative; width: 100%; height: 100%; z-index: 1;"></div></div>')
|
||||
.appendTo($('#unity-container'));
|
||||
}
|
||||
var $last = $('.webviewContainer:last');
|
||||
var clonedTop = parseInt($last.css('top')) - 100;
|
||||
var $clone = $last.clone().insertAfter($last).css('top', clonedTop + '%');
|
||||
var $iframe =
|
||||
$('<iframe style="position:relative; width:100%; height100%; border-style:none; display:none; pointer-events:auto;"></iframe>')
|
||||
.attr('id', 'webview_' + name)
|
||||
.appendTo($last)
|
||||
.on('load', function () {
|
||||
$(this).attr('loaded', 'true');
|
||||
var contents = $(this).contents();
|
||||
var w = $(this)[0].contentWindow;
|
||||
contents.find('a').click(function (e) {
|
||||
var href = $.trim($(this).attr('href'));
|
||||
if (href.substr(0, 6) === 'unity:') {
|
||||
unityInstance.SendMessage(name, "CallFromJS", href.substring(6, href.length));
|
||||
e.preventDefault();
|
||||
}
|
||||
});
|
||||
|
||||
contents.find('form').submit(function () {
|
||||
$this = $(this);
|
||||
var action = $.trim($this.attr('action'));
|
||||
if (action.substr(0, 6) === 'unity:') {
|
||||
var message = action.substring(6, action.length);
|
||||
if ($this.attr('method').toLowerCase() == 'get') {
|
||||
message += '?' + $this.serialize();
|
||||
}
|
||||
unityInstance.SendMessage(name, "CallFromJS", message);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
|
||||
unityInstance.SendMessage(name, "CallOnLoaded", location.href);
|
||||
});
|
||||
},
|
||||
|
||||
sendMessage: function (name, message) {
|
||||
unityInstance.SendMessage(name, "CallFromJS", message);
|
||||
},
|
||||
|
||||
setMargins: function (name, left, top, right, bottom) {
|
||||
var container = $('#unity-container');
|
||||
var r = (container.hasClass('unity-desktop')) ? window.devicePixelRatio : 1;
|
||||
var w0 = container.width() * r;
|
||||
var h0 = container.height() * r;
|
||||
var canvas = $('#unity-canvas');
|
||||
var w1 = canvas.attr('width');
|
||||
var h1 = canvas.attr('height');
|
||||
|
||||
var lp = left / w0 * 100;
|
||||
var tp = top / h0 * 100;
|
||||
var wp = (w1 - left - right) / w0 * 100;
|
||||
var hp = (h1 - top - bottom) / h0 * 100;
|
||||
|
||||
this.iframe(name)
|
||||
.css('left', lp + '%')
|
||||
.css('top', tp + '%')
|
||||
.css('width', wp + '%')
|
||||
.css('height', hp + '%');
|
||||
},
|
||||
|
||||
setVisibility: function (name, visible) {
|
||||
if (visible)
|
||||
this.iframe(name).show();
|
||||
else
|
||||
this.iframe(name).hide();
|
||||
},
|
||||
|
||||
loadURL: function(name, url) {
|
||||
this.iframe(name).attr('loaded', 'false')[0].contentWindow.location.replace(url);
|
||||
},
|
||||
|
||||
evaluateJS: function (name, js) {
|
||||
$iframe = this.iframe(name);
|
||||
if ($iframe.attr('loaded') === 'true') {
|
||||
$iframe[0].contentWindow.eval(js);
|
||||
} else {
|
||||
$iframe.on('load', function(){
|
||||
$(this)[0].contentWindow.eval(js);
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
destroy: function (name) {
|
||||
this.iframe(name).parent().parent().remove();
|
||||
},
|
||||
|
||||
iframe: function (name) {
|
||||
return $('#webview_' + name);
|
||||
},
|
||||
|
||||
};
|
||||
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5b98600d622f440fab913c56685e11bf
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 74f24ca1a6cc14b5c8da7e2a8e5de817
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,32 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
||||
<title>Unity Web Player</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 src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
|
||||
|
||||
<script>
|
||||
var unityInstance = UnityLoader.instantiate("gameContainer", "%UNITY_WEBGL_BUILD_URL%", {onProgress: UnityProgress});
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<div class="content">
|
||||
<div class="webgl-content" id="unityPlayer">
|
||||
<div id="gameContainer" style="width: 960px; height: 600px"></div>
|
||||
<div class="footer">
|
||||
<div class="webgl-logo"></div>
|
||||
<div class="fullscreen" onclick="document.getElementById('gameContainer').requestFullscreen()"></div>
|
||||
<div class="title">Title</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- unity_webview -->
|
||||
<script type="text/javascript" src="unity-webview.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cd45543727a7e47d88051ca9ab86a6f5
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,100 @@
|
||||
var unityWebView =
|
||||
{
|
||||
loaded: [],
|
||||
|
||||
init : function (name) {
|
||||
$containers = $('.webviewContainer');
|
||||
if ($containers.length === 0) {
|
||||
$('<div style="position: absolute; left: 0px; width: 100%; height: 100%; top: 0px; pointer-events: none;"><div class="webviewContainer" style="overflow: hidden; position: relative; width: 100%; height: 100%; z-index: 1;"></div></div>')
|
||||
.appendTo($('#gameContainer'));
|
||||
}
|
||||
var $last = $('.webviewContainer:last');
|
||||
var clonedTop = parseInt($last.css('top')) - 100;
|
||||
var $clone = $last.clone().insertAfter($last).css('top', clonedTop + '%');
|
||||
var $iframe =
|
||||
$('<iframe style="position:relative; width:100%; height100%; border-style:none; display:none; pointer-events:auto;"></iframe>')
|
||||
.attr('id', 'webview_' + name)
|
||||
.appendTo($last)
|
||||
.on('load', function () {
|
||||
$(this).attr('loaded', 'true');
|
||||
var contents = $(this).contents();
|
||||
var w = $(this)[0].contentWindow;
|
||||
contents.find('a').click(function (e) {
|
||||
var href = $.trim($(this).attr('href'));
|
||||
if (href.substr(0, 6) === 'unity:') {
|
||||
unityInstance.SendMessage(name, "CallFromJS", href.substring(6, href.length));
|
||||
e.preventDefault();
|
||||
}
|
||||
});
|
||||
|
||||
contents.find('form').submit(function () {
|
||||
$this = $(this);
|
||||
var action = $.trim($this.attr('action'));
|
||||
if (action.substr(0, 6) === 'unity:') {
|
||||
var message = action.substring(6, action.length);
|
||||
if ($this.attr('method').toLowerCase() == 'get') {
|
||||
message += '?' + $this.serialize();
|
||||
}
|
||||
unityInstance.SendMessage(name, "CallFromJS", message);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
|
||||
unityInstance.SendMessage(name, "CallOnLoaded", location.href);
|
||||
});
|
||||
},
|
||||
|
||||
sendMessage: function (name, message) {
|
||||
unityInstance.SendMessage(name, "CallFromJS", message);
|
||||
},
|
||||
|
||||
setMargins: function (name, left, top, right, bottom) {
|
||||
var container = $('#gameContainer');
|
||||
var r = window.devicePixelRatio;
|
||||
var w0 = container.width() * r;
|
||||
var h0 = container.height() * r;
|
||||
|
||||
var lp = left / w0 * 100;
|
||||
var tp = top / h0 * 100;
|
||||
var wp = (w0 - left - right) / w0 * 100;
|
||||
var hp = (h0 - top - bottom) / h0 * 100;
|
||||
|
||||
this.iframe(name)
|
||||
.css('left', lp + '%')
|
||||
.css('top', tp + '%')
|
||||
.css('width', wp + '%')
|
||||
.css('height', hp + '%');
|
||||
},
|
||||
|
||||
setVisibility: function (name, visible) {
|
||||
if (visible)
|
||||
this.iframe(name).show();
|
||||
else
|
||||
this.iframe(name).hide();
|
||||
},
|
||||
|
||||
loadURL: function(name, url) {
|
||||
this.iframe(name).attr('loaded', 'false')[0].contentWindow.location.replace(url);
|
||||
},
|
||||
|
||||
evaluateJS: function (name, js) {
|
||||
$iframe = this.iframe(name);
|
||||
if ($iframe.attr('loaded') === 'true') {
|
||||
$iframe[0].contentWindow.eval(js);
|
||||
} else {
|
||||
$iframe.on('load', function(){
|
||||
$(this)[0].contentWindow.eval(js);
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
destroy: function (name) {
|
||||
this.iframe(name).parent().parent().remove();
|
||||
},
|
||||
|
||||
iframe: function (name) {
|
||||
return $('#webview_' + name);
|
||||
},
|
||||
|
||||
};
|
||||
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8de1ecd3ea5954800b53548d8c2e2d70
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user