com.typhoon.unitysdk 1.1.25 → 1.1.27
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/Editor/ApplyTool.cs +36 -0
- package/Editor/Templates/yandex_games_html_landscape_template.txt +328 -0
- package/Editor/Templates/yandex_games_html_landscape_template.txt.meta +7 -0
- package/Editor/Templates/yandex_games_html_portrait_template.txt +330 -0
- package/Editor/Templates/yandex_games_html_portrait_template.txt.meta +7 -0
- package/Editor/{TempPublish.meta → Templates.meta} +8 -8
- package/Editor/UniEditor.cs +12 -0
- package/Editor/YandexGamesConfig.cs +64 -2
- package/Runtime/LabelOverride.cs +1 -1
- package/Runtime/YandexGamesLifecycle.cs +3 -0
- package/Sources~/Package/YandexGames.unitypackage +0 -0
- package/Sources~/Package/YandexGames.unitypackage.manifest +2 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/Editor/ApplyTool.cs
CHANGED
|
@@ -925,6 +925,42 @@ namespace TyphoonUnitySDK
|
|
|
925
925
|
}
|
|
926
926
|
|
|
927
927
|
ReimportScript(manifest);
|
|
928
|
+
//同步参数到PlayerSettings
|
|
929
|
+
var config = YandexGamesConfig.Default;
|
|
930
|
+
if (!string.IsNullOrEmpty(config.ProductName))
|
|
931
|
+
{
|
|
932
|
+
PlayerSettings.productName = config.ProductName;
|
|
933
|
+
}
|
|
934
|
+
|
|
935
|
+
if (!string.IsNullOrEmpty(config.CompanyName))
|
|
936
|
+
{
|
|
937
|
+
PlayerSettings.companyName = config.CompanyName;
|
|
938
|
+
}
|
|
939
|
+
|
|
940
|
+
PlayerSettings.SetIconsForTargetGroup(
|
|
941
|
+
BuildTargetGroup.Unknown, // 👈 关键
|
|
942
|
+
new[] { config.ProductIcon }
|
|
943
|
+
);
|
|
944
|
+
|
|
945
|
+
//修改模板横竖屏
|
|
946
|
+
var html = "Assets/WebGLTemplates/YandexGames/index.html";
|
|
947
|
+
switch (config.Orientation)
|
|
948
|
+
{
|
|
949
|
+
case YandexGamesConfig.ScreenOrientation.Portrait:
|
|
950
|
+
{
|
|
951
|
+
var template =
|
|
952
|
+
$"{UniEditor.PathRoot}/Editor/Templates/yandex_games_html_portrait_template.txt";
|
|
953
|
+
File.Copy(template, html, true);
|
|
954
|
+
}
|
|
955
|
+
break;
|
|
956
|
+
case YandexGamesConfig.ScreenOrientation.Landscape:
|
|
957
|
+
{
|
|
958
|
+
var template =
|
|
959
|
+
$"{UniEditor.PathRoot}/Editor/Templates/yandex_games_html_landscape_template.txt";
|
|
960
|
+
File.Copy(template, html, true);
|
|
961
|
+
}
|
|
962
|
+
break;
|
|
963
|
+
}
|
|
928
964
|
AssetDatabase.Refresh();
|
|
929
965
|
EditorUtility.SetDirty(AppConfigAsset.Instance);
|
|
930
966
|
AssetDatabase.SaveAssets();
|
|
@@ -0,0 +1,328 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en-us">
|
|
3
|
+
|
|
4
|
+
<head>
|
|
5
|
+
<meta charset="utf-8">
|
|
6
|
+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
|
7
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
|
|
8
|
+
<link rel="stylesheet" href="./style.css">
|
|
9
|
+
|
|
10
|
+
<!-- Yandex Games SDK -->
|
|
11
|
+
<script src="/sdk.js"></script>
|
|
12
|
+
|
|
13
|
+
<style>
|
|
14
|
+
canvas:focus {
|
|
15
|
+
outline: none;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
html,
|
|
19
|
+
body {
|
|
20
|
+
padding: 0;
|
|
21
|
+
margin: 0;
|
|
22
|
+
overflow: hidden;
|
|
23
|
+
-webkit-touch-callout: none;
|
|
24
|
+
-webkit-user-select: none;
|
|
25
|
+
-khtml-user-select: none;
|
|
26
|
+
-moz-user-select: none;
|
|
27
|
+
-ms-user-select: none;
|
|
28
|
+
user-select: none;
|
|
29
|
+
-webkit-tap-highlight-color: rgba(0, 0, 0, 0);
|
|
30
|
+
height: 100%;
|
|
31
|
+
}
|
|
32
|
+
</style>
|
|
33
|
+
|
|
34
|
+
<!-- Additional head modules -->
|
|
35
|
+
|
|
36
|
+
</head>
|
|
37
|
+
|
|
38
|
+
<body class="{{{ SPLASH_SCREEN_STYLE.toLowerCase() }}}">
|
|
39
|
+
<div id="unity-container" class="unity-desktop">
|
|
40
|
+
<canvas id="unity-canvas" tabindex="-1"></canvas>
|
|
41
|
+
</div>
|
|
42
|
+
<div id="loading-cover" style="display:none;">
|
|
43
|
+
<div id="unity-loading-bar">
|
|
44
|
+
<div id="unity-logo"><img src="Images/logo.png"></div>
|
|
45
|
+
<div id="unity-progress-bar-empty" style="display: none;">
|
|
46
|
+
<div id="unity-progress-bar-full"></div>
|
|
47
|
+
</div>
|
|
48
|
+
<div class="spinner"></div>
|
|
49
|
+
</div>
|
|
50
|
+
</div>
|
|
51
|
+
|
|
52
|
+
<!-- Additional body modules -->
|
|
53
|
+
|
|
54
|
+
<script>
|
|
55
|
+
const hideFullScreenButton = "";
|
|
56
|
+
const buildUrl = "Build";
|
|
57
|
+
const loaderUrl = buildUrl + "/{{{ LOADER_FILENAME }}}";
|
|
58
|
+
const config = {
|
|
59
|
+
dataUrl: buildUrl + "/{{{ DATA_FILENAME }}}",
|
|
60
|
+
frameworkUrl: buildUrl + "/{{{ FRAMEWORK_FILENAME }}}",
|
|
61
|
+
codeUrl: buildUrl + "/{{{ CODE_FILENAME }}}",
|
|
62
|
+
#if MEMORY_FILENAME
|
|
63
|
+
memoryUrl: buildUrl + "/{{{ MEMORY_FILENAME }}}",
|
|
64
|
+
#endif
|
|
65
|
+
#if SYMBOLS_FILENAME
|
|
66
|
+
symbolsUrl: buildUrl + "/{{{ SYMBOLS_FILENAME }}}",
|
|
67
|
+
#endif
|
|
68
|
+
streamingAssetsUrl: "StreamingAssets",
|
|
69
|
+
companyName: "{{{ COMPANY_NAME }}}",
|
|
70
|
+
productName: "{{{ PRODUCT_NAME }}}",
|
|
71
|
+
productVersion: "{{{ PRODUCT_VERSION }}}"
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
const container = document.querySelector("#unity-container");
|
|
75
|
+
const canvas = document.querySelector("#unity-canvas");
|
|
76
|
+
const loadingCover = document.querySelector("#loading-cover");
|
|
77
|
+
const progressBarEmpty = document.querySelector("#unity-progress-bar-empty");
|
|
78
|
+
const progressBarFull = document.querySelector("#unity-progress-bar-full");
|
|
79
|
+
const spinner = document.querySelector('.spinner');
|
|
80
|
+
|
|
81
|
+
const canFullscreen = (function () {
|
|
82
|
+
for (const key of [
|
|
83
|
+
'exitFullscreen',
|
|
84
|
+
'webkitExitFullscreen',
|
|
85
|
+
'webkitCancelFullScreen',
|
|
86
|
+
'mozCancelFullScreen',
|
|
87
|
+
'msExitFullscreen',
|
|
88
|
+
]) {
|
|
89
|
+
if (key in document) {
|
|
90
|
+
return true;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return false;
|
|
94
|
+
}());
|
|
95
|
+
|
|
96
|
+
if (/iPhone|iPad|iPod|Android/i.test(navigator.userAgent)) {
|
|
97
|
+
container.className = "unity-mobile";
|
|
98
|
+
//config.devicePixelRatio = 1;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// The background image when loading the game. When building a build, the code changes depending on the project settings.
|
|
102
|
+
#if BACKGROUND_FILENAME
|
|
103
|
+
var backgroundUnity = "url('" + buildUrl + "/{{{ BACKGROUND_FILENAME.replace(/'/g, '%27') }}}') center / cover";
|
|
104
|
+
#endif
|
|
105
|
+
loadingCover.style.background = "url('Images/background.png') center / cover";
|
|
106
|
+
loadingCover.style.display = "";
|
|
107
|
+
|
|
108
|
+
let StartUnityInstance;
|
|
109
|
+
let ygGameInstance = null;
|
|
110
|
+
let ysdk = null;
|
|
111
|
+
let initYSDK = false;
|
|
112
|
+
let initGame = false;
|
|
113
|
+
let syncInit = false;
|
|
114
|
+
let isVisibility = true;
|
|
115
|
+
let isPausedGame = false;
|
|
116
|
+
const NO_DATA = 'no data';
|
|
117
|
+
|
|
118
|
+
document.addEventListener('contextmenu', event => event.preventDefault());
|
|
119
|
+
document.addEventListener('visibilitychange', () => SetVisibility(!document.hidden));
|
|
120
|
+
window.addEventListener('blur', () => SetVisibility(false));
|
|
121
|
+
window.addEventListener('focus', () => SetVisibility(true));
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
window.addEventListener('pointerdown', () => {
|
|
125
|
+
FocusGame();
|
|
126
|
+
SetVisibility(true);
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
const oRequestPointerLock = Element.prototype.requestPointerLock;
|
|
130
|
+
Element.prototype.requestPointerLock = async function hkRequestPointerLock(...args) {
|
|
131
|
+
try {
|
|
132
|
+
(args[0] ||= {}).unadjustedMovement = true;
|
|
133
|
+
await oRequestPointerLock.apply(this, args);
|
|
134
|
+
} catch (err) {
|
|
135
|
+
console.log(err);
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
function InstallBlurFocusBlocker() {
|
|
140
|
+
if (!('onblur' in document)) return;
|
|
141
|
+
if (window.blurFocusHandlersInstalled) return;
|
|
142
|
+
|
|
143
|
+
window.addEventListener('blur', function () {
|
|
144
|
+
let blockerButton = document.createElement('button');
|
|
145
|
+
blockerButton.style.position = 'fixed';
|
|
146
|
+
blockerButton.style.top = '0';
|
|
147
|
+
blockerButton.style.left = '0';
|
|
148
|
+
blockerButton.style.width = '100%';
|
|
149
|
+
blockerButton.style.height = '100%';
|
|
150
|
+
blockerButton.style.zIndex = '9999';
|
|
151
|
+
blockerButton.style.backgroundColor = 'rgba(0, 0, 0, 0)';
|
|
152
|
+
blockerButton.style.border = 'none';
|
|
153
|
+
blockerButton.style.cursor = 'default';
|
|
154
|
+
|
|
155
|
+
document.body.appendChild(blockerButton);
|
|
156
|
+
|
|
157
|
+
function removeBlocker() {
|
|
158
|
+
if (blockerButton && blockerButton.parentNode) {
|
|
159
|
+
blockerButton.parentNode.removeChild(blockerButton);
|
|
160
|
+
}
|
|
161
|
+
window.removeEventListener('focus', removeBlocker);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
window.addEventListener('focus', removeBlocker);
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
window.blurFocusHandlersInstalled = true;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
function FocusGame() {
|
|
171
|
+
if (!isPausedGame) canvas.focus();
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
function SetVisibility(visibility) {
|
|
175
|
+
if (ysdk !== null && initGame === true && isVisibility !== visibility) {
|
|
176
|
+
isVisibility = visibility;
|
|
177
|
+
if (!visibility) {
|
|
178
|
+
YG2Instance('SetFocusWindowGame', 'false');
|
|
179
|
+
}
|
|
180
|
+
else {
|
|
181
|
+
YG2Instance('SetFocusWindowGame', 'true');
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
const PauseCallback = () => {
|
|
187
|
+
isPausedGame = true;
|
|
188
|
+
YG2Instance('SetPauseGame', 'true');
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
const ResumeCallback = () => {
|
|
192
|
+
isPausedGame = false;
|
|
193
|
+
YG2Instance('SetPauseGame', 'false');
|
|
194
|
+
};
|
|
195
|
+
|
|
196
|
+
const script = document.createElement("script");
|
|
197
|
+
script.src = loaderUrl;
|
|
198
|
+
script.onload = () => {
|
|
199
|
+
StartUnityInstance = function () {
|
|
200
|
+
createUnityInstance(canvas, config, (progress) => {
|
|
201
|
+
spinner.style.display = "none";
|
|
202
|
+
progressBarEmpty.style.display = "";
|
|
203
|
+
const adjustedProgress = Math.max(progress, 0.05);
|
|
204
|
+
progressBarFull.style.width = `${100 * adjustedProgress}%`;
|
|
205
|
+
}).then((unityInstance) => {
|
|
206
|
+
ygGameInstance = unityInstance;
|
|
207
|
+
loadingCover.style.background = "";
|
|
208
|
+
loadingCover.style.display = "none";
|
|
209
|
+
// Fill Background [Build Modify]
|
|
210
|
+
}).catch((message) => {
|
|
211
|
+
console.error(message);
|
|
212
|
+
});
|
|
213
|
+
};
|
|
214
|
+
|
|
215
|
+
InstallBlurFocusBlocker();
|
|
216
|
+
InitYSDK();
|
|
217
|
+
|
|
218
|
+
if (IsLocalHost() || syncInit)
|
|
219
|
+
StartUnityInstance_IfUnloaded();
|
|
220
|
+
};
|
|
221
|
+
|
|
222
|
+
function StartUnityInstance_IfUnloaded() {
|
|
223
|
+
if (spinner.style.display !== "none")
|
|
224
|
+
StartUnityInstance();
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
function IsLocalHost() {
|
|
228
|
+
try {
|
|
229
|
+
if (window.top !== window) {
|
|
230
|
+
return false;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
const host = window.location.hostname;
|
|
234
|
+
if (host === "localhost" || host === "127.0.0.1" || host.endsWith(".local")) {
|
|
235
|
+
LogStyledMessage("Local Host");
|
|
236
|
+
return true;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
catch (error) {
|
|
240
|
+
console.error("Error checking the local host:", error);
|
|
241
|
+
return false;
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
function YG2Instance(method) {
|
|
246
|
+
if (ygGameInstance == null)
|
|
247
|
+
return;
|
|
248
|
+
|
|
249
|
+
if (!initGame) {
|
|
250
|
+
setTimeout(function () {
|
|
251
|
+
if (ygGameInstance)
|
|
252
|
+
ygGameInstance.SendMessage('YG2Instance', method);
|
|
253
|
+
}, 100);
|
|
254
|
+
}
|
|
255
|
+
else {
|
|
256
|
+
ygGameInstance.SendMessage('YG2Instance', method);
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
}
|
|
260
|
+
function YG2Instance(method, arg) {
|
|
261
|
+
if (ygGameInstance == null)
|
|
262
|
+
return;
|
|
263
|
+
|
|
264
|
+
if (!initGame) {
|
|
265
|
+
setTimeout(function () {
|
|
266
|
+
ygGameInstance.SendMessage('YG2Instance', method, arg);
|
|
267
|
+
}, 100);
|
|
268
|
+
}
|
|
269
|
+
else {
|
|
270
|
+
ygGameInstance.SendMessage('YG2Instance', method, arg);
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
function LogStyledMessage(message, style) {
|
|
275
|
+
console.log('%c' + message, style);
|
|
276
|
+
}
|
|
277
|
+
function LogStyledMessage(message) {
|
|
278
|
+
console.log('%c' + message, 'color: #FFDF73; background-color: #454545');
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
async function InitYSDK() {
|
|
282
|
+
try {
|
|
283
|
+
if (IsLocalHost()) return;
|
|
284
|
+
|
|
285
|
+
ysdk = await YaGames.init();
|
|
286
|
+
ysdk.on('game_api_pause', PauseCallback);
|
|
287
|
+
ysdk.on('game_api_resume', ResumeCallback);
|
|
288
|
+
|
|
289
|
+
// Additional init0 modules
|
|
290
|
+
|
|
291
|
+
// Additional init1 modules
|
|
292
|
+
|
|
293
|
+
// Additional init2 modules
|
|
294
|
+
|
|
295
|
+
// Additional init modules
|
|
296
|
+
|
|
297
|
+
initYSDK = true;
|
|
298
|
+
if (ygGameInstance != null)
|
|
299
|
+
ygGameInstance.SendMessage('YG2Instance', 'InitSDKComplete');
|
|
300
|
+
|
|
301
|
+
LogStyledMessage('Init YandexSDK Success');
|
|
302
|
+
|
|
303
|
+
} catch (e) {
|
|
304
|
+
console.error('CRASH Initialization SDK: ', e);
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
if (!IsLocalHost() && !syncInit)
|
|
308
|
+
StartUnityInstance_IfUnloaded();
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
function InitGame() {
|
|
312
|
+
initGame = true;
|
|
313
|
+
|
|
314
|
+
setTimeout(function () {
|
|
315
|
+
if (isPausedGame == true)
|
|
316
|
+
YG2Instance('SetPauseGame', 'true');
|
|
317
|
+
}, 100);
|
|
318
|
+
|
|
319
|
+
// Additional start modules
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
// Additional script modules
|
|
323
|
+
|
|
324
|
+
document.body.appendChild(script);
|
|
325
|
+
</script>
|
|
326
|
+
</body>
|
|
327
|
+
|
|
328
|
+
</html>
|
|
@@ -0,0 +1,330 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en-us">
|
|
3
|
+
|
|
4
|
+
<head>
|
|
5
|
+
<meta charset="utf-8">
|
|
6
|
+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
|
7
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
|
|
8
|
+
<link rel="stylesheet" href="./style.css">
|
|
9
|
+
|
|
10
|
+
<!-- Yandex Games SDK -->
|
|
11
|
+
<script src="/sdk.js"></script>
|
|
12
|
+
|
|
13
|
+
<style>
|
|
14
|
+
canvas:focus {
|
|
15
|
+
outline: none;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
html,
|
|
19
|
+
body {
|
|
20
|
+
padding: 0;
|
|
21
|
+
margin: 0;
|
|
22
|
+
overflow: hidden;
|
|
23
|
+
-webkit-touch-callout: none;
|
|
24
|
+
-webkit-user-select: none;
|
|
25
|
+
-khtml-user-select: none;
|
|
26
|
+
-moz-user-select: none;
|
|
27
|
+
-ms-user-select: none;
|
|
28
|
+
user-select: none;
|
|
29
|
+
-webkit-tap-highlight-color: rgba(0, 0, 0, 0);
|
|
30
|
+
height: 100%;
|
|
31
|
+
}
|
|
32
|
+
</style>
|
|
33
|
+
|
|
34
|
+
<!-- Additional head modules -->
|
|
35
|
+
|
|
36
|
+
</head>
|
|
37
|
+
|
|
38
|
+
<body class="{{{ SPLASH_SCREEN_STYLE.toLowerCase() }}}">
|
|
39
|
+
<div id="game-container">
|
|
40
|
+
<div id="unity-container" class="unity-desktop">
|
|
41
|
+
<canvas id="unity-canvas" tabindex="-1"></canvas>
|
|
42
|
+
</div>
|
|
43
|
+
</div>
|
|
44
|
+
<div id="loading-cover" style="display:none;">
|
|
45
|
+
<div id="unity-loading-bar">
|
|
46
|
+
<div id="unity-logo"><img src="Images/logo.png"></div>
|
|
47
|
+
<div id="unity-progress-bar-empty" style="display: none;">
|
|
48
|
+
<div id="unity-progress-bar-full"></div>
|
|
49
|
+
</div>
|
|
50
|
+
<div class="spinner"></div>
|
|
51
|
+
</div>
|
|
52
|
+
</div>
|
|
53
|
+
|
|
54
|
+
<!-- Additional body modules -->
|
|
55
|
+
|
|
56
|
+
<script>
|
|
57
|
+
const hideFullScreenButton = "";
|
|
58
|
+
const buildUrl = "Build";
|
|
59
|
+
const loaderUrl = buildUrl + "/{{{ LOADER_FILENAME }}}";
|
|
60
|
+
const config = {
|
|
61
|
+
dataUrl: buildUrl + "/{{{ DATA_FILENAME }}}",
|
|
62
|
+
frameworkUrl: buildUrl + "/{{{ FRAMEWORK_FILENAME }}}",
|
|
63
|
+
codeUrl: buildUrl + "/{{{ CODE_FILENAME }}}",
|
|
64
|
+
#if MEMORY_FILENAME
|
|
65
|
+
memoryUrl: buildUrl + "/{{{ MEMORY_FILENAME }}}",
|
|
66
|
+
#endif
|
|
67
|
+
#if SYMBOLS_FILENAME
|
|
68
|
+
symbolsUrl: buildUrl + "/{{{ SYMBOLS_FILENAME }}}",
|
|
69
|
+
#endif
|
|
70
|
+
streamingAssetsUrl: "StreamingAssets",
|
|
71
|
+
companyName: "{{{ COMPANY_NAME }}}",
|
|
72
|
+
productName: "{{{ PRODUCT_NAME }}}",
|
|
73
|
+
productVersion: "{{{ PRODUCT_VERSION }}}"
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
const container = document.querySelector("#unity-container");
|
|
77
|
+
const canvas = document.querySelector("#unity-canvas");
|
|
78
|
+
const loadingCover = document.querySelector("#loading-cover");
|
|
79
|
+
const progressBarEmpty = document.querySelector("#unity-progress-bar-empty");
|
|
80
|
+
const progressBarFull = document.querySelector("#unity-progress-bar-full");
|
|
81
|
+
const spinner = document.querySelector('.spinner');
|
|
82
|
+
|
|
83
|
+
const canFullscreen = (function () {
|
|
84
|
+
for (const key of [
|
|
85
|
+
'exitFullscreen',
|
|
86
|
+
'webkitExitFullscreen',
|
|
87
|
+
'webkitCancelFullScreen',
|
|
88
|
+
'mozCancelFullScreen',
|
|
89
|
+
'msExitFullscreen',
|
|
90
|
+
]) {
|
|
91
|
+
if (key in document) {
|
|
92
|
+
return true;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return false;
|
|
96
|
+
}());
|
|
97
|
+
|
|
98
|
+
if (/iPhone|iPad|iPod|Android/i.test(navigator.userAgent)) {
|
|
99
|
+
container.className = "unity-mobile";
|
|
100
|
+
//config.devicePixelRatio = 1;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// The background image when loading the game. When building a build, the code changes depending on the project settings.
|
|
104
|
+
#if BACKGROUND_FILENAME
|
|
105
|
+
var backgroundUnity = "url('" + buildUrl + "/{{{ BACKGROUND_FILENAME.replace(/'/g, '%27') }}}') center / cover";
|
|
106
|
+
#endif
|
|
107
|
+
loadingCover.style.background = "url('Images/background.png') center / cover";
|
|
108
|
+
loadingCover.style.display = "";
|
|
109
|
+
|
|
110
|
+
let StartUnityInstance;
|
|
111
|
+
let ygGameInstance = null;
|
|
112
|
+
let ysdk = null;
|
|
113
|
+
let initYSDK = false;
|
|
114
|
+
let initGame = false;
|
|
115
|
+
let syncInit = false;
|
|
116
|
+
let isVisibility = true;
|
|
117
|
+
let isPausedGame = false;
|
|
118
|
+
const NO_DATA = 'no data';
|
|
119
|
+
|
|
120
|
+
document.addEventListener('contextmenu', event => event.preventDefault());
|
|
121
|
+
document.addEventListener('visibilitychange', () => SetVisibility(!document.hidden));
|
|
122
|
+
window.addEventListener('blur', () => SetVisibility(false));
|
|
123
|
+
window.addEventListener('focus', () => SetVisibility(true));
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
window.addEventListener('pointerdown', () => {
|
|
127
|
+
FocusGame();
|
|
128
|
+
SetVisibility(true);
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
const oRequestPointerLock = Element.prototype.requestPointerLock;
|
|
132
|
+
Element.prototype.requestPointerLock = async function hkRequestPointerLock(...args) {
|
|
133
|
+
try {
|
|
134
|
+
(args[0] ||= {}).unadjustedMovement = true;
|
|
135
|
+
await oRequestPointerLock.apply(this, args);
|
|
136
|
+
} catch (err) {
|
|
137
|
+
console.log(err);
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
function InstallBlurFocusBlocker() {
|
|
142
|
+
if (!('onblur' in document)) return;
|
|
143
|
+
if (window.blurFocusHandlersInstalled) return;
|
|
144
|
+
|
|
145
|
+
window.addEventListener('blur', function () {
|
|
146
|
+
let blockerButton = document.createElement('button');
|
|
147
|
+
blockerButton.style.position = 'fixed';
|
|
148
|
+
blockerButton.style.top = '0';
|
|
149
|
+
blockerButton.style.left = '0';
|
|
150
|
+
blockerButton.style.width = '100%';
|
|
151
|
+
blockerButton.style.height = '100%';
|
|
152
|
+
blockerButton.style.zIndex = '9999';
|
|
153
|
+
blockerButton.style.backgroundColor = 'rgba(0, 0, 0, 0)';
|
|
154
|
+
blockerButton.style.border = 'none';
|
|
155
|
+
blockerButton.style.cursor = 'default';
|
|
156
|
+
|
|
157
|
+
document.body.appendChild(blockerButton);
|
|
158
|
+
|
|
159
|
+
function removeBlocker() {
|
|
160
|
+
if (blockerButton && blockerButton.parentNode) {
|
|
161
|
+
blockerButton.parentNode.removeChild(blockerButton);
|
|
162
|
+
}
|
|
163
|
+
window.removeEventListener('focus', removeBlocker);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
window.addEventListener('focus', removeBlocker);
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
window.blurFocusHandlersInstalled = true;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
function FocusGame() {
|
|
173
|
+
if (!isPausedGame) canvas.focus();
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
function SetVisibility(visibility) {
|
|
177
|
+
if (ysdk !== null && initGame === true && isVisibility !== visibility) {
|
|
178
|
+
isVisibility = visibility;
|
|
179
|
+
if (!visibility) {
|
|
180
|
+
YG2Instance('SetFocusWindowGame', 'false');
|
|
181
|
+
}
|
|
182
|
+
else {
|
|
183
|
+
YG2Instance('SetFocusWindowGame', 'true');
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
const PauseCallback = () => {
|
|
189
|
+
isPausedGame = true;
|
|
190
|
+
YG2Instance('SetPauseGame', 'true');
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
const ResumeCallback = () => {
|
|
194
|
+
isPausedGame = false;
|
|
195
|
+
YG2Instance('SetPauseGame', 'false');
|
|
196
|
+
};
|
|
197
|
+
|
|
198
|
+
const script = document.createElement("script");
|
|
199
|
+
script.src = loaderUrl;
|
|
200
|
+
script.onload = () => {
|
|
201
|
+
StartUnityInstance = function () {
|
|
202
|
+
createUnityInstance(canvas, config, (progress) => {
|
|
203
|
+
spinner.style.display = "none";
|
|
204
|
+
progressBarEmpty.style.display = "";
|
|
205
|
+
const adjustedProgress = Math.max(progress, 0.05);
|
|
206
|
+
progressBarFull.style.width = `${100 * adjustedProgress}%`;
|
|
207
|
+
}).then((unityInstance) => {
|
|
208
|
+
ygGameInstance = unityInstance;
|
|
209
|
+
loadingCover.style.background = "";
|
|
210
|
+
loadingCover.style.display = "none";
|
|
211
|
+
// Fill Background [Build Modify]
|
|
212
|
+
}).catch((message) => {
|
|
213
|
+
console.error(message);
|
|
214
|
+
});
|
|
215
|
+
};
|
|
216
|
+
|
|
217
|
+
InstallBlurFocusBlocker();
|
|
218
|
+
InitYSDK();
|
|
219
|
+
|
|
220
|
+
if (IsLocalHost() || syncInit)
|
|
221
|
+
StartUnityInstance_IfUnloaded();
|
|
222
|
+
};
|
|
223
|
+
|
|
224
|
+
function StartUnityInstance_IfUnloaded() {
|
|
225
|
+
if (spinner.style.display !== "none")
|
|
226
|
+
StartUnityInstance();
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
function IsLocalHost() {
|
|
230
|
+
try {
|
|
231
|
+
if (window.top !== window) {
|
|
232
|
+
return false;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
const host = window.location.hostname;
|
|
236
|
+
if (host === "localhost" || host === "127.0.0.1" || host.endsWith(".local")) {
|
|
237
|
+
LogStyledMessage("Local Host");
|
|
238
|
+
return true;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
catch (error) {
|
|
242
|
+
console.error("Error checking the local host:", error);
|
|
243
|
+
return false;
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
function YG2Instance(method) {
|
|
248
|
+
if (ygGameInstance == null)
|
|
249
|
+
return;
|
|
250
|
+
|
|
251
|
+
if (!initGame) {
|
|
252
|
+
setTimeout(function () {
|
|
253
|
+
if (ygGameInstance)
|
|
254
|
+
ygGameInstance.SendMessage('YG2Instance', method);
|
|
255
|
+
}, 100);
|
|
256
|
+
}
|
|
257
|
+
else {
|
|
258
|
+
ygGameInstance.SendMessage('YG2Instance', method);
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
}
|
|
262
|
+
function YG2Instance(method, arg) {
|
|
263
|
+
if (ygGameInstance == null)
|
|
264
|
+
return;
|
|
265
|
+
|
|
266
|
+
if (!initGame) {
|
|
267
|
+
setTimeout(function () {
|
|
268
|
+
ygGameInstance.SendMessage('YG2Instance', method, arg);
|
|
269
|
+
}, 100);
|
|
270
|
+
}
|
|
271
|
+
else {
|
|
272
|
+
ygGameInstance.SendMessage('YG2Instance', method, arg);
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
function LogStyledMessage(message, style) {
|
|
277
|
+
console.log('%c' + message, style);
|
|
278
|
+
}
|
|
279
|
+
function LogStyledMessage(message) {
|
|
280
|
+
console.log('%c' + message, 'color: #FFDF73; background-color: #454545');
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
async function InitYSDK() {
|
|
284
|
+
try {
|
|
285
|
+
if (IsLocalHost()) return;
|
|
286
|
+
|
|
287
|
+
ysdk = await YaGames.init();
|
|
288
|
+
ysdk.on('game_api_pause', PauseCallback);
|
|
289
|
+
ysdk.on('game_api_resume', ResumeCallback);
|
|
290
|
+
|
|
291
|
+
// Additional init0 modules
|
|
292
|
+
|
|
293
|
+
// Additional init1 modules
|
|
294
|
+
|
|
295
|
+
// Additional init2 modules
|
|
296
|
+
|
|
297
|
+
// Additional init modules
|
|
298
|
+
|
|
299
|
+
initYSDK = true;
|
|
300
|
+
if (ygGameInstance != null)
|
|
301
|
+
ygGameInstance.SendMessage('YG2Instance', 'InitSDKComplete');
|
|
302
|
+
|
|
303
|
+
LogStyledMessage('Init YandexSDK Success');
|
|
304
|
+
|
|
305
|
+
} catch (e) {
|
|
306
|
+
console.error('CRASH Initialization SDK: ', e);
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
if (!IsLocalHost() && !syncInit)
|
|
310
|
+
StartUnityInstance_IfUnloaded();
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
function InitGame() {
|
|
314
|
+
initGame = true;
|
|
315
|
+
|
|
316
|
+
setTimeout(function () {
|
|
317
|
+
if (isPausedGame == true)
|
|
318
|
+
YG2Instance('SetPauseGame', 'true');
|
|
319
|
+
}, 100);
|
|
320
|
+
|
|
321
|
+
// Additional start modules
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
// Additional script modules
|
|
325
|
+
|
|
326
|
+
document.body.appendChild(script);
|
|
327
|
+
</script>
|
|
328
|
+
</body>
|
|
329
|
+
|
|
330
|
+
</html>
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
fileFormatVersion: 2
|
|
2
|
-
guid:
|
|
3
|
-
folderAsset: yes
|
|
4
|
-
DefaultImporter:
|
|
5
|
-
externalObjects: {}
|
|
6
|
-
userData:
|
|
7
|
-
assetBundleName:
|
|
8
|
-
assetBundleVariant:
|
|
1
|
+
fileFormatVersion: 2
|
|
2
|
+
guid: b4372fee5676d2643860b1d30834d758
|
|
3
|
+
folderAsset: yes
|
|
4
|
+
DefaultImporter:
|
|
5
|
+
externalObjects: {}
|
|
6
|
+
userData:
|
|
7
|
+
assetBundleName:
|
|
8
|
+
assetBundleVariant:
|
package/Editor/UniEditor.cs
CHANGED
|
@@ -454,6 +454,18 @@ namespace TyphoonUnitySDK
|
|
|
454
454
|
return version;
|
|
455
455
|
}
|
|
456
456
|
|
|
457
|
+
/// <summary>
|
|
458
|
+
/// 判断版本号是否合规
|
|
459
|
+
/// </summary>
|
|
460
|
+
public static bool IsMatchVersionString(string version)
|
|
461
|
+
{
|
|
462
|
+
if (string.IsNullOrEmpty(version))
|
|
463
|
+
return false;
|
|
464
|
+
|
|
465
|
+
// 数字(.数字)* —— 保证不以 . 开头/结尾,也不会出现 ..
|
|
466
|
+
return Regex.IsMatch(version, @"^\d+(\.\d+)*$");
|
|
467
|
+
}
|
|
468
|
+
|
|
457
469
|
|
|
458
470
|
/// <summary>
|
|
459
471
|
/// 复制文件夹
|
|
@@ -12,8 +12,29 @@ namespace TyphoonUnitySDK
|
|
|
12
12
|
new Dictionary<string, Func<YandexGamesConfig, bool>>()
|
|
13
13
|
{
|
|
14
14
|
{ "m_Script", DrawProperty_m_Script },
|
|
15
|
+
// { "PackageVersion", DrawProperty_PackageVersion },
|
|
16
|
+
{ "CanvasHeight", DrawProperty_CanvasHeight },
|
|
15
17
|
};
|
|
16
18
|
|
|
19
|
+
private static bool DrawProperty_CanvasHeight(YandexGamesConfig arg)
|
|
20
|
+
{
|
|
21
|
+
GUILayout.BeginHorizontal();
|
|
22
|
+
if (GUILayout.Button("540*960(竖屏)"))
|
|
23
|
+
{
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
if (GUILayout.Button("720*1280(竖屏)"))
|
|
27
|
+
{
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (GUILayout.Button("540*960(竖屏)"))
|
|
31
|
+
{
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
GUILayout.EndHorizontal();
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
|
|
17
38
|
|
|
18
39
|
private static bool DrawProperty_m_Script(YandexGamesConfig arg)
|
|
19
40
|
{
|
|
@@ -22,11 +43,28 @@ namespace TyphoonUnitySDK
|
|
|
22
43
|
GUILayout.Space(6);
|
|
23
44
|
GUIDrawer.DrawKeynotes("①支持Unity 2021.3.18+ , 2022.3+ , 2023.2+ , Unity 6");
|
|
24
45
|
GUIDrawer.DrawKeynotes("②剔除第三方SDK,避免与渠道冲突或不兼容");
|
|
46
|
+
GUIDrawer.DrawKeynotes("③先应用后再打包,避免参数写入失败");
|
|
25
47
|
GUILayout.Space(6);
|
|
26
48
|
GUI.enabled = tmpEnable;
|
|
27
49
|
return true;
|
|
28
50
|
}
|
|
29
51
|
|
|
52
|
+
// public static bool DrawProperty_PackageVersion(YandexGamesConfig arg)
|
|
53
|
+
// {
|
|
54
|
+
// GUILayout.BeginHorizontal();
|
|
55
|
+
// GUILayout.Label("Package Version", GUILayout.Width(218));
|
|
56
|
+
// arg.PackageVersion = EditorGUILayout.TextField("", arg.PackageVersion);
|
|
57
|
+
// if (GUILayout.Button("自动版本号", GUILayout.Width(100)))
|
|
58
|
+
// {
|
|
59
|
+
// arg.PackageVersion = UniEditor.AutoVersionSting(arg.PackageVersion);
|
|
60
|
+
// EditorUtility.SetDirty(arg);
|
|
61
|
+
// GUI.FocusControl("");
|
|
62
|
+
// }
|
|
63
|
+
//
|
|
64
|
+
// GUILayout.EndHorizontal();
|
|
65
|
+
// return true;
|
|
66
|
+
// }
|
|
67
|
+
|
|
30
68
|
|
|
31
69
|
/*绘制GUI*/
|
|
32
70
|
public static void DrawGUI()
|
|
@@ -83,8 +121,32 @@ namespace TyphoonUnitySDK
|
|
|
83
121
|
[LabelOverride("激励视频播放后跳过下一次插页广告", 220)]
|
|
84
122
|
public bool SkipIntersAfterShowRewardFlag = true;
|
|
85
123
|
|
|
86
|
-
[LabelOverride("
|
|
87
|
-
public
|
|
124
|
+
[LabelOverride("Product Icon", 220)]
|
|
125
|
+
public Texture2D ProductIcon;
|
|
126
|
+
|
|
127
|
+
[LabelOverride("Product Name (非中文)", 220)]
|
|
128
|
+
public string ProductName = string.Empty;
|
|
129
|
+
|
|
130
|
+
[LabelOverride("Company Name (非中文)", 220)]
|
|
131
|
+
public string CompanyName = string.Empty;
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
[LabelOverride("导出目录 (非中文,可选)", 220)]
|
|
135
|
+
public string ExportPath = "";
|
|
136
|
+
|
|
137
|
+
/// <summary>
|
|
138
|
+
/// 横竖屏模式
|
|
139
|
+
/// </summary>
|
|
140
|
+
public enum ScreenOrientation
|
|
141
|
+
{
|
|
142
|
+
Portrait,
|
|
143
|
+
Landscape,
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
[Header("横竖屏模式")]
|
|
147
|
+
public ScreenOrientation Orientation = ScreenOrientation.Portrait;
|
|
148
|
+
|
|
149
|
+
|
|
88
150
|
|
|
89
151
|
public void Save()
|
|
90
152
|
{
|
package/Runtime/LabelOverride.cs
CHANGED
|
@@ -18,6 +18,7 @@ namespace TyphoonUnitySDK
|
|
|
18
18
|
|
|
19
19
|
public void OnPauseGame(bool isPaused)
|
|
20
20
|
{
|
|
21
|
+
SdkDebug.Log($"[YandexGamesLifecycle] OnPauseGame {isPaused}");
|
|
21
22
|
if (isPaused)
|
|
22
23
|
{
|
|
23
24
|
GamePauser.AddPauseTag(TAG_ON_PAUSE_GAME);
|
|
@@ -30,11 +31,13 @@ namespace TyphoonUnitySDK
|
|
|
30
31
|
|
|
31
32
|
public void OnCloseAnyAdv()
|
|
32
33
|
{
|
|
34
|
+
SdkDebug.Log($"[YandexGamesLifecycle] OnCloseAnyAdv");
|
|
33
35
|
GamePauser.RemovePauseTag(TAG_ANY_ADV);
|
|
34
36
|
}
|
|
35
37
|
|
|
36
38
|
public void OnOpenAnyAdv()
|
|
37
39
|
{
|
|
40
|
+
SdkDebug.Log($"[YandexGamesLifecycle] OnOpenAnyAdv");
|
|
38
41
|
GamePauser.AddPauseTag(TAG_ANY_ADV);
|
|
39
42
|
}
|
|
40
43
|
}
|
|
Binary file
|
|
@@ -25,6 +25,8 @@ Assets/PluginYourGames/Third-Party Notices.txt
|
|
|
25
25
|
Assets/PluginYourGames/Third-Party Notices.txt.meta
|
|
26
26
|
Assets/PluginYourGames/Version.txt
|
|
27
27
|
Assets/PluginYourGames/Version.txt.meta
|
|
28
|
+
Assets/PluginYourGames/Editor/BuildLogYG2.txt
|
|
29
|
+
Assets/PluginYourGames/Editor/BuildLogYG2.txt.meta
|
|
28
30
|
Assets/PluginYourGames/Editor/ModulesListYG2.txt
|
|
29
31
|
Assets/PluginYourGames/Editor/ModulesListYG2.txt.meta
|
|
30
32
|
Assets/PluginYourGames/Editor/PluginPrefs.json
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"com.typhoon.unitysdk","displayName":"typhoon unity sdk","version":"1.1.
|
|
1
|
+
{"name":"com.typhoon.unitysdk","displayName":"typhoon unity sdk","version":"1.1.27","description":"","unity":"2018.1","type":"tool","hideInEditor":false,"author":{"name":"Jan Zhang","email":"","url":""},"changelogUrl":"","documentationUrl":"","keywords":["typhoon"],"license":"","licensesUrl":"","customDependencies":[{"PackageName":"com.unity.nuget.newtonsoft-json","Value":"2.0.0"}],"version_log":"## [1.1.27] - 2026-01-05\r\n\r\n### 新增\n* yandexgames渠道适配竖屏模式\r\n\r\n","major_flag":false,"write_time_stamp":1767608417000,"others":{"items":[]},"dependencies":{"com.unity.nuget.newtonsoft-json":"2.0.0"}}
|