Skip to content
This repository was archived by the owner on Jul 22, 2024. It is now read-only.

Commit a434c9e

Browse files
committed
Updating scene
1 parent eb1265c commit a434c9e

File tree

10 files changed

+377
-2
lines changed

10 files changed

+377
-2
lines changed
-91 Bytes
Binary file not shown.
5 Bytes
Binary file not shown.
1.25 KB
Binary file not shown.

Build/Build/Build.data.unityweb

397 Bytes
Binary file not shown.
-359 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.

Build/index.html

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,23 @@
1010
<title> | Unity-WebVR-Export</title>
1111
<meta name="description" content="">
1212
<link rel="icon" href="favicon.ico">
13-
<link rel="stylesheet" type="text/css" href="webvr.css">
13+
<link rel="stylesheet" type="text/css" href="styles/webvr.css">
14+
<script src="lib/telemetry.js"></script>
15+
<script>
16+
MozillaResearch.telemetry.start({
17+
analytics: true,
18+
errorLogging: true,
19+
performance: true
20+
});
21+
MozillaResearch.telemetry.performance.mark('LoaderParsingStart');
22+
</script>
1423
<script src="Build/UnityLoader.js"></script>
1524
<script>
16-
/* global UnityLoader */
25+
/* global UnityLoader, MozillaResearch */
26+
MozillaResearch.telemetry.performance.measure('LoaderParsing', 'LoaderParsingStart');
1727
(function () {
1828
UnityLoader.SystemInfo.mobile = false; // Workaround to force `UnityLoader` to actually load on mobile.
29+
MozillaResearch.telemetry.performance.mark('LoadingStart');
1930
window.gameInstance = UnityLoader.instantiate('gameContainer', 'Build/Build.json', {
2031
Module: {
2132
// `preserveDrawingBuffer` is needed for WebVR content to be mirrored to the `<canvas>`.

Build/lib/telemetry.js

Lines changed: 204 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,204 @@
1+
/* global Raven */
2+
(function (window) {
3+
'use strict';
4+
5+
/*
6+
* The main requirements when dealing with Do-Not-Track (DNT) are:
7+
*
8+
* 1. Prevent explicit collection, storage and sending data if DNT is enabled.
9+
*
10+
* 2. GA and Telemetry APIs should not throw or error if DNT is enabled,
11+
* although they must ensure requirement #1.
12+
*
13+
* 3. If DNT is enabled in the middle of the gameplay, the API must ensure
14+
* requirements #1 and #2. If DNT is disabled in the middle of the gameplay,
15+
* resuming data collection is not mandatory.
16+
*
17+
* FOR MAINTAINERS: Some collection can happen implicitly when loading 3rd party
18+
* libraries. Try to prevent loading external libraries if DNT is enabled and
19+
* this does not conflict with requirement #2.
20+
*/
21+
22+
var CURRENT_VERSION = '1.0.2';
23+
var MOZILLA_RESEARCH_TRACKER = 'UA-77033033-6';
24+
25+
if (!('MozillaResearch' in window)) {
26+
window.MozillaResearch = {};
27+
}
28+
29+
if (!('telemetry' in window.MozillaResearch)) {
30+
window.MozillaResearch.telemetry = {};
31+
}
32+
33+
var navigator = window.navigator;
34+
var telemetry = window.MozillaResearch.telemetry;
35+
36+
var NO_OP = function () {};
37+
38+
Object.defineProperty(telemetry, '_gtag', {
39+
get: function () {
40+
return window.gtag || NO_OP;
41+
}
42+
});
43+
44+
telemetry.performance = {
45+
mark: NO_OP,
46+
measure: NO_OP
47+
};
48+
49+
telemetry.start = onlyOnce(function (config) {
50+
config = config || {};
51+
if (config.errorLogging) {
52+
setupErrorLogging();
53+
}
54+
if (config.analytics) {
55+
var researchAnalytics = startAnalytics();
56+
if (config.performance) {
57+
setupPerformanceAPI(researchAnalytics);
58+
}
59+
}
60+
});
61+
62+
setupAnalytics();
63+
64+
function setupAnalytics() {
65+
if (doNotTrack()) { return; }
66+
67+
window.dataLayer = window.dataLayer || [];
68+
window.gtag = window.gtag || function () { dataLayer.push(arguments); };
69+
window.gtag('js', new Date());
70+
71+
injectScript('https://www.googletagmanager.com/gtag/js?id=' + MOZILLA_RESEARCH_TRACKER, function (err) {
72+
if (err) {
73+
console.warn('Could not load Analytics.js script:', err);
74+
return;
75+
}
76+
});
77+
}
78+
79+
function setupErrorLogging() {
80+
if (doNotTrack()) { return; }
81+
82+
injectScript('https://cdn.ravenjs.com/3.22.3/console/raven.min.js', function (err) {
83+
if (err) {
84+
console.warn('Could not load Raven.js script:', err);
85+
return;
86+
}
87+
if (!('Raven' in window)) {
88+
console.warn('Could not find `window.Raven` global');
89+
return;
90+
}
91+
startRaven();
92+
});
93+
94+
function startRaven () {
95+
Raven.config('https://e359be9fb9324addb0dc97b664cf5ee6@sentry.io/294878')
96+
.install();
97+
}
98+
};
99+
100+
function startAnalytics() {
101+
var tracker = configureBoundTracker(MOZILLA_RESEARCH_TRACKER, {
102+
'groups': 'MozillaResearch',
103+
'custom_map': {
104+
'dimension1': 'version'
105+
}
106+
});
107+
tracker('event', 'using_webvr_template', { version: CURRENT_VERSION });
108+
return tracker;
109+
}
110+
111+
function setupPerformanceAPI(tracker) {
112+
telemetry.performance = {
113+
mark: function (name) {
114+
if (doNotTrack()) { return; }
115+
116+
performance.mark(name);
117+
},
118+
119+
measure: function (name, start, end) {
120+
if (doNotTrack()) { return; }
121+
122+
performance.measure(name, start, end);
123+
var performanceEntry = performance.getEntriesByName(name)[0];
124+
var duration = performanceEntry.duration;
125+
tracker('event', name, {
126+
'event_category': 'Performance',
127+
'value': Math.round(duration)
128+
});
129+
}
130+
};
131+
}
132+
133+
/**
134+
* The function configures Google Analytics sending a `config` command [1] but
135+
* also returns a function to use instead of `gtag` that respects `Do-Not-Track`
136+
* and it's bound to the `groups` property of the `options` parameter to avoid
137+
* adding the `send_to` key [2] to each command.
138+
*
139+
* [1] https://developers.google.com/analytics/devguides/collection/gtagjs/pages
140+
* [2] https://developers.google.com/analytics/devguides/collection/gtagjs/sending-data#groups-and-properties
141+
*
142+
* @param {string} trackingId see `'config'` command signature [1]
143+
* @param {object} options see `'config'` command signature [1]
144+
* @returns {function} A tracker function to replace invocation of `gtag` that
145+
* honours Do-Not-Track and automatically adds the `send_to` key to the
146+
* commands [2].
147+
*/
148+
function configureBoundTracker(trackingId, options) {
149+
if (doNotTrack()) { return NO_OP; }
150+
151+
options = options || {};
152+
var groups = options.groups;
153+
telemetry._gtag('config', trackingId, options);
154+
return trackingFunction;
155+
156+
function trackingFunction(command, label, options) {
157+
if (doNotTrack()) { return; }
158+
159+
options = options || {};
160+
if (groups) {
161+
options.send_to = groups;
162+
}
163+
telemetry._gtag(command, label, options);
164+
};
165+
}
166+
167+
function injectScript(src, callback) {
168+
var script = document.createElement('script');
169+
script.src = src;
170+
script.crossorigin = 'anonymous';
171+
script.addEventListener('load', function () {
172+
if (callback) {
173+
callback(null, true);
174+
}
175+
});
176+
script.addEventListener('error', function (err) {
177+
if (callback) {
178+
callback(err);
179+
}
180+
});
181+
document.head.appendChild(script);
182+
return script;
183+
}
184+
185+
// IE9/IE10 uses a prefixed version while MS Edge sets the property in
186+
// `window` instead of `navigator`:
187+
// https://developer.mozilla.org/en-US/docs/Web/API/Navigator/doNotTrack#Browser_compatibility
188+
function doNotTrack() {
189+
return navigator.doNotTrack === '1' ||
190+
navigator.msDoNotTrack === '1' ||
191+
window.doNotTrack === '1';
192+
}
193+
194+
function onlyOnce(fn) {
195+
var called = false;
196+
return function () {
197+
if (called) { return; }
198+
var returnValue = fn.apply(this, arguments);
199+
called = true;
200+
return returnValue;
201+
};
202+
}
203+
204+
})(window);

Build/styles/webvr.css

Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
html, body {
2+
font-size: 16px;
3+
overflow: hidden;
4+
/* NOTE: Don't use `-apple-system` at the head of a shorthand font declaration.
5+
See https://booking.design/implementing-system-fonts-on-booking-com-a-lesson-learned-bdc984df627f for more info. */
6+
font-family: BlinkMacSystemFont, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
7+
}
8+
9+
html, body, #canvas, #loader {
10+
height: 100%;
11+
left: 0;
12+
margin: 0;
13+
padding: 0;
14+
top: 0;
15+
width: 100%;
16+
}
17+
18+
a:link, a:visited {
19+
color: #198EFB;
20+
}
21+
22+
#loader {
23+
background: #2C3146;
24+
}
25+
26+
[data-unity-loaded='true'] #loader {
27+
display: none;
28+
}
29+
30+
#progress {
31+
bottom: 0;
32+
height: 80px;
33+
position: absolute;
34+
width: 0;
35+
}
36+
37+
.loading {
38+
align-items: center;
39+
color: #fff;
40+
display: flex;
41+
font-size: 50px;
42+
font-weight: light;
43+
height: 100%;
44+
justify-content: center;
45+
}
46+
47+
/* loading dots */
48+
.loading:after {
49+
content: ' .';
50+
animation: dots 2s steps(5, end) infinite;
51+
}
52+
53+
@keyframes dots {
54+
0%, 20% {
55+
color: rgba(0,0,0,0);
56+
text-shadow:
57+
.25em 0 0 rgba(0,0,0,0),
58+
.5em 0 0 rgba(0,0,0,0);
59+
}
60+
40% {
61+
color: #fff;
62+
text-shadow:
63+
.25em 0 0 rgba(0,0,0,0),
64+
.5em 0 0 rgba(0,0,0,0);
65+
}
66+
60% {
67+
text-shadow:
68+
.25em 0 0 #fff,
69+
.5em 0 0 rgba(0,0,0,0);
70+
}
71+
80%, 100% {
72+
text-shadow:
73+
.25em 0 0 #fff,
74+
.5em 0 0 #fff;
75+
}
76+
}
77+
78+
#canvas {
79+
display: block;
80+
position: absolute;
81+
z-index: 0;
82+
}
83+
84+
#vr {
85+
position: absolute;
86+
display: flex;
87+
right: 30px;
88+
bottom: 30px;
89+
}
90+
91+
#status {
92+
display: none;
93+
background: #fff;
94+
margin-right: 15px;
95+
padding: 10px;
96+
}
97+
98+
[data-unity-loaded='true'] #status[data-enabled='true'] {
99+
display: block;
100+
}
101+
102+
#vr button {
103+
border: none;
104+
}
105+
106+
#entervr {
107+
background: #fff url(../vr.png) center no-repeat;
108+
background-size: 80%;
109+
cursor: pointer;
110+
display: none;
111+
height: 100px;
112+
width: 100px;
113+
}
114+
115+
[data-unity-loaded='true'] #entervr[data-enabled='true'] {
116+
display: block;
117+
}
118+
119+
#progress,
120+
#entervr:hover,
121+
#instruction button {
122+
background-color: #198EFB;
123+
}
124+
125+
#instruction {
126+
align-items: center;
127+
display: flex;
128+
height: 100%;
129+
justify-content: center;
130+
position: absolute;
131+
top: 0;
132+
width: 100%;
133+
}
134+
135+
#instruction button {
136+
color: #fff;
137+
cursor: pointer;
138+
font-size: 25px;
139+
padding: 15px 20px;
140+
}
141+
142+
#icons {
143+
display: flex;
144+
}
145+
146+
.panel {
147+
background: #fff;
148+
display: none;
149+
max-width: 50%;
150+
padding: 10px 30px;
151+
}
152+
153+
.panel[data-enabled='true'] {
154+
display: block;
155+
}
156+
157+
.center {
158+
text-align: center;
159+
}

Build/webvr.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
}
3838

3939
function onUnityLoaded () {
40+
MozillaResearch.telemetry.performance.measure('LoadingTime', 'LoadingStart');
4041
canvas = document.getElementById('#canvas');
4142
document.body.dataset.unityLoaded = 'true';
4243
onResize();

0 commit comments

Comments
 (0)