@cc-component/cc-core 1.2.8
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/.cc-ex-component.md +12 -0
- package/assets/core/config/CommonEnum.ts +94 -0
- package/assets/core/config/CommonEnum.ts.meta +9 -0
- package/assets/core/config/IConfig.ts +89 -0
- package/assets/core/config/IConfig.ts.meta +9 -0
- package/assets/core/config/LayerType.ts +44 -0
- package/assets/core/config/LayerType.ts.meta +9 -0
- package/assets/core/config/LayerUI.ts +113 -0
- package/assets/core/config/LayerUI.ts.meta +9 -0
- package/assets/core/config.meta +9 -0
- package/assets/core/editor/LanguageManager.ts +323 -0
- package/assets/core/editor/LanguageManager.ts.meta +9 -0
- package/assets/core/editor/SpineRunner.ts +39 -0
- package/assets/core/editor/SpineRunner.ts.meta +9 -0
- package/assets/core/editor/i18nEditorComponent.ts +137 -0
- package/assets/core/editor/i18nEditorComponent.ts.meta +9 -0
- package/assets/core/editor.meta +9 -0
- package/assets/core/home/AudioUtil.ts +164 -0
- package/assets/core/home/AudioUtil.ts.meta +9 -0
- package/assets/core/home/BaseBoxView.ts +60 -0
- package/assets/core/home/BaseBoxView.ts.meta +9 -0
- package/assets/core/home/BaseLaunchComponent.ts +9 -0
- package/assets/core/home/BaseLaunchComponent.ts.meta +9 -0
- package/assets/core/home/BaseLoading.ts +136 -0
- package/assets/core/home/BaseLoading.ts.meta +9 -0
- package/assets/core/home/BaseSkeleton.ts +39 -0
- package/assets/core/home/BaseSkeleton.ts.meta +9 -0
- package/assets/core/home/CameraAngel.ts +326 -0
- package/assets/core/home/CameraAngel.ts.meta +9 -0
- package/assets/core/home/DouYinShow.ts +27 -0
- package/assets/core/home/DouYinShow.ts.meta +9 -0
- package/assets/core/home/EventManager.ts +39 -0
- package/assets/core/home/EventManager.ts.meta +9 -0
- package/assets/core/home/ExView.ts +9 -0
- package/assets/core/home/ExView.ts.meta +9 -0
- package/assets/core/home/FollowCamera.ts +205 -0
- package/assets/core/home/FollowCamera.ts.meta +9 -0
- package/assets/core/home/InViewCenter.ts +52 -0
- package/assets/core/home/InViewCenter.ts.meta +9 -0
- package/assets/core/home/JsonUtil.ts +102 -0
- package/assets/core/home/JsonUtil.ts.meta +9 -0
- package/assets/core/home/LoadingWindow.ts +44 -0
- package/assets/core/home/LoadingWindow.ts.meta +9 -0
- package/assets/core/home/ParabolaTween.ts +110 -0
- package/assets/core/home/ParabolaTween.ts.meta +9 -0
- package/assets/core/home/ProgessView.ts +96 -0
- package/assets/core/home/ProgessView.ts.meta +9 -0
- package/assets/core/home/Quaternion.ts +237 -0
- package/assets/core/home/Quaternion.ts.meta +9 -0
- package/assets/core/home/ResUtil.ts +132 -0
- package/assets/core/home/ResUtil.ts.meta +9 -0
- package/assets/core/home/ResourceManager.ts +430 -0
- package/assets/core/home/ResourceManager.ts.meta +9 -0
- package/assets/core/home/StateMachine.ts +93 -0
- package/assets/core/home/StateMachine.ts.meta +9 -0
- package/assets/core/home/StorageManager.ts +161 -0
- package/assets/core/home/StorageManager.ts.meta +9 -0
- package/assets/core/home/ThirdFreeLookCamera.ts +201 -0
- package/assets/core/home/ThirdFreeLookCamera.ts.meta +9 -0
- package/assets/core/home/TimeManager.ts +486 -0
- package/assets/core/home/TimeManager.ts.meta +9 -0
- package/assets/core/home/Tools.ts +103 -0
- package/assets/core/home/Tools.ts.meta +9 -0
- package/assets/core/home/prefabs.meta +12 -0
- package/assets/core/home/util/EncryptUtil.ts +60 -0
- package/assets/core/home/util/EncryptUtil.ts.meta +11 -0
- package/assets/core/home/util/MathUtil.ts +22 -0
- package/assets/core/home/util/MathUtil.ts.meta +9 -0
- package/assets/core/home/util/Md5.ts +202 -0
- package/assets/core/home/util/Md5.ts.meta +11 -0
- package/assets/core/home/util/RandomUtil.ts +61 -0
- package/assets/core/home/util/RandomUtil.ts.meta +9 -0
- package/assets/core/home/util/ResUtil.ts +129 -0
- package/assets/core/home/util/ResUtil.ts.meta +9 -0
- package/assets/core/home/util/crypto-js.d.ts +30 -0
- package/assets/core/home/util/crypto-js.d.ts.meta +11 -0
- package/assets/core/home/util/crypto-js.js +6030 -0
- package/assets/core/home/util/crypto-js.js.meta +9 -0
- package/assets/core/home/util.meta +12 -0
- package/assets/core/home.meta +12 -0
- package/assets/core/interface/ISceneParam.ts +11 -0
- package/assets/core/interface/ISceneParam.ts.meta +9 -0
- package/assets/core/interface/Interface.ts +160 -0
- package/assets/core/interface/Interface.ts.meta +1 -0
- package/assets/core/interface/MainModule.ts +1019 -0
- package/assets/core/interface/MainModule.ts.meta +9 -0
- package/assets/core/interface.meta +9 -0
- package/assets/core/lib/Logger.ts +286 -0
- package/assets/core/lib/Logger.ts.meta +9 -0
- package/assets/core/lib/language/.language.md +1 -0
- package/assets/core/lib/language/Language.ts +133 -0
- package/assets/core/lib/language/Language.ts.meta +13 -0
- package/assets/core/lib/language/LanguageData.ts +114 -0
- package/assets/core/lib/language/LanguageData.ts.meta +9 -0
- package/assets/core/lib/language/LanguageLabel.ts +172 -0
- package/assets/core/lib/language/LanguageLabel.ts.meta +13 -0
- package/assets/core/lib/language/LanguagePack.ts +126 -0
- package/assets/core/lib/language/LanguagePack.ts.meta +13 -0
- package/assets/core/lib/language/LanguagePointLabel.ts.meta +16 -0
- package/assets/core/lib/language/LanguageSpine.ts +60 -0
- package/assets/core/lib/language/LanguageSpine.ts.meta +9 -0
- package/assets/core/lib/language/LanguageSprite.ts +138 -0
- package/assets/core/lib/language/LanguageSprite.ts.meta +13 -0
- package/assets/core/lib/language.meta +9 -0
- package/assets/core/lib/logger/ELoggerLevel.ts +16 -0
- package/assets/core/lib/logger/ELoggerLevel.ts.meta +9 -0
- package/assets/core/lib/logger/MLogger.ts +118 -0
- package/assets/core/lib/logger/MLogger.ts.meta +9 -0
- package/assets/core/lib/logger.meta +9 -0
- package/assets/core/lib/net/libs/proto/output/protobuf.d.ts +2729 -0
- package/assets/core/lib/net/libs/proto/output/protobuf.d.ts.meta +9 -0
- package/assets/core/lib/net/libs/proto/output/protobuf.min.js +8 -0
- package/assets/core/lib/net/libs/proto/output/protobuf.min.js.meta +9 -0
- package/assets/core/lib/net/libs/proto/output/protobuf_custom.d.ts +102 -0
- package/assets/core/lib/net/libs/proto/output/protobuf_custom.d.ts.meta +9 -0
- package/assets/core/lib/net/libs/proto/output/protobuf_custom.js +222 -0
- package/assets/core/lib/net/libs/proto/output/protobuf_custom.js.meta +9 -0
- package/assets/core/lib/net/libs/proto/output.meta +9 -0
- package/assets/core/lib/net/libs/proto/source/Cmd.proto +6 -0
- package/assets/core/lib/net/libs/proto/source/Cmd.proto.meta +11 -0
- package/assets/core/lib/net/libs/proto/source/UserLogin.proto +12 -0
- package/assets/core/lib/net/libs/proto/source/UserLogin.proto.meta +11 -0
- package/assets/core/lib/net/libs/proto/source/base.proto +24 -0
- package/assets/core/lib/net/libs/proto/source/base.proto.meta +11 -0
- package/assets/core/lib/net/libs/proto/source/command.proto +31 -0
- package/assets/core/lib/net/libs/proto/source/command.proto.meta +11 -0
- package/assets/core/lib/net/libs/proto/source/domain/boos_battle_info.proto +13 -0
- package/assets/core/lib/net/libs/proto/source/domain/boos_battle_info.proto.meta +11 -0
- package/assets/core/lib/net/libs/proto/source/domain/player_auth.proto +26 -0
- package/assets/core/lib/net/libs/proto/source/domain/player_auth.proto.meta +11 -0
- package/assets/core/lib/net/libs/proto/source/domain.meta +9 -0
- package/assets/core/lib/net/libs/proto/source/message/game_push.proto +23 -0
- package/assets/core/lib/net/libs/proto/source/message/game_push.proto.meta +11 -0
- package/assets/core/lib/net/libs/proto/source/message/game_request.proto +24 -0
- package/assets/core/lib/net/libs/proto/source/message/game_request.proto.meta +11 -0
- package/assets/core/lib/net/libs/proto/source/message/game_response.proto +24 -0
- package/assets/core/lib/net/libs/proto/source/message/game_response.proto.meta +11 -0
- package/assets/core/lib/net/libs/proto/source/message.meta +9 -0
- package/assets/core/lib/net/libs/proto/source/push/boss_battle_events.proto +43 -0
- package/assets/core/lib/net/libs/proto/source/push/boss_battle_events.proto.meta +11 -0
- package/assets/core/lib/net/libs/proto/source/push.meta +9 -0
- package/assets/core/lib/net/libs/proto/source.meta +12 -0
- package/assets/core/lib/net/libs/proto.meta +9 -0
- package/assets/core/lib/net/libs.meta +9 -0
- package/assets/core/lib/net/net/HttpManager.ts +307 -0
- package/assets/core/lib/net/net/HttpManager.ts.meta +9 -0
- package/assets/core/lib/net/net/NetInterface.ts +114 -0
- package/assets/core/lib/net/net/NetInterface.ts.meta +9 -0
- package/assets/core/lib/net/net/NetManager.ts +77 -0
- package/assets/core/lib/net/net/NetManager.ts.meta +9 -0
- package/assets/core/lib/net/net/NetNode.ts +471 -0
- package/assets/core/lib/net/net/NetNode.ts.meta +9 -0
- package/assets/core/lib/net/net/WebSock.ts +81 -0
- package/assets/core/lib/net/net/WebSock.ts.meta +9 -0
- package/assets/core/lib/net/net/custom/NetChannelManager.ts +41 -0
- package/assets/core/lib/net/net/custom/NetChannelManager.ts.meta +9 -0
- package/assets/core/lib/net/net/custom/NetConfig.ts +11 -0
- package/assets/core/lib/net/net/custom/NetConfig.ts.meta +9 -0
- package/assets/core/lib/net/net/custom/NetErrorCode.ts +4 -0
- package/assets/core/lib/net/net/custom/NetErrorCode.ts.meta +9 -0
- package/assets/core/lib/net/net/custom/NetGameTips.ts +53 -0
- package/assets/core/lib/net/net/custom/NetGameTips.ts.meta +9 -0
- package/assets/core/lib/net/net/custom/NetNodeGame.ts +105 -0
- package/assets/core/lib/net/net/custom/NetNodeGame.ts.meta +9 -0
- package/assets/core/lib/net/net/custom.meta +9 -0
- package/assets/core/lib/net/net/protocol/NetProtocolJson.ts +39 -0
- package/assets/core/lib/net/net/protocol/NetProtocolJson.ts.meta +9 -0
- package/assets/core/lib/net/net/protocol/NetProtocolProtobuf.ts +85 -0
- package/assets/core/lib/net/net/protocol/NetProtocolProtobuf.ts.meta +9 -0
- package/assets/core/lib/net/net/protocol.meta +9 -0
- package/assets/core/lib/net/net.meta +9 -0
- package/assets/core/lib/net/prompt.meta +9 -0
- package/assets/core/lib/net.meta +9 -0
- package/assets/core/lib/old/VM2.ts +619 -0
- package/assets/core/lib/old/VM2.ts.meta +9 -0
- package/assets/core/lib/old/ViewModel.ts +905 -0
- package/assets/core/lib/old/ViewModel.ts.meta +9 -0
- package/assets/core/lib/old/ViewSearch.ts +125 -0
- package/assets/core/lib/old/ViewSearch.ts.meta +9 -0
- package/assets/core/lib/old.meta +9 -0
- package/assets/core/lib/tabbar/TabBarComponent.ts +113 -0
- package/assets/core/lib/tabbar/TabBarComponent.ts.meta +9 -0
- package/assets/core/lib/tabbar/TabBarController.ts +86 -0
- package/assets/core/lib/tabbar/TabBarController.ts.meta +9 -0
- package/assets/core/lib/tabbar/TabBarItem.ts +52 -0
- package/assets/core/lib/tabbar/TabBarItem.ts.meta +9 -0
- package/assets/core/lib/tabbar.meta +9 -0
- package/assets/core/lib.meta +12 -0
- package/assets/core.meta +9 -0
- package/assets.meta +9 -0
- package/index.ts +3 -0
- package/index.ts.meta +9 -0
- package/package.json +19 -0
- package/package.json.meta +11 -0
|
@@ -0,0 +1,1019 @@
|
|
|
1
|
+
import { Asset, assetManager, AudioClip, Canvas, CCObject, Constructor, director, find, game, instantiate, js, misc, Node, Prefab, resources, Size, tween, UITransform, v3, Vec3, view, Widget } from "cc";
|
|
2
|
+
import { AudioUtil } from "../home/AudioUtil";
|
|
3
|
+
import { BYTEDANCE, DEBUG, EDITOR } from "cc/env";
|
|
4
|
+
import { EventManager } from "../home/EventManager";
|
|
5
|
+
import { ResourceManager } from "../home/ResourceManager";
|
|
6
|
+
import { ISceneParam } from "./ISceneParam";
|
|
7
|
+
import { ParabolaTween } from "../home/ParabolaTween";
|
|
8
|
+
import { Component } from "cc";
|
|
9
|
+
import { isValid } from "cc";
|
|
10
|
+
import { EnvironmentConfig, IConfig } from "../config/IConfig";
|
|
11
|
+
import { LayerUI } from "../config/LayerUI";
|
|
12
|
+
import { Sprite, SpriteFrame, sp } from "cc";
|
|
13
|
+
import { HttpManager, HttpReturn } from "../lib/net/net/HttpManager";
|
|
14
|
+
import { StorageManager } from "../home/StorageManager";
|
|
15
|
+
import { TimeManager } from "../home/TimeManager";
|
|
16
|
+
import { LanguageManager } from "../lib/language/Language";
|
|
17
|
+
import { BundleConfigName, HttpType, IBundleConfig, IExtData, IHttpConfig, IInitConfig, IWindowParam, SystemMessage } from "../config/CommonEnum";
|
|
18
|
+
import { LayerType } from "../config/LayerType";
|
|
19
|
+
import { Logger } from "../lib/Logger";
|
|
20
|
+
import { Main } from "electron";
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
// const { keepClassName } = keepClass;
|
|
24
|
+
|
|
25
|
+
// @keepClassName
|
|
26
|
+
export class MainModule {
|
|
27
|
+
/**当前bundle */
|
|
28
|
+
static get bundleName(): string { return this.instance._gui.bundleName };
|
|
29
|
+
/**界面层 */
|
|
30
|
+
static get gui(): LayerUI { return this.instance._gui };
|
|
31
|
+
/**网络 */
|
|
32
|
+
static get http(): HttpManager { return this.instance._http };
|
|
33
|
+
/**存储层 */
|
|
34
|
+
static get storage(): StorageManager { return this.instance._storage };
|
|
35
|
+
/**场景参数 */
|
|
36
|
+
static get scenesParm(): ISceneParam { return this.instance._scenesParm };
|
|
37
|
+
/**时间管理 */
|
|
38
|
+
static get timeManager(): TimeManager { return this.instance._timeManager };
|
|
39
|
+
/**多语言模块 */
|
|
40
|
+
static get language(): LanguageManager {
|
|
41
|
+
|
|
42
|
+
return this.instance._language
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
_gui: LayerUI;
|
|
47
|
+
_http: HttpManager;
|
|
48
|
+
_storage: StorageManager;
|
|
49
|
+
_scenesParm: ISceneParam = {
|
|
50
|
+
param: undefined,
|
|
51
|
+
bundleName: "",
|
|
52
|
+
sceneName: "",
|
|
53
|
+
};
|
|
54
|
+
_timeManager: TimeManager;
|
|
55
|
+
/** 多语言模块 */
|
|
56
|
+
_language: LanguageManager;
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
private static instance: MainModule | null = null;
|
|
60
|
+
public static get Ins(): MainModule {
|
|
61
|
+
if (!MainModule.instance) { MainModule.instance = new MainModule(); }
|
|
62
|
+
return MainModule.instance;
|
|
63
|
+
}
|
|
64
|
+
constructor() {
|
|
65
|
+
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
time: number = 0
|
|
69
|
+
private openedWindows: Map<string, Component> = new Map();
|
|
70
|
+
private openedWindowsConfig: Map<string, IBundleConfig> = new Map();
|
|
71
|
+
|
|
72
|
+
private openWindowLayer: Map<string, string[]> = new Map();
|
|
73
|
+
|
|
74
|
+
static async InitGameConfig(param: IInitConfig) {
|
|
75
|
+
if (MainModule.Ins._gui) { return }
|
|
76
|
+
|
|
77
|
+
/**资源下载配置 */
|
|
78
|
+
assetManager.downloader.maxConcurrency = 10;
|
|
79
|
+
assetManager.downloader.maxRequestsPerFrame = 6;
|
|
80
|
+
assetManager.downloader.maxRetryCount = 100
|
|
81
|
+
assetManager.downloader.retryInterval = 2000
|
|
82
|
+
const self = MainModule.Ins;
|
|
83
|
+
// 存储层
|
|
84
|
+
self._storage = new StorageManager();
|
|
85
|
+
/**时间管理器 */
|
|
86
|
+
self._timeManager = new TimeManager();
|
|
87
|
+
self._language = new LanguageManager();
|
|
88
|
+
// 加载资源配置
|
|
89
|
+
self._gui = new LayerUI();
|
|
90
|
+
self._http = new HttpManager();
|
|
91
|
+
if (!EDITOR) {
|
|
92
|
+
await self._gui.loadConfig(param);
|
|
93
|
+
const config: EnvironmentConfig = self._gui.current_config;
|
|
94
|
+
// 免网络
|
|
95
|
+
self._http.server = config.httpServer;
|
|
96
|
+
self._http.timeout = config.httpTimeout;
|
|
97
|
+
}
|
|
98
|
+
console.log("初始化完成")
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
static OpenLoading(is_show: boolean) {
|
|
102
|
+
if (is_show)
|
|
103
|
+
MainModule.gui.loading_call.open?.(() => { })
|
|
104
|
+
else
|
|
105
|
+
MainModule.gui.loading_call.close?.()
|
|
106
|
+
MainModule.OpenBlockEvents(LayerType.LayerBlockEventsUI, is_show)
|
|
107
|
+
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
//设置微信按钮的大小和位置
|
|
113
|
+
static GetWxRatio(node: Node) {
|
|
114
|
+
|
|
115
|
+
let width = node.getComponent(UITransform).contentSize.width;
|
|
116
|
+
let height = node.getComponent(UITransform).contentSize.height;
|
|
117
|
+
let windowSize = view.getVisibleSize();
|
|
118
|
+
// console.log(windowSize);
|
|
119
|
+
// console.log("屏幕:", windowSize);
|
|
120
|
+
let leftRatio = node.worldPosition.x / windowSize.width;
|
|
121
|
+
let topRatio = 1 - (node.worldPosition.y / windowSize.height);
|
|
122
|
+
|
|
123
|
+
// let scale = 1334/windowSize.height;
|
|
124
|
+
// console.error("比例",scale,node.position.y);
|
|
125
|
+
// node.position = v3(node.position.x,node.position.y*scale)
|
|
126
|
+
// console.error("2比例",scale,node.position.y);
|
|
127
|
+
|
|
128
|
+
return { width: width, height: height, topRatio: topRatio, leftRatio: leftRatio }
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
//业务
|
|
132
|
+
//加载LoadResources
|
|
133
|
+
static async LoadResources(pre: Function, finish?: Function) {
|
|
134
|
+
resources.preloadDir("prefabs", (finished: number, total: number, item: any) => {
|
|
135
|
+
pre(parseInt((finished / total * 100).toFixed(1)));
|
|
136
|
+
}, () => {
|
|
137
|
+
finish && finish();
|
|
138
|
+
})
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* 加载资源并自动记录
|
|
142
|
+
* @param bundleName Bundle 名称
|
|
143
|
+
* @param path 资源路径
|
|
144
|
+
* @param type 资源类型
|
|
145
|
+
* @returns 加载的资源
|
|
146
|
+
*/
|
|
147
|
+
public static getAsset<T extends Asset>(bundleName: string, path: string, type?: { new(): T }): T {
|
|
148
|
+
// 加载资源
|
|
149
|
+
return ResourceManager.getAsset(bundleName, path, type)
|
|
150
|
+
}
|
|
151
|
+
public static async loadAsset<T extends Asset>(
|
|
152
|
+
bundleName: string,
|
|
153
|
+
path: string,
|
|
154
|
+
type: { new(): T }
|
|
155
|
+
): Promise<T> {
|
|
156
|
+
// 加载资源
|
|
157
|
+
return ResourceManager.loadAsset(bundleName, path, type)
|
|
158
|
+
}
|
|
159
|
+
static releaseAssetsByBundle(bundleName: string) {
|
|
160
|
+
ResourceManager.instance.releaseAssetsByBundle(bundleName);
|
|
161
|
+
// if (DEBUG) {
|
|
162
|
+
// setTimeout(() => {
|
|
163
|
+
// ResourceManager.instance.LogAssetsAll()
|
|
164
|
+
// }, 1000)
|
|
165
|
+
// }
|
|
166
|
+
//ResourceManager.instance.releaseAssetsByBundle(BundleConfigName.common);//释放通用资源
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
static releaseAsset(bundleName: string, node: Node) {
|
|
170
|
+
ResourceManager.instance.releaseAsset(node, bundleName)
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
static releaseAssetPath(path: string, bundleName: string): void {
|
|
174
|
+
ResourceManager.instance.releaseAssetPath(path, bundleName)
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
static async preloadDir(bundleName: string, dirName: string, pre: Function) {
|
|
178
|
+
return ResourceManager.preloadDir(bundleName, dirName, pre)
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
static async loadDir(bundleName: string, dirName: string, type: any, pre: Function) {
|
|
182
|
+
return ResourceManager.loadDir(bundleName, dirName, type, pre)
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
static DeepCopy<T>(obj: T): T {
|
|
188
|
+
if (obj === null || typeof obj !== 'object') {
|
|
189
|
+
return obj;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
if (Array.isArray(obj)) {
|
|
193
|
+
const arrCopy = [] as any[];
|
|
194
|
+
for (const item of obj) {
|
|
195
|
+
arrCopy.push(MainModule.DeepCopy(item));
|
|
196
|
+
}
|
|
197
|
+
return arrCopy as unknown as T;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
const objCopy = {} as { [key: string]: any };
|
|
201
|
+
for (const key in obj) {
|
|
202
|
+
if (obj.hasOwnProperty(key)) {
|
|
203
|
+
objCopy[key] = MainModule.DeepCopy(obj[key]);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
return objCopy as T;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
//音乐
|
|
213
|
+
static async playOneShot(sound: AudioClip | string, volume: number = 0.5) {
|
|
214
|
+
AudioUtil.inst.playOneShot(sound, volume)
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
static async play(sound: AudioClip | string, volume: number = 1.0) {
|
|
218
|
+
let isMusic = MainModule.storage.getBoolean("musicButton")
|
|
219
|
+
// console.error("音乐", isMusic);
|
|
220
|
+
|
|
221
|
+
if (!isMusic) {
|
|
222
|
+
MainModule.storage.set("musicButton", false)
|
|
223
|
+
}
|
|
224
|
+
isMusic = MainModule.storage.getBoolean("musicButton")
|
|
225
|
+
|
|
226
|
+
if (isMusic) {
|
|
227
|
+
AudioUtil.inst.play(sound, volume)
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
// console.error('声音---',isMusic);
|
|
231
|
+
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
static async stop() {
|
|
235
|
+
AudioUtil.inst.stop()
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
static async pause() {
|
|
239
|
+
AudioUtil.inst.pause()
|
|
240
|
+
}
|
|
241
|
+
static async resume() {
|
|
242
|
+
AudioUtil.inst.resume()
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
static musicVolume(volume: number) {
|
|
246
|
+
AudioUtil.inst.music_volume = volume
|
|
247
|
+
}
|
|
248
|
+
static soundVolume(volume: number) {
|
|
249
|
+
AudioUtil.inst.sound_volume = volume
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
static getMusicVolume() {
|
|
253
|
+
return AudioUtil.inst.music_volume
|
|
254
|
+
}
|
|
255
|
+
static getSoundVolume() {
|
|
256
|
+
return AudioUtil.inst.sound_volume
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
static async playJump(sound: AudioClip | string, volume: number = 1.0) {
|
|
260
|
+
AudioUtil.inst.playJump(sound, volume)
|
|
261
|
+
// console.error('声音---',isMusic);
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
static async stopJump() {
|
|
265
|
+
AudioUtil.inst.stopJump()
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
// static async Http<T>(config: IHttpConfig, params?: any, ext?: { is_show_alert?: boolean }): Promise<HttpReturn<T>> {
|
|
269
|
+
// return new Promise<HttpReturn<any>>(async (resolve, reject) => {
|
|
270
|
+
// MainModule.OpenBlockEvents(LayerType.LayerBlockEventsNet, true)
|
|
271
|
+
// console.warn(`发起${config.type === HttpType.GET ? "GET请求" : "POST请求"} url:${config.url}\n 参数:${params}`,);
|
|
272
|
+
// let ret: HttpReturn<any>;
|
|
273
|
+
// if (config.type == HttpType.GET) {
|
|
274
|
+
// ret = await MainModule.http.getJson(config.url, params);
|
|
275
|
+
// } else if (config.type == HttpType.POST) {
|
|
276
|
+
// ret = await MainModule.http.postJson(config.url, params);
|
|
277
|
+
// }
|
|
278
|
+
// console.warn(`${config.type === HttpType.GET ? "GET请求" : "POST请求"} url:${config.url}\n 参数:${params}`);
|
|
279
|
+
// console.warn(`返回结果:${ret}`);
|
|
280
|
+
// console.warn(`返回结果:${JSON.stringify(ret.res)}`);
|
|
281
|
+
// MainModule.OpenBlockEvents(LayerType.LayerBlockEventsNet, false)
|
|
282
|
+
// if (ret.isSucc) {
|
|
283
|
+
// resolve(ret.res)
|
|
284
|
+
// }
|
|
285
|
+
// else {
|
|
286
|
+
// console.log(ret.err);
|
|
287
|
+
// if (ext && ext.is_show_alert || (ext === undefined || ext.is_show_alert === undefined)) {
|
|
288
|
+
// const param = { des: "网络断开,请检查网络!", enterStr: "重试?", cancelStr: "取消", isDestory: false }
|
|
289
|
+
// const view = await CommonModule.OpenAlertWindow(param);
|
|
290
|
+
// view.callBack = (isOk: boolean) => {
|
|
291
|
+
// if (isOk) {
|
|
292
|
+
// MainModule.Http(config, params).then(resolve).catch(reject);
|
|
293
|
+
// } else {
|
|
294
|
+
// reject?.(ret.err)
|
|
295
|
+
// }
|
|
296
|
+
// }
|
|
297
|
+
// } else {
|
|
298
|
+
// reject?.(ret.err)
|
|
299
|
+
// }
|
|
300
|
+
// //
|
|
301
|
+
// }
|
|
302
|
+
// })
|
|
303
|
+
// }
|
|
304
|
+
|
|
305
|
+
static async Requst<T>(
|
|
306
|
+
config: IHttpConfig,
|
|
307
|
+
params?: any,
|
|
308
|
+
ext?: IExtData
|
|
309
|
+
): Promise<HttpReturn<T>> {
|
|
310
|
+
return new Promise<HttpReturn<any>>(async (originalResolve, originalReject) => {
|
|
311
|
+
let retries = 0; // 当前重试次数
|
|
312
|
+
const maxRetries = 5; // 最大重试次数
|
|
313
|
+
|
|
314
|
+
// 内部辅助函数,用于执行请求逻辑
|
|
315
|
+
const attemptRequest = async () => {
|
|
316
|
+
try {
|
|
317
|
+
MainModule.OpenBlockEvents(LayerType.LayerBlockEventsNet, true);
|
|
318
|
+
|
|
319
|
+
const url = MainModule.gui.current_config.httpServer + config.url
|
|
320
|
+
console.log(`${config.type === HttpType.GET ? "GET请求" : "POST请求"} url:${url} `, `\n 参数:`, params);
|
|
321
|
+
let ret: HttpReturn<any>;
|
|
322
|
+
if (config.type === HttpType.GET) {
|
|
323
|
+
ret = await MainModule.http.getJson(config.url, params);
|
|
324
|
+
} else if (config.type === HttpType.POST) {
|
|
325
|
+
ret = await MainModule.http.postJson(config.url, params, ext);
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
console.log(`${config.type === HttpType.GET ? "GET请求" : "POST请求"} 结果 url:${url}\n`, ` 参数:`, params);
|
|
329
|
+
console.log(`返回结果:`, ret.res);
|
|
330
|
+
//console.warn(`返回结果:${JSON.stringify(ret.res)}`);
|
|
331
|
+
|
|
332
|
+
MainModule.OpenBlockEvents(LayerType.LayerBlockEventsNet, false);
|
|
333
|
+
if (ret.isSucc) {
|
|
334
|
+
originalResolve(ret.res); // 请求成功,调用原始 resolve
|
|
335
|
+
} else {
|
|
336
|
+
throw new Error(ret.err); // 请求失败,抛出错误以触发重试逻辑
|
|
337
|
+
}
|
|
338
|
+
} catch (error) {
|
|
339
|
+
console.error(`请求失败: ${error.message}`);
|
|
340
|
+
retries++;
|
|
341
|
+
|
|
342
|
+
if (retries > maxRetries) {
|
|
343
|
+
console.error("达到最大重试次数,请求失败");
|
|
344
|
+
originalReject(error); // 达到最大重试次数后调用原始 reject
|
|
345
|
+
return;
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
if (ext && ext.is_show_alert || (ext === undefined || ext.is_show_alert === undefined)) {
|
|
349
|
+
|
|
350
|
+
const userChoice = await new Promise<boolean>((resolve) => {
|
|
351
|
+
const finish = (isOk: boolean) => { resolve(isOk) }
|
|
352
|
+
MainModule.http.open?.(finish)
|
|
353
|
+
//param.callBack = (isOk: boolean) => resolve(isOk);
|
|
354
|
+
});
|
|
355
|
+
|
|
356
|
+
if (!userChoice) {
|
|
357
|
+
console.log("用户取消请求");
|
|
358
|
+
originalReject("取消了"); // 用户取消,调用原始 reject
|
|
359
|
+
return;
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
|
|
363
|
+
}
|
|
364
|
+
MainModule.OpenBlockEvents(LayerType.LayerBlockEventsNet, true);
|
|
365
|
+
// 继续重试,但避免直接递归调用
|
|
366
|
+
setTimeout(attemptRequest, 100); // 使用 setTimeout 避免栈溢出
|
|
367
|
+
}
|
|
368
|
+
};
|
|
369
|
+
|
|
370
|
+
// 开始第一次请求
|
|
371
|
+
attemptRequest();
|
|
372
|
+
});
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
|
|
376
|
+
//获取真实的时间挫
|
|
377
|
+
static DateNow() {
|
|
378
|
+
let time = Date.now()
|
|
379
|
+
if (MainModule.Ins.time > 0) {//客户端比服务器时间快
|
|
380
|
+
time = time - MainModule.Ins.time;
|
|
381
|
+
} else {//客户端比服务器时间慢
|
|
382
|
+
time = time + Math.abs(MainModule.Ins.time)
|
|
383
|
+
}
|
|
384
|
+
return time
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
static UpdateTime(old: number) {
|
|
388
|
+
MainModule.Ins.time = parseInt(old.toFixed(0));
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
|
|
392
|
+
static async OpenWindow<T extends Component>(config: IBundleConfig, param?: IWindowParam): Promise<T> {
|
|
393
|
+
return new Promise<T>(async (resolve, reject) => {
|
|
394
|
+
try {
|
|
395
|
+
const className = config.name ?? config.path.split('/').pop();
|
|
396
|
+
if (MainModule.IsWindowOpen(className)) {
|
|
397
|
+
const view = MainModule.GetOpenWindow<Component>(config);
|
|
398
|
+
resolve(view as T);
|
|
399
|
+
//延迟100毫秒防止连点
|
|
400
|
+
setTimeout(() => { MainModule.OpenBlockEvents(LayerType.LayerBlockEventsUI, false) }, 100);
|
|
401
|
+
return;
|
|
402
|
+
}
|
|
403
|
+
else if (MainModule.IsWindowOpen(className)) {
|
|
404
|
+
console.warn("重复打开窗口-请检查", config.path)
|
|
405
|
+
return;
|
|
406
|
+
}
|
|
407
|
+
//console.error('打开:', Array.from(MainModule.Instance.openedWindows.keys()), config.path);
|
|
408
|
+
MainModule.OpenBlockEvents(LayerType.LayerBlockEventsUI, true)
|
|
409
|
+
if (!param) {
|
|
410
|
+
param = {}
|
|
411
|
+
}
|
|
412
|
+
const call = param?.callBack;
|
|
413
|
+
const backCallback = (arg1: any, arg2: any) => {
|
|
414
|
+
call?.(arg1, arg2)
|
|
415
|
+
}
|
|
416
|
+
if (param instanceof Object)
|
|
417
|
+
param.callBack = backCallback;
|
|
418
|
+
|
|
419
|
+
const view = await MainModule.LoadWindow<T>(config, param);
|
|
420
|
+
|
|
421
|
+
MainModule.gui.GetLayer(config.layer).addChild(view.node);
|
|
422
|
+
|
|
423
|
+
// 添加关闭事件监听
|
|
424
|
+
MainModule.Ins.setupCloseListener(view, className);
|
|
425
|
+
|
|
426
|
+
if (config.is_load_sub) {
|
|
427
|
+
(view as any).root.active = false;
|
|
428
|
+
await new Promise<void>((resolve, reject) => { (view as any).finish_sub = resolve; });
|
|
429
|
+
(view as any).root.active = true;
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
view.node.getComponent(Widget)?.updateAlignment();
|
|
433
|
+
|
|
434
|
+
//隐藏底层的UI
|
|
435
|
+
MainModule.instance.ShowLayerUI(config, false)
|
|
436
|
+
//收集打开的窗口
|
|
437
|
+
if (!MainModule.Ins.openWindowLayer.has(config.layer)) {
|
|
438
|
+
MainModule.Ins.openWindowLayer.set(config.layer, []);//LayerUI层
|
|
439
|
+
}
|
|
440
|
+
const list = MainModule.Ins.openWindowLayer.get(config.layer)
|
|
441
|
+
list.push(className);
|
|
442
|
+
const layerUI_list = MainModule.Ins.openWindowLayer.get(LayerType.LayerUI)
|
|
443
|
+
if (layerUI_list && layerUI_list.length > 0) MainModule.gui.GetLayer(LayerType.LayerGame).active = false;
|
|
444
|
+
console.log('LayerType.LayerUI 打开窗口记录:', className, list);
|
|
445
|
+
MainModule.Emit(SystemMessage.OpenWindow, className)
|
|
446
|
+
|
|
447
|
+
resolve(view);
|
|
448
|
+
//延迟100毫秒防止连点
|
|
449
|
+
setTimeout(() => { MainModule.OpenBlockEvents(LayerType.LayerBlockEventsUI, false) }, 100);
|
|
450
|
+
} catch (error) {
|
|
451
|
+
console.error("打开窗口失败:", error);
|
|
452
|
+
MainModule.CloseLoading()
|
|
453
|
+
reject(error);
|
|
454
|
+
}
|
|
455
|
+
});
|
|
456
|
+
}
|
|
457
|
+
static async LoadWindow<T extends Component>(config: IBundleConfig, param?: IWindowParam): Promise<T> {
|
|
458
|
+
return new Promise<T>(async (resolve, reject) => {
|
|
459
|
+
try {
|
|
460
|
+
const className = config.name ?? config.path.split('/').pop();
|
|
461
|
+
// 记录打开的窗口--先占位
|
|
462
|
+
if (config.is_record === undefined || config.is_record) {//默认记录
|
|
463
|
+
MainModule.Ins.openedWindows.set(className, null);
|
|
464
|
+
MainModule.Ins.openedWindowsConfig.set(className, config);
|
|
465
|
+
}
|
|
466
|
+
//await Await(1000)
|
|
467
|
+
const prefab = await ResourceManager.loadAsset<Prefab>(config.bundle, config.path)
|
|
468
|
+
const node = instantiate(prefab);
|
|
469
|
+
|
|
470
|
+
const view = ((node.getComponent(className)) || (node.addComponent(className))) as T;
|
|
471
|
+
if (config.is_record === undefined || config.is_record) {//默认记录
|
|
472
|
+
MainModule.Ins.openedWindows.set(className, view);
|
|
473
|
+
MainModule.Ins.openedWindowsConfig.set(className, config);
|
|
474
|
+
}
|
|
475
|
+
//@ts-ignore
|
|
476
|
+
view.window_name = className;
|
|
477
|
+
//@ts-ignore
|
|
478
|
+
view.config = config;
|
|
479
|
+
//@ts-ignore
|
|
480
|
+
if (param) view.param = param;
|
|
481
|
+
// if (config.is_add_layer) {
|
|
482
|
+
// MainModule.gui.GetLayer(config.layer).addChild(view.node);
|
|
483
|
+
// }
|
|
484
|
+
|
|
485
|
+
resolve(view);
|
|
486
|
+
} catch (error) {
|
|
487
|
+
console.error("加载窗口失败:", config.path, error);
|
|
488
|
+
reject(error);
|
|
489
|
+
}
|
|
490
|
+
});
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
static async RootWindow<T extends Component>(config: IBundleConfig, param?: IWindowParam): Promise<T> {
|
|
494
|
+
await MainModule.CloseAll([LayerType.LayerUI, LayerType.LayerDialog, LayerType.LayerPopUp])
|
|
495
|
+
//打开
|
|
496
|
+
return MainModule.OpenWindow(config)
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
static async CloseAll(layer_list: LayerType[]) {
|
|
500
|
+
const windows = MainModule.GetOpenedWindowNames()
|
|
501
|
+
await new Promise<void>((resolve, reject) => {
|
|
502
|
+
//销毁已有的窗口
|
|
503
|
+
const destroyPromises: Promise<void>[] = []; // 用于存储每个销毁事件的 Promise
|
|
504
|
+
windows.forEach(className => {
|
|
505
|
+
const config = MainModule.Ins.openedWindowsConfig.get(className);
|
|
506
|
+
if (layer_list.includes(config.layer)) {
|
|
507
|
+
const view = MainModule.GetOpenWindow<any>(config);
|
|
508
|
+
// 创建一个 Promise 来等待 NODE_DESTROYED 事件完成
|
|
509
|
+
const destroyPromise = new Promise<void>((destroyResolve) => {
|
|
510
|
+
if (view.node && isValid(view.node, true)) {
|
|
511
|
+
view.node.once(Node.EventType.NODE_DESTROYED, () => {
|
|
512
|
+
destroyResolve(); // 当前节点销毁后 resolve
|
|
513
|
+
});
|
|
514
|
+
} else {
|
|
515
|
+
destroyResolve(); // 当前节点销毁后 resolve
|
|
516
|
+
}
|
|
517
|
+
});
|
|
518
|
+
destroyPromises.push(destroyPromise); // 将 Promise 添加到集合中
|
|
519
|
+
if (view && view.node && isValid(view.node, true)) {
|
|
520
|
+
view.node.destroy(); // 关闭窗口
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
})
|
|
524
|
+
// 等待所有销毁事件完成后再 resolve 外层 Promise
|
|
525
|
+
Promise.all(destroyPromises).then(() => resolve());
|
|
526
|
+
});
|
|
527
|
+
}
|
|
528
|
+
static OpenBlockEvents(type: LayerType, is_show: boolean) {
|
|
529
|
+
MainModule.gui.GetLayer(type).active = is_show;
|
|
530
|
+
}
|
|
531
|
+
static async CloseLoading() {
|
|
532
|
+
MainModule.OpenBlockEvents(LayerType.LayerBlockEventsUI, false)
|
|
533
|
+
MainModule.OpenBlockEvents(LayerType.LayerBlockEventsNet, false)
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
static async OpenScene(param: ISceneParam) {
|
|
537
|
+
MainModule.OpenBlockEvents(LayerType.LayerBlockEventsUI, true)
|
|
538
|
+
await new Promise<void>(resolve => { MainModule.gui.progess?.open?.(() => { resolve() }) })
|
|
539
|
+
//关闭所有窗口
|
|
540
|
+
await MainModule.CloseAll([LayerType.LayerUI, LayerType.LayerDialog, LayerType.LayerPopUp, LayerType.LayerGame])
|
|
541
|
+
MainModule.scenesParm.param = param
|
|
542
|
+
let scene = await ResourceManager.loadScene(param.bundleName, param.sceneName, (pro) => { });
|
|
543
|
+
if (scene) {
|
|
544
|
+
ResourceManager.runScene(scene);
|
|
545
|
+
} else {
|
|
546
|
+
param.error?.("加载场景失败");
|
|
547
|
+
}
|
|
548
|
+
MainModule.OpenBlockEvents(LayerType.LayerBlockEventsUI, false)
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
static LoadSprite(sp: Sprite, params: { path: string, bundle?: string, callback?: () => void }) {
|
|
552
|
+
const path = params.path + '/spriteFrame'
|
|
553
|
+
const bundleName = params ? (params.bundle ?? 'game') : "game"
|
|
554
|
+
const sprite = MainModule.getAsset<SpriteFrame>(bundleName, path, SpriteFrame)
|
|
555
|
+
if (sprite) {
|
|
556
|
+
if (isValid(sp, true)) {
|
|
557
|
+
sp.spriteFrame = sprite;
|
|
558
|
+
params?.callback?.()
|
|
559
|
+
}
|
|
560
|
+
else {
|
|
561
|
+
console.log("图片已销毁")
|
|
562
|
+
}
|
|
563
|
+
return;
|
|
564
|
+
}
|
|
565
|
+
MainModule.loadAsset(bundleName, path, SpriteFrame).then((spriteFrame) => {
|
|
566
|
+
if (sp) {
|
|
567
|
+
if (isValid(sp, true)) {
|
|
568
|
+
sp.spriteFrame = spriteFrame;
|
|
569
|
+
params?.callback?.()
|
|
570
|
+
}
|
|
571
|
+
else {
|
|
572
|
+
console.log("图片已销毁")
|
|
573
|
+
}
|
|
574
|
+
}
|
|
575
|
+
})
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
|
|
579
|
+
static LoadSpine(spine: sp.Skeleton, params: { path: string, bundle?: string, callback?: () => void }) {
|
|
580
|
+
const path = params.path
|
|
581
|
+
const bundleName = params ? (params.bundle ?? 'game') : "game"
|
|
582
|
+
const skeletonData = MainModule.getAsset<sp.SkeletonData>(bundleName, path, sp.SkeletonData)
|
|
583
|
+
if (skeletonData) {
|
|
584
|
+
if (spine) {
|
|
585
|
+
if (isValid(spine, true)) {
|
|
586
|
+
spine.skeletonData = skeletonData;
|
|
587
|
+
params?.callback?.()
|
|
588
|
+
}
|
|
589
|
+
}
|
|
590
|
+
return;
|
|
591
|
+
}
|
|
592
|
+
MainModule.loadAsset(bundleName, path, sp.SkeletonData).then((skeletonData) => {
|
|
593
|
+
if (spine) {
|
|
594
|
+
if (isValid(spine, true)) {
|
|
595
|
+
spine.skeletonData = skeletonData;
|
|
596
|
+
params?.callback?.()
|
|
597
|
+
}
|
|
598
|
+
else {
|
|
599
|
+
console.log("动画已销毁")
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
})
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
|
|
606
|
+
|
|
607
|
+
//抖音排行榜数据
|
|
608
|
+
public static UpdatePlayerRankData_tt(count: number) {
|
|
609
|
+
const isdy = MainModule.IsDouYin()
|
|
610
|
+
// console.error('抖音22==', isdy)
|
|
611
|
+
|
|
612
|
+
if (!isdy) { return }
|
|
613
|
+
// const playerLevel = MeCenter.Ins.player.playerLevel;
|
|
614
|
+
// const levelName = MeCenter.Ins.player.levelName;
|
|
615
|
+
// const levelScore = MeCenter.Ins.player.levelScore;
|
|
616
|
+
// const count = MeCenter.Ins.player.levelScore;
|
|
617
|
+
|
|
618
|
+
// const value = `【${levelName}】x${levelScore}星` + ' 大逃杀:' + count + '块'
|
|
619
|
+
const value = '【大逃杀】' + count + '块'
|
|
620
|
+
|
|
621
|
+
if (BYTEDANCE) {
|
|
622
|
+
//一个moba游戏,想要对用户的段位进行排序
|
|
623
|
+
//@ts-ignore
|
|
624
|
+
tt.setImRankData({
|
|
625
|
+
dataType: 1, //成绩为枚举类型,因为段位不是一个数字
|
|
626
|
+
value: value, //该用户段位为白银
|
|
627
|
+
priority: count, //dataType为 1,需要权重,该游戏排序为 青铜(1)、白银(2)、黄金(3)、王者(4),因此此处传2
|
|
628
|
+
extra: "extra",
|
|
629
|
+
zoneId: "default",
|
|
630
|
+
success(res) {
|
|
631
|
+
console.log(`排行榜设置成功: ${res}`);
|
|
632
|
+
},
|
|
633
|
+
fail(res) {
|
|
634
|
+
console.log(`排行榜设置失败: ${res.errMsg}`);
|
|
635
|
+
},
|
|
636
|
+
});
|
|
637
|
+
}
|
|
638
|
+
|
|
639
|
+
}
|
|
640
|
+
|
|
641
|
+
public static IsDouYin() {
|
|
642
|
+
if (BYTEDANCE) {
|
|
643
|
+
//@ts-ignore
|
|
644
|
+
const info = tt.getSystemInfoSync();
|
|
645
|
+
console.log('-------抖音', info.appName);
|
|
646
|
+
const appName = info.appName;
|
|
647
|
+
if (appName.toUpperCase() === "DOUYIN") {//抖音
|
|
648
|
+
// do something
|
|
649
|
+
return true
|
|
650
|
+
}
|
|
651
|
+
else if (appName.toUpperCase() === "TOUTIAO") {//今日头条
|
|
652
|
+
// do something
|
|
653
|
+
}
|
|
654
|
+
else if (appName.toUpperCase() === "TOUTIAO_PRO") {//今日头条专业版
|
|
655
|
+
// do something
|
|
656
|
+
}
|
|
657
|
+
else if (appName.toUpperCase() === 'NEWS_ARTICLE_LITE') {//今日头条极速版
|
|
658
|
+
// do something
|
|
659
|
+
}
|
|
660
|
+
else if (appName.toUpperCase() === "DOUYIN_LITE") {//抖音极速版
|
|
661
|
+
// do something
|
|
662
|
+
return true
|
|
663
|
+
}
|
|
664
|
+
else if (appName.toUpperCase() === "LIVE_STREAM") {//抖音火山版
|
|
665
|
+
// do something
|
|
666
|
+
return true
|
|
667
|
+
}
|
|
668
|
+
else if (appName.toUpperCase() === "TIKTOK") {//TikTok
|
|
669
|
+
// do something
|
|
670
|
+
return true
|
|
671
|
+
}
|
|
672
|
+
else if (appName.toUpperCase() === "MUSICALLY") {//TikTok.M
|
|
673
|
+
// do something
|
|
674
|
+
return true
|
|
675
|
+
}
|
|
676
|
+
else if (appName.toUpperCase() === "XiGua") {//西瓜视频
|
|
677
|
+
// do something
|
|
678
|
+
}
|
|
679
|
+
else if (appName.toUpperCase() === "PPX") {//皮皮虾
|
|
680
|
+
// do something
|
|
681
|
+
}
|
|
682
|
+
else if (appName.toUpperCase() === "automobile") {//懂车帝
|
|
683
|
+
// do something
|
|
684
|
+
}
|
|
685
|
+
else if (appName.toUpperCase() === "DeliverManager") {//巨量
|
|
686
|
+
// do something
|
|
687
|
+
}
|
|
688
|
+
else if (appName.toUpperCase() === "Reading") {//番茄小说
|
|
689
|
+
// do something
|
|
690
|
+
}
|
|
691
|
+
else if (appName.toUpperCase() === "xiaohe") {//小河
|
|
692
|
+
// do something
|
|
693
|
+
}
|
|
694
|
+
return false
|
|
695
|
+
}
|
|
696
|
+
return false
|
|
697
|
+
|
|
698
|
+
|
|
699
|
+
}
|
|
700
|
+
|
|
701
|
+
|
|
702
|
+
//游戏结束动画
|
|
703
|
+
static StartPlayEndAnimation(cameraNode, targetNode, callBackFinish: Function) {
|
|
704
|
+
// 获取相机节点
|
|
705
|
+
// 创建一个Tween对象,让相机沿着路径移动
|
|
706
|
+
const self = this
|
|
707
|
+
const callBack = function () {
|
|
708
|
+
cameraNode.lookAt(targetNode.worldPosition);
|
|
709
|
+
}
|
|
710
|
+
|
|
711
|
+
const list = MainModule.Ins.GetListPos(20, 30, targetNode.worldPosition)
|
|
712
|
+
let list_tw = []
|
|
713
|
+
list.forEach((pos, index) => {
|
|
714
|
+
const tw = tween(cameraNode).to(index === 0 ? 1 : (index === 19 ? 0.5 : 0.2), { worldPosition: pos }, {
|
|
715
|
+
onUpdate: () => {
|
|
716
|
+
callBack();
|
|
717
|
+
}
|
|
718
|
+
}) // 沿着路径移动
|
|
719
|
+
|
|
720
|
+
list_tw.push(tw);
|
|
721
|
+
});
|
|
722
|
+
const ttw = tween(cameraNode)
|
|
723
|
+
list_tw.forEach(element => {
|
|
724
|
+
ttw.then(element);
|
|
725
|
+
});
|
|
726
|
+
|
|
727
|
+
ttw.call(() => {
|
|
728
|
+
callBackFinish && callBackFinish();
|
|
729
|
+
}).start()
|
|
730
|
+
}
|
|
731
|
+
|
|
732
|
+
GetListPos(objectCount: number, circleRadius: number, startPos: Vec3) {
|
|
733
|
+
let list: Vec3[] = []
|
|
734
|
+
// 生成指定数量的物体,并按照圆形排列
|
|
735
|
+
for (let i = 0; i < objectCount; i++) {
|
|
736
|
+
// 计算每个物体在圆周上的角度
|
|
737
|
+
let angle = (i / objectCount) * 2 * Math.PI;
|
|
738
|
+
|
|
739
|
+
// 计算每个物体在圆周上的位置
|
|
740
|
+
let x = startPos.x + circleRadius * Math.cos(angle);
|
|
741
|
+
let z = startPos.z + circleRadius * Math.sin(angle);
|
|
742
|
+
|
|
743
|
+
// 创建物体
|
|
744
|
+
const pos = v3(x, 15, z);
|
|
745
|
+
list.push(pos)
|
|
746
|
+
}
|
|
747
|
+
return list
|
|
748
|
+
}
|
|
749
|
+
|
|
750
|
+
//抛物线
|
|
751
|
+
//计算贝塞尔曲线坐标函数
|
|
752
|
+
static twoBezier(k3, startPos, controlPos, endPos) {
|
|
753
|
+
let twoBezier = (t: number, p1: Vec3, cp: Vec3, p2: Vec3) => {
|
|
754
|
+
let x = (1 - t) * (1 - t) * p1.x + 2 * t * (1 - t) * cp.x + t * t * p2.x;
|
|
755
|
+
let y = (1 - t) * (1 - t) * p1.y + 2 * t * (1 - t) * cp.y + t * t * p2.y;
|
|
756
|
+
return new Vec3(x, y, 0);
|
|
757
|
+
};
|
|
758
|
+
|
|
759
|
+
let result_pos = twoBezier(k3, startPos, controlPos, endPos)
|
|
760
|
+
return result_pos
|
|
761
|
+
}
|
|
762
|
+
static customEaseOutInWithSpeed(t) {
|
|
763
|
+
let speedFactor = 0.6
|
|
764
|
+
if (t < 0.5) {
|
|
765
|
+
return 0.5 * MainModule.customEaseOut(2 * t, speedFactor);
|
|
766
|
+
} else {
|
|
767
|
+
return 0.5 * MainModule.customEaseIn(2 * t - 1, speedFactor) + 0.5;
|
|
768
|
+
}
|
|
769
|
+
}
|
|
770
|
+
|
|
771
|
+
static customEaseOut(t, speedFactor) {
|
|
772
|
+
return 1 - Math.pow(1 - t, 2 * speedFactor);
|
|
773
|
+
}
|
|
774
|
+
|
|
775
|
+
static customEaseIn(t, speedFactor) {
|
|
776
|
+
return Math.pow(t, 2 * speedFactor);
|
|
777
|
+
}
|
|
778
|
+
|
|
779
|
+
//检测碰撞
|
|
780
|
+
static Collision(box1: { x1: number, y1: number, x2: number, y2: number },
|
|
781
|
+
box2: { x1: number, y1: number, x2: number, y2: number }): boolean {
|
|
782
|
+
|
|
783
|
+
|
|
784
|
+
// 碰撞检测逻辑
|
|
785
|
+
return !(box1.x2 <= box2.x1 || box1.x1 >= box2.x2 ||
|
|
786
|
+
box1.y2 <= box2.y1 || box1.y1 >= box2.y2);
|
|
787
|
+
}
|
|
788
|
+
|
|
789
|
+
//朝向
|
|
790
|
+
static CalculateAngle(pointA: Vec3, pointB: Vec3): number {
|
|
791
|
+
// const dx = pointB.x - pointA.x;
|
|
792
|
+
// const dy = pointB.y - pointA.y;
|
|
793
|
+
// return Math.atan2(dy, dx) * (180 / Math.PI);
|
|
794
|
+
|
|
795
|
+
const dx = pointB.x - pointA.x;
|
|
796
|
+
const dy = pointB.y - pointA.y;
|
|
797
|
+
let angle = Math.atan2(dy, dx)
|
|
798
|
+
angle = angle * (180 / Math.PI);
|
|
799
|
+
return angle
|
|
800
|
+
}
|
|
801
|
+
|
|
802
|
+
static LookAtTarget(self: Vec3, target: Vec3) {
|
|
803
|
+
if (target == null) { return }
|
|
804
|
+
// //计算朝向
|
|
805
|
+
let angle = MainModule.CalculateAngle(self, target);
|
|
806
|
+
//物体朝向
|
|
807
|
+
return v3(0, 0, angle);
|
|
808
|
+
}
|
|
809
|
+
/**向量的新的位置 */
|
|
810
|
+
static DirectionPosition(start: Vec3, endPos: Vec3, scalar: number) {
|
|
811
|
+
const direction = endPos.clone().subtract(start);
|
|
812
|
+
const pos = direction.normalize().multiplyScalar(scalar);
|
|
813
|
+
return pos
|
|
814
|
+
}
|
|
815
|
+
|
|
816
|
+
/**
|
|
817
|
+
* 开始抛物线缓动
|
|
818
|
+
* @param item 运动节点
|
|
819
|
+
* @param target_postion 目标位置
|
|
820
|
+
* @param update 更新 运动中回调
|
|
821
|
+
* @param offset_ratio 最高点 的偏移量
|
|
822
|
+
* @param time 动画时间
|
|
823
|
+
*/
|
|
824
|
+
static RunParabolaTween(item: Node, target_postion: Vec3, update: (ratio: number) => void, param?: { offset_ratio?: number, is_random: boolean, time?: number, start_position?: Vec3 }) {
|
|
825
|
+
new ParabolaTween().RunParabolaTween(item, target_postion, update, param);
|
|
826
|
+
}
|
|
827
|
+
|
|
828
|
+
/**
|
|
829
|
+
* ================事件===================
|
|
830
|
+
*/
|
|
831
|
+
static Emit(eventName: string, params: any) {
|
|
832
|
+
EventManager.ins.emit(eventName, params);
|
|
833
|
+
}
|
|
834
|
+
static On(eventName: string, callback: any, target?: any) {
|
|
835
|
+
EventManager.ins.on(eventName, callback, target);
|
|
836
|
+
}
|
|
837
|
+
static Off(eventName: string, callback?: any, target?: any) {
|
|
838
|
+
EventManager.ins.off(eventName, callback, target);
|
|
839
|
+
}
|
|
840
|
+
static OffAll(target: any) {
|
|
841
|
+
EventManager.ins.OffAll(target);
|
|
842
|
+
}
|
|
843
|
+
//#region 记录打开的窗口
|
|
844
|
+
// 关闭指定窗口
|
|
845
|
+
static CloseWindow(className: string): boolean {
|
|
846
|
+
const instance = MainModule.Ins;
|
|
847
|
+
const window = instance.openedWindows.get(className);
|
|
848
|
+
if (window) {
|
|
849
|
+
try {
|
|
850
|
+
// 调用窗口的关闭方法(如果存在)
|
|
851
|
+
if (typeof (window as any).onClose === 'function') {
|
|
852
|
+
(window as any).onClose();
|
|
853
|
+
}
|
|
854
|
+
// 销毁节点
|
|
855
|
+
if (window.node && isValid(window.node, true)) {
|
|
856
|
+
window.node.destroy();
|
|
857
|
+
}
|
|
858
|
+
// 清除记录
|
|
859
|
+
instance.openedWindows.delete(className);
|
|
860
|
+
instance.openedWindowsConfig.delete(className);
|
|
861
|
+
return true;
|
|
862
|
+
} catch (error) {
|
|
863
|
+
console.error(`关闭窗口 ${className} 时出错:`, error);
|
|
864
|
+
return false;
|
|
865
|
+
}
|
|
866
|
+
} else {
|
|
867
|
+
console.warn(`窗口 ${className} 未找到或未打开`);
|
|
868
|
+
return false;
|
|
869
|
+
}
|
|
870
|
+
}
|
|
871
|
+
|
|
872
|
+
// 设置窗口关闭监听
|
|
873
|
+
private setupCloseListener(view: Component, className: string) {
|
|
874
|
+
view.node["old_destroy"] = view.node.destroy
|
|
875
|
+
view.node.destroy = () => {
|
|
876
|
+
this.removeWindowRecord(className);
|
|
877
|
+
return view.node["old_destroy"]()
|
|
878
|
+
}
|
|
879
|
+
// 监听节点销毁事件
|
|
880
|
+
// view.node.once(Node.EventType.NODE_DESTROYED, () => {
|
|
881
|
+
// this.removeWindowRecord(className);
|
|
882
|
+
// });
|
|
883
|
+
}
|
|
884
|
+
|
|
885
|
+
ShowLayerUI(config: IBundleConfig, is_show: boolean) {
|
|
886
|
+
if (config.layer === LayerType.LayerUI) {
|
|
887
|
+
const list_layer = MainModule.Ins.openWindowLayer.get(config.layer)
|
|
888
|
+
if (list_layer && list_layer.length > 0) {
|
|
889
|
+
const last_name = list_layer[list_layer.length - 1];
|
|
890
|
+
const com = this.openedWindows.get(last_name);
|
|
891
|
+
if (com && com.isValid) {
|
|
892
|
+
com.node.active = is_show;
|
|
893
|
+
}
|
|
894
|
+
} else {
|
|
895
|
+
MainModule.gui.GetLayer(LayerType.LayerGame).active = true;
|
|
896
|
+
}
|
|
897
|
+
}
|
|
898
|
+
}
|
|
899
|
+
// 移除窗口记录
|
|
900
|
+
private removeWindowRecord(className: string) {
|
|
901
|
+
const config = MainModule.Ins.openedWindowsConfig.get(className);
|
|
902
|
+
if (config.layer === LayerType.LayerUI) {
|
|
903
|
+
const list_layer = MainModule.Ins.openWindowLayer.get(config.layer)
|
|
904
|
+
list_layer.pop();//移除最后一个
|
|
905
|
+
this.ShowLayerUI(config, true)
|
|
906
|
+
console.log('LayerType.LayerUI 移除窗口记录:', className, list_layer);
|
|
907
|
+
}
|
|
908
|
+
|
|
909
|
+
this.openedWindows.delete(className);
|
|
910
|
+
this.openedWindowsConfig.delete(className);
|
|
911
|
+
MainModule.Emit(SystemMessage.CloseWindow, className)
|
|
912
|
+
}
|
|
913
|
+
|
|
914
|
+
|
|
915
|
+
// 通过配置关闭窗口
|
|
916
|
+
static CloseWindowTarget(config: IBundleConfig): boolean {
|
|
917
|
+
const className = config.path.split('/').pop();
|
|
918
|
+
return MainModule.CloseWindow(className);
|
|
919
|
+
}
|
|
920
|
+
|
|
921
|
+
// 关闭所有窗口
|
|
922
|
+
static CloseAllWindows(): number {
|
|
923
|
+
const instance = MainModule.Ins;
|
|
924
|
+
let closedCount = 0;
|
|
925
|
+
|
|
926
|
+
// 创建副本以避免在迭代时修改Map
|
|
927
|
+
const windowsToClose = new Array(...instance.openedWindows.entries());
|
|
928
|
+
|
|
929
|
+
for (const [className, window] of windowsToClose) {
|
|
930
|
+
if (MainModule.CloseWindow(className)) {
|
|
931
|
+
closedCount++;
|
|
932
|
+
}
|
|
933
|
+
}
|
|
934
|
+
|
|
935
|
+
console.log(`共关闭 ${closedCount} 个窗口`);
|
|
936
|
+
return closedCount;
|
|
937
|
+
}
|
|
938
|
+
|
|
939
|
+
// 检查窗口是否已打开
|
|
940
|
+
static IsWindowOpen(className: string): boolean {
|
|
941
|
+
return MainModule.Ins.openedWindows.has(className);
|
|
942
|
+
}
|
|
943
|
+
|
|
944
|
+
// 获取已打开的窗口实例
|
|
945
|
+
static GetOpenWindow<T extends Component>(config: IBundleConfig): T | null {
|
|
946
|
+
const className = config.path.split('/').pop();
|
|
947
|
+
const window = MainModule.Ins.openedWindows.get(className);
|
|
948
|
+
return window ? window as T : null;
|
|
949
|
+
}
|
|
950
|
+
|
|
951
|
+
// 获取所有已打开的窗口名称
|
|
952
|
+
static GetOpenedWindowNames(): string[] {
|
|
953
|
+
return Array.from(MainModule.Ins.openedWindows.keys());
|
|
954
|
+
}
|
|
955
|
+
|
|
956
|
+
/**任务进度队列 */
|
|
957
|
+
static PromiseQueue<T>(promises: Promise<T>[], onProgress: (completed: number, total: number) => void): Promise<T[]> {
|
|
958
|
+
const total = promises.length;
|
|
959
|
+
let completed = 0;
|
|
960
|
+
|
|
961
|
+
// 包装每个 Promise,以便在完成时触发进度更新
|
|
962
|
+
const trackedPromises = promises.map(promise =>
|
|
963
|
+
promise.then(result => {
|
|
964
|
+
completed++;
|
|
965
|
+
onProgress(completed, total); // 更新进度
|
|
966
|
+
return result;
|
|
967
|
+
})
|
|
968
|
+
);
|
|
969
|
+
|
|
970
|
+
// 返回一个新的 Promise.all,确保所有任务完成后返回结果
|
|
971
|
+
return Promise.all(trackedPromises);
|
|
972
|
+
}
|
|
973
|
+
/**播放skpine动画 */
|
|
974
|
+
static PlaySpine(skeleton: sp.Skeleton, animations: { name: string, loop?: boolean, call?: (name?: string) => void, event?: (name?: string) => void }[]) {
|
|
975
|
+
MainModule.PlaySpine(skeleton, animations);
|
|
976
|
+
}
|
|
977
|
+
|
|
978
|
+
//#region 运行补丁
|
|
979
|
+
// 默认实现函数
|
|
980
|
+
static DefaultFunction(param?: any, callBack?: Function) {
|
|
981
|
+
console.warn('调用了默认方法,可能该方法未实现', param);
|
|
982
|
+
callBack?.();
|
|
983
|
+
}
|
|
984
|
+
/**
|
|
985
|
+
* 为 target 补全缺失的方法
|
|
986
|
+
* @param target 目标类/对象
|
|
987
|
+
s */
|
|
988
|
+
static RegisterModule(target: any) {
|
|
989
|
+
if (!target) { return }
|
|
990
|
+
const allKeys = Object.keys(target);
|
|
991
|
+
for (const key of allKeys) {
|
|
992
|
+
const desc = Object.getOwnPropertyDescriptor(target, key);
|
|
993
|
+
if (desc?.get || desc?.set) continue; // ✅ 正确跳过 getter/setter
|
|
994
|
+
if (!desc?.writable) continue; // ✅ 跳过只读(防御性)
|
|
995
|
+
if (typeof target[key] !== 'function') { // ⚠️ 问题在这里!
|
|
996
|
+
target[key] = MainModule.DefaultFunction;
|
|
997
|
+
}
|
|
998
|
+
}
|
|
999
|
+
}
|
|
1000
|
+
|
|
1001
|
+
//#region 监听模块消息
|
|
1002
|
+
static OnRequstNet(param: { open: (finish: (isOk: boolean) => void) => void }) {
|
|
1003
|
+
MainModule.http.open = param.open;
|
|
1004
|
+
}
|
|
1005
|
+
|
|
1006
|
+
static OnLoading(param: { open: (finish: () => void) => void, close: () => void }) {
|
|
1007
|
+
MainModule.gui.loading_call = param;
|
|
1008
|
+
}
|
|
1009
|
+
|
|
1010
|
+
static OnProgess(param: { open: (finish: () => void) => void, close: () => void, progess: (progress: number) => void }) {
|
|
1011
|
+
MainModule.gui.progess = param;
|
|
1012
|
+
}
|
|
1013
|
+
}
|
|
1014
|
+
|
|
1015
|
+
window.MainModule = MainModule;
|
|
1016
|
+
|
|
1017
|
+
|
|
1018
|
+
|
|
1019
|
+
|