-
Notifications
You must be signed in to change notification settings - Fork 82
/
unity.js
32 lines (26 loc) · 912 Bytes
/
unity.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
function UnityWebMediator() {
this.android = navigator.userAgent.match(/Android/);
this.ios = navigator.userAgent.match(/iPhone/) || navigator.userAgent.match(/iPod/) || navigator.userAgent.match(/iPad/);
this.messageQueue = Array();
this.callback = function(path, args) {
var message = path;
if (args) {
var stack = [];
for (var key in args) {
stack.push(key + "=" + encodeURIComponent(args[key]));
}
message += "?" + stack.join("&");
}
if (this.android) {
UnityInterface.pushMessage(message);
} else if (this.ios) {
this.messageQueue.push(message);
} else {
console.log(message);
}
};
this.pollMessage = function() {
return this.messageQueue.shift();
}
unityWebMediatorInstance = this;
}