add
This commit is contained in:
32
Assets/WebGLTemplates/unity-webview/index.html
Normal file
32
Assets/WebGLTemplates/unity-webview/index.html
Normal file
@@ -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>
|
||||
7
Assets/WebGLTemplates/unity-webview/index.html.meta
Normal file
7
Assets/WebGLTemplates/unity-webview/index.html.meta
Normal file
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 94ef8924433cd442c9e14cd3b152a9e9
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
99
Assets/WebGLTemplates/unity-webview/unity-webview.js
Normal file
99
Assets/WebGLTemplates/unity-webview/unity-webview.js
Normal file
@@ -0,0 +1,99 @@
|
||||
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();
|
||||
} else {
|
||||
w.location.replace(href);
|
||||
}
|
||||
});
|
||||
|
||||
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;
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
sendMessage: function (name, message) {
|
||||
unityInstance.SendMessage(name, "CallFromJS", message);
|
||||
},
|
||||
|
||||
setMargins: function (name, left, top, right, bottom) {
|
||||
var container = $('#gameContainer');
|
||||
var width = container.width();
|
||||
var height = container.height();
|
||||
|
||||
var lp = left / width * 100;
|
||||
var tp = top / height * 100;
|
||||
var wp = (width - left - right) / width * 100;
|
||||
var hp = (height - top - bottom) / height * 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: c760bad0efd5e4d2093996b01d1755a6
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user