PreLoader.js 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726
  1. var PreLoader = cc.Class({
  2. ctor: function () {
  3. this.m_MapBundle = {};
  4. this.m_MapPrefab = {};
  5. this.m_MapAudio = {};
  6. this.m_MapRes = {};
  7. this.m_szToolPhp = 'Tool.php';
  8. this.m_szRemote = 'remote';
  9. // this.m_sBundles = new Array("10017","21201", "Chat_2", "GamePublic_3", "GameSetting_2", "GPS_2", "Jetton_2",
  10. // "PublicMJ_2", "Activity", "AgreeMent", "Alert_6", "BindPhone", "Club", "ClubAndroid", "Com_6", "CSY", "DLG_7", "FilterNode",
  11. // "GameRecord_2", "InviteCode", "Login", "Pay","MailInfo", "PublicAudio", "RealAuth", "Room", "SelfInfo", "Service",
  12. // "Setting_3", "Share", "Sign", "TurnTable", "UpdateManager_7");
  13. this.m_sBundles = new Array("21201", "Chat_2", "GamePublic_3", "GameSetting_2", "Jetton_2",
  14. "PublicMJ_2", "Activity", "AgreeMent", "Alert_6", "BindPhone", "Club", "ClubAndroid", "Com_6", "CSY", "DLG_7", "FilterNode",
  15. "GameRecord_2", "InviteCode", "Login", "MailInfo", "PublicAudio", "Room", "SelfInfo", "Service",
  16. "Setting_3", "Share", "Sign", "TurnTable", "Store", "UpdateManager_7");
  17. },
  18. Init: function (CallFunc) {
  19. // this.LoadBundleVer(CallFunc);
  20. if (cc.sys.isBrowser) {
  21. this.loadLocalBundle(CallFunc);
  22. return;
  23. }
  24. this.getAppVersion((url) => {
  25. if (window.IS_UPDATE) {
  26. // this.LoadBundleVer(CallFunc)
  27. CallFunc(url)
  28. } else {
  29. this.loadLocalBundle(CallFunc)
  30. }
  31. });
  32. },
  33. loadLocalBundle: function (CallFunc) {
  34. //console.log("this.m_MapBundle-------2", this.m_MapPrefab, this.m_MapAudio, this.m_MapRes)
  35. let Cnt = 0;
  36. let Index = 0;
  37. for (let index = 0; index < this.m_sBundles.length; index++) {
  38. this.m_MapBundle[this.m_sBundles[index]] = {
  39. Name: this.m_sBundles[index],
  40. Ver: 0,
  41. Bundle: null,
  42. PrefabCnt: 0,
  43. }
  44. Cnt++;
  45. }
  46. // console.log("this.m_MapBundle---------3")
  47. for (let index = 0; index < this.m_sBundles.length; index++) {
  48. let BundleName = this.m_sBundles[index];
  49. cc.assetManager.loadBundle(BundleName, "", function (err, bundle) {
  50. if (err) {
  51. return console.error(err);
  52. }
  53. for (let i in bundle._config.paths._map) {
  54. let asset = bundle._config.paths._map[i];
  55. for (let j = 0; j < asset.length; j++) {
  56. let Name = asset[j].path.substring(asset[j].path.lastIndexOf('/') + 1, asset[j].path.length);
  57. let Path = asset[j].path.substring(asset[j].path.lastIndexOf('/') + 1, 0);
  58. let pathSpl = Path.split('/')
  59. let isTo = false;
  60. let isImage = false;
  61. for (let p = 0; p < pathSpl.length; p++) {
  62. if (pathSpl[p] == "Prefab") {
  63. if (!this.m_MapPrefab[Name]) {
  64. this.m_MapPrefab[Name] = {
  65. BundleName: BundleName,
  66. Name: Name,
  67. ComName: Name,
  68. Path: Path,
  69. Prefab: null,
  70. Type: cc.Prefab,
  71. };
  72. }
  73. isTo = true;
  74. break;
  75. } else if (pathSpl[p] == 'Audio' || BundleName == "PublicAudio") {
  76. if (!this.m_MapAudio[BundleName]) this.m_MapAudio[BundleName] = {};
  77. var AudioName = `${Path}${Name}`.replace(/\//g, '_');
  78. this.m_MapAudio[BundleName][AudioName] = {
  79. BundleName: BundleName,
  80. Name: Name,
  81. Path: Path,
  82. Audio: null,
  83. Type: cc.AudioClip,
  84. };
  85. isTo = true;
  86. break;
  87. } else if (pathSpl[p] == 'Image') {
  88. isImage = true;
  89. break;
  90. }
  91. }
  92. if (isTo == false) {
  93. if (!this.m_MapRes[BundleName]) {
  94. this.m_MapRes[BundleName] = {};
  95. }
  96. let ResName = `${Path}${Name}`.replace(/\//g, '_');
  97. //let replacedStr = asset[j].ctor.name.replace("_", ".");
  98. this.m_MapRes[BundleName][ResName] = {
  99. BundleName: BundleName,
  100. Name: Name,
  101. Path: Path,
  102. Body: null,
  103. Type: isImage ? cc.SpriteFrame : null,
  104. // Type: eval(replacedStr),
  105. };
  106. }
  107. }
  108. }
  109. Index++;
  110. if (Index == Cnt && CallFunc) CallFunc();
  111. }.bind(this));
  112. }
  113. //console.log("this.m_MapBundle-------3", this.m_MapPrefab, this.m_MapAudio, this.m_MapRes)
  114. },
  115. getAppVersion: function (cb) {
  116. let webUrl = `${window.PHP_HOME}/${this.m_szToolPhp}`;
  117. if (cc.sys.OS_ANDROID == cc.sys.os) {
  118. webUrl += '?GetMark=3';
  119. } else {
  120. webUrl += '?GetMark=2';
  121. }
  122. WebCenter.GetData(webUrl, 0, function (data) {
  123. let pData = JSON.parse(data);
  124. if (pData) {
  125. window.APP_VERSION_ON_LINE = pData.verIos
  126. window.IS_UPDATE = pData.IS_UPDATE == "1" ? true : false;
  127. console.log("window.APP_VERSION_ON_LINE----", pData.verIos, pData.IS_UPDATE, window.IS_UPDATE)
  128. if (window.isAppLastVersion()) {
  129. console.log("GetMark=2----版本新")
  130. } else {
  131. console.log("GetMark=2----版本老旧")
  132. window.IS_UPDATE = true;
  133. }
  134. cb(decodeURIComponent(pData.url));
  135. }
  136. // cb()
  137. }.bind(this))
  138. console.log("window.APP_BOTTOM_VER--", window.APP_BOTTOM_VER_ANDROID, window.APP_BOTTOM_VER_IOS)
  139. },
  140. LoadBundleVer: function (CallFunc) {
  141. var webUrl = `${window.PHP_HOME}/${this.m_szToolPhp}`;
  142. if (cc.share.IsH5_WX()) {
  143. webUrl += '?GetMark=1';
  144. this.m_szRemote = 'game/assets';
  145. } else {
  146. webUrl += '?GetMark=0';
  147. }
  148. WebCenter.GetData(webUrl, 0, function (data) {
  149. var Cnt = 0;
  150. var Index = 0;
  151. var pData = JSON.parse(data);
  152. // console.log("pData-------",pData)
  153. if (pData) {
  154. for (var i in pData) {
  155. if (i == 'RemotePath') {
  156. this.m_szRemote = pData[i];
  157. continue;
  158. }
  159. if (pData[i].length == 0) continue;
  160. var ver = pData[i][0].substring(pData[i][0].indexOf('.') + 1, pData[i][0].lastIndexOf('.'));
  161. if (this.m_MapBundle[i]) {
  162. this.m_MapBundle[i].Ver = ver;
  163. this.m_MapBundle[i].PrefabCnt = 0;
  164. }
  165. else this.m_MapBundle[i] = {
  166. Name: i,
  167. Ver: ver,
  168. Bundle: null,
  169. PrefabCnt: 0,
  170. };
  171. Cnt++;
  172. }
  173. // console.log("this.m_MapBundle-------", this.m_MapBundle)
  174. }
  175. for (var i in this.m_MapBundle) {
  176. var UrlRemote = `${window.PHP_HOME}/${this.m_szRemote}/${this.m_MapBundle[i].Name}/config.${this.m_MapBundle[i].Ver}.json`;
  177. if (window.LOG_NET_DATA) console.log(` ###### LoadBundleVer ${UrlRemote} `);
  178. cc.assetManager.loadRemote(UrlRemote, function (a, b, c) {
  179. //console.log("abc-------", a, b, c)
  180. var BundleName = b.json.name;
  181. for (var j in b.json.paths) {
  182. if (!b.json.types[b.json.paths[j][1]]) continue;
  183. var Name = b.json.paths[j][0].substring(b.json.paths[j][0].lastIndexOf('/') + 1, b.json.paths[j][0].length);
  184. var Path = b.json.paths[j][0].substring(b.json.paths[j][0].lastIndexOf('/') + 1, 0);
  185. if (b.json.types[b.json.paths[j][1]] == 'cc.Prefab') {
  186. if (!this.m_MapPrefab[Name]) {
  187. this.m_MapPrefab[Name] = {
  188. BundleName: BundleName,
  189. Name: Name,
  190. ComName: Name,
  191. Path: Path,
  192. Prefab: null,
  193. Type: cc.Prefab,
  194. };
  195. }
  196. this.m_MapBundle[BundleName].PrefabCnt++;
  197. } else if (b.json.types[b.json.paths[j][1]] == 'cc.AudioClip') {
  198. if (!this.m_MapAudio[BundleName]) this.m_MapAudio[BundleName] = {};
  199. var AudioName = `${Path}${Name}`.replace(/\//g, '_');
  200. this.m_MapAudio[BundleName][AudioName] = {
  201. BundleName: BundleName,
  202. Name: Name,
  203. Path: Path,
  204. Audio: null,
  205. Type: cc.AudioClip,
  206. };
  207. } else {
  208. if (!this.m_MapRes[BundleName]) this.m_MapRes[BundleName] = {};
  209. var ResName = `${Path}${Name}`.replace(/\//g, '_');
  210. this.m_MapRes[BundleName][ResName] = {
  211. BundleName: BundleName,
  212. Name: Name,
  213. Path: Path,
  214. Body: null,
  215. Type: eval(b.json.types[b.json.paths[j][1]]),
  216. };
  217. }
  218. }
  219. Index++;
  220. if (Index == Cnt && CallFunc) CallFunc();
  221. }.bind(this));
  222. }
  223. //console.log("this.m_MapBundle-------2", this.m_MapPrefab, this.m_MapAudio, this.m_MapRes)
  224. }.bind(this));
  225. },
  226. _LoadBundle: function (BundleName, Callback, Param) {
  227. //console.log("_LoadBundle---1----",BundleName)
  228. if (this.m_MapBundle[BundleName].Bundle == 'loading') return 'loading';
  229. if (this.m_MapBundle[BundleName].Bundle) {
  230. if (window.LOG_NET_DATA) console.log(` ###### _LoadBundle => ${BundleName} is loaded, to loadprefab `);
  231. if (Callback) Callback(this.m_MapBundle[BundleName].Bundle, Param);
  232. } else {
  233. this.m_MapBundle[BundleName].Bundle = 'loading';
  234. var UrlBundle = `${BundleName}`;
  235. var Version = null;
  236. if (cc.sys.isNative && window.IS_UPDATE) {
  237. UrlBundle = `${window.PHP_HOME}/${this.m_szRemote}/${BundleName}`;
  238. Version = new Object();
  239. Version.version = this.m_MapBundle[BundleName].Ver;
  240. }
  241. if (window.LOG_NET_DATA) console.log(` ###### _LoadBundle => ${UrlBundle} `);
  242. cc.assetManager.loadBundle(UrlBundle, Version, function (err, bundle) {
  243. if (err) {
  244. this.m_MapBundle[BundleName].Bundle = null;
  245. this.m_MapBundle[BundleName].Error = err;
  246. if (window.LOG_NET_DATA) (`loadBundle[${BundleName}] error ${err}`);
  247. if (window.trapExceptional) {
  248. window.trapExceptional(`_LoadBundle ${BundleName} ${err}`, `Preloader`);
  249. }
  250. return null;
  251. }
  252. if (window.LOG_NET_DATA) console.log(` ###### _LoadBundle success => ${BundleName} `);
  253. cc.sys.localStorage.setItem(`${window.Key_ABVersion}_${BundleName}`, this.m_MapBundle[BundleName].Ver);
  254. this.m_MapBundle[BundleName].Bundle = (bundle);
  255. this.m_MapBundle[BundleName].Error = null;
  256. if (Param) Param.BundleName = BundleName;
  257. if (Callback) Callback(bundle, Param);
  258. }.bind(this));
  259. }
  260. },
  261. _LoadPrefab: function (PrefabName, Bundle, OnSuccess, OnFalied, Param) {
  262. if (this.m_MapPrefab[PrefabName].Prefab == 'loading') return 'loading';
  263. this.m_MapPrefab[PrefabName].Prefab = 'loading';
  264. var UrlPrefab = `${this.m_MapPrefab[PrefabName].Path}${this.m_MapPrefab[PrefabName].Name}`;
  265. if (window.LOG_NET_DATA) console.log(` ###### _LoadPrefab => loadPrefab url ${UrlPrefab} `);
  266. Bundle.load(UrlPrefab, cc.Prefab, function (a, b, c) {
  267. cc.director.emit('UpdateItemProgress', a, b);
  268. }.bind(this), function (err, prefab) {
  269. if (err) {
  270. this.m_MapPrefab[PrefabName].Prefab = null;
  271. this.m_MapPrefab[PrefabName].Error = err;
  272. console.log(`_loadPrefab[${PrefabName}] error ${err}`);
  273. if (OnFalied) OnFalied(err);
  274. return null;
  275. }
  276. if (window.LOG_NET_DATA) console.log(` ###### _LoadPrefab success => ${PrefabName} => ${this.m_MapPrefab[PrefabName].Path}${this.m_MapPrefab[PrefabName].Name} `);
  277. this.m_MapPrefab[PrefabName].Prefab = prefab;
  278. this.m_MapPrefab[PrefabName].Error = null;
  279. if (OnSuccess) OnSuccess(prefab, Param);
  280. }.bind(this));
  281. },
  282. LoadPrefab: function (Key, OnSuccess, OnFalied) {
  283. if (!this.m_MapPrefab[Key]) return null;
  284. var szBundleName = this.m_MapPrefab[Key].BundleName;
  285. if (!szBundleName) return null;
  286. if (this.m_MapBundle[szBundleName].Bundle == 'loading') {
  287. if (window.LOG_NET_DATA) console.log(` ###### LoadPrefab => bundle ${szBundleName} is loading `);
  288. return null;
  289. }
  290. if (this.m_MapPrefab[Key].Prefab == 'loading') {
  291. if (window.LOG_NET_DATA) console.log(` ###### LoadPrefab => prefab ${Key} is loading `);
  292. return null;
  293. }
  294. if (this.m_MapPrefab[Key].Prefab) {
  295. var TempPre = cc.instantiate(this.m_MapPrefab[Key].Prefab).getComponent(this.m_MapPrefab[Key].ComName);
  296. if (!TempPre) {
  297. this.m_MapPrefab[Key].Prefab = null;
  298. if (window.LOG_NET_DATA) console.log(` ###### LoadPrefab faild => reload prefab ${Key} `);
  299. this.LoadPrefab(Key, OnSuccess, OnFalied);
  300. return null;
  301. }
  302. if (OnSuccess) OnSuccess(TempPre);
  303. return TempPre;
  304. } else {
  305. this._LoadBundle(szBundleName, function (Bundle, Param1) {
  306. this._LoadPrefab(Key, Bundle, function (prefab, Param2) {
  307. var TempPre = cc.instantiate(prefab).getComponent(this.m_MapPrefab[Param1.Key].ComName);
  308. if (Param1 && Param1.OnSuccess) Param1.OnSuccess(TempPre);
  309. }.bind(this), function (err) {
  310. if (Param1 && Param1.OnFalied) Param1.OnFalied(err);
  311. else if (window.trapExceptional) {
  312. window.trapExceptional(`Loadprefab ${Param1.Key} ${err}`, `Preloader`);
  313. }
  314. },);
  315. }.bind(this), { Key: Key, OnSuccess: OnSuccess, OnFalied: OnFalied });
  316. }
  317. return null;
  318. },
  319. LoadAudio: function (Key, Path, KindID, Callback, Param) {
  320. this.LoadAudioByBundle(KindID, Key, Path, Callback, Param);
  321. },
  322. LoadPublicAudio: function (Key, Callback, Param) {
  323. this.LoadAudioByBundle('PublicAudio', Key, null, Callback, Param);
  324. },
  325. LoadAudioByBundle: function (BundleName, Key, Path, Callback, Param) {
  326. if (!this.m_MapAudio[BundleName]) return null;
  327. for (var i in this.m_MapAudio[BundleName]) {
  328. var UrlAudio = `${this.m_MapAudio[BundleName][i].Path}${this.m_MapAudio[BundleName][i].Name}`;
  329. if (Path) { if (Path != UrlAudio) continue; }
  330. else { if (Key != i) continue; }
  331. if (this.m_MapBundle[BundleName].Bundle == 'loading') break;
  332. if (this.m_MapBundle[BundleName].Bundle) {
  333. this.m_MapBundle[BundleName].Bundle.load(UrlAudio, cc.AudioClip, function (a, b, c) { }.bind(this), function (err, audio) {
  334. if (!err && Callback) Callback(audio, Param);
  335. }.bind(this));
  336. } else {
  337. this._LoadBundle(BundleName, function (Bundle) {
  338. this.m_MapBundle[BundleName].Bundle.load(UrlAudio, cc.AudioClip, function (a, b, c) { }.bind(this), function (err, audio) {
  339. if (!err && Callback) Callback(audio, Param);
  340. }.bind(this));
  341. }.bind(this));
  342. }
  343. break;
  344. }
  345. },
  346. LoadGamePrefab: function (Key, Callback) {
  347. return this.LoadPrefab(Key, Callback);
  348. },
  349. LoadByGame: function (KindID) {
  350. },
  351. LoadPrefabByBundle: function (BundleName) {
  352. for (var i in this.m_MapPrefab) {
  353. if (this.m_MapPrefab[i].BundleName != BundleName) continue;
  354. this.LoadPrefab(i);
  355. }
  356. },
  357. LoadResByBundle: function (BundleName, path, Callback) {
  358. this._LoadBundle(BundleName, function (Bundle) {
  359. Bundle.loadDir(path, cc.SpriteFrame, function (err, assets) {
  360. console.log(assets);
  361. if (Callback) Callback();
  362. }.bind(this));
  363. }.bind(this));
  364. },
  365. LoadRes: function (Name, BundleName, Callback, Param) {
  366. if (!this.m_MapRes[BundleName]) return null;
  367. if (!this.m_MapRes[BundleName][Name]) return null;
  368. if (this.m_MapRes[BundleName][Name].Body) {
  369. if (Callback) Callback(this.m_MapRes[BundleName][Name].Body, Param);
  370. return this.m_MapRes[BundleName][Name].Body;
  371. }
  372. if (Callback && this.m_MapRes[BundleName][Name]) {
  373. if (!!!this.m_MapRes[BundleName][Name].CallbackList) this.m_MapRes[BundleName][Name].CallbackList = [];
  374. this.m_MapRes[BundleName][Name].CallbackList.push({
  375. Callback: Callback,
  376. Param: Param
  377. })
  378. }
  379. return this._LoadBundle(BundleName, function (Bundle) {
  380. for (var i in this.m_MapRes[BundleName]) {
  381. if (this.m_MapRes[BundleName][i].CallbackList && this.m_MapRes[BundleName][i].CallbackList.length > 0) {
  382. this._LoadRes(Bundle, `${this.m_MapRes[BundleName][i].Path}${this.m_MapRes[BundleName][i].Name}`, i, BundleName);
  383. }
  384. }
  385. }.bind(this), Param);
  386. },
  387. _LoadRes: function (Bundle, Url, Name, BundleName, Callback, Param) {
  388. Bundle.load(Url, this.m_MapRes[BundleName][Name].Type, function (a, b, c) { }.bind(this), function (err, res) {
  389. if (err) {
  390. this.m_MapRes[BundleName][Name].Body = null;
  391. this.m_MapRes[BundleName][Name].Error = err;
  392. console.log(`_LoadRes[ ${BundleName} => ${Name} ] error ${err}`);
  393. if (window.trapExceptional) {
  394. window.trapExceptional(`_LoadRes ${BundleName} => ${Name} ${err}`, `Preloader`);
  395. }
  396. return;
  397. }
  398. this.m_MapRes[BundleName][Name].Body = res;
  399. for (var j in this.m_MapRes[BundleName][Name].CallbackList) {
  400. this.m_MapRes[BundleName][Name].CallbackList[j].Callback(this.m_MapRes[BundleName][Name].Body, this.m_MapRes[BundleName][Name].CallbackList[j].Param);
  401. }
  402. this.m_MapRes[BundleName][Name].CallbackList = new Array();
  403. }.bind(this));
  404. },
  405. Exist_Res: function (BundleName, Name) {
  406. if (!this.m_MapRes[BundleName]) return false;
  407. if (!this.m_MapRes[BundleName][Name]) return false;
  408. return true;
  409. },
  410. Exist_Prefab: function (Name) {
  411. if (!this.m_MapPrefab[Name]) return false;
  412. var BundleName = this.m_MapPrefab[Name].BundleName;
  413. if (!BundleName) return false;
  414. if (!this.m_MapBundle[BundleName]) return false;
  415. return true;
  416. },
  417. _GetGameSupport: function (wKindID) {
  418. var LoadArray = ['GamePublic_3', 'Chat_2', 'GPS_2', 'Jetton_2', 'GameSetting_2'];
  419. if (!wKindID) {
  420. LoadArray.push('GamePHZ_2');
  421. LoadArray.push('PublicMJ_2');
  422. } else {
  423. // for (var i in window.GameList_MJ_New) {
  424. // if (window.GameList_MJ_New[i] == wKindID) {
  425. // LoadArray.push('GameMJ_2');
  426. // break;
  427. // }
  428. // }
  429. for (var i in window.GameList_MJ) {
  430. if (window.GameList_MJ[i] == wKindID) {
  431. LoadArray.push('PublicMJ_2');
  432. break;
  433. }
  434. }
  435. // for (var i in window.GameList_PHZ){
  436. // if (window.GameList_PHZ[i] == wKindID) {
  437. // LoadArray.push('GamePHZ_2');
  438. // break;
  439. // }
  440. // }
  441. }
  442. return LoadArray;
  443. },
  444. StartPreload: function (bLoadLobby, wKindID) {
  445. this.m_nPrefabCnt = 0;
  446. this.m_nLoadCnt = 0;
  447. this.m_LoadArray = [];
  448. this.m_GameSupport = this._GetGameSupport(wKindID);
  449. if (bLoadLobby) {
  450. for (var i = 7; i > 1; --i) {
  451. for (var j in this.m_MapPrefab) {
  452. var BundleName = this.m_MapPrefab[j].BundleName;
  453. var bLoad = true;
  454. for (var k in this.m_GameSupport) {
  455. if (BundleName == this.m_GameSupport[k]) {
  456. bLoad = false;
  457. break;
  458. }
  459. }
  460. if (!bLoad) continue;
  461. var temp = BundleName.split('_');
  462. if (temp.length < 2) continue;
  463. if (Number(temp[1]) != i) continue;
  464. this.m_nPrefabCnt++;
  465. this.m_LoadArray.push(this.m_MapPrefab[j].Name);
  466. }
  467. }
  468. for (var j in this.m_MapPrefab) {
  469. var BundleName = this.m_MapPrefab[j].BundleName;
  470. var bLoad = true;
  471. if (Number(BundleName) > 0) bLoad = false;
  472. else {
  473. for (var k in this.m_GameSupport) {
  474. if (BundleName == this.m_GameSupport[k]) {
  475. bLoad = false;
  476. break;
  477. }
  478. }
  479. }
  480. if (!bLoad) continue;
  481. var temp = BundleName.split('_');
  482. if (temp.length > 1) continue;
  483. this.m_nPrefabCnt++;
  484. this.m_LoadArray.push(this.m_MapPrefab[j].Name);
  485. }
  486. for (var i in window.GameList) {
  487. this.m_LoadArray.push(`SubRoom_${i}`);
  488. }
  489. }
  490. if (wKindID) {
  491. for (var i = 7; i > 1; --i) {
  492. for (var j in this.m_MapPrefab) {
  493. var BundleName = this.m_MapPrefab[j].BundleName;
  494. var bLoad = false;
  495. for (var k in this.m_GameSupport) {
  496. if (BundleName == this.m_GameSupport[k]) {
  497. bLoad = true;
  498. break;
  499. }
  500. }
  501. if (!bLoad) continue;
  502. var temp = BundleName.split('_');
  503. if (temp.length < 2) continue;
  504. if (Number(temp[1]) != i) continue;
  505. this.m_nPrefabCnt++;
  506. this.m_LoadArray.push(this.m_MapPrefab[j].Name);
  507. }
  508. }
  509. for (var j in this.m_MapPrefab) {
  510. var BundleName = this.m_MapPrefab[j].BundleName;
  511. if (BundleName != wKindID) continue;
  512. var temp = BundleName.split('_');
  513. if (temp.length > 1) continue;
  514. this.m_nPrefabCnt++;
  515. this.m_LoadArray.push(this.m_MapPrefab[j].Name);
  516. }
  517. return this.m_LoadArray;
  518. }
  519. return this.CheckVer(this.m_LoadArray);
  520. },
  521. NextPreload: function (Name, OnSuccess, OnFalied) {
  522. this.LoadPrefab(Name, OnSuccess, OnFalied);
  523. },
  524. CheckVer: function (LoadArray) {
  525. for (var i = LoadArray.length - 1; i >= 0; --i) {
  526. if (!this.m_MapPrefab[LoadArray[i]]) {
  527. LoadArray.splice(i, 1);
  528. } else {
  529. var BundleName = this.m_MapPrefab[LoadArray[i]].BundleName;
  530. var Ver = null;
  531. if (this.m_MapBundle[BundleName]) Ver = this.m_MapBundle[BundleName].Ver;
  532. var LocalVer = null;
  533. LocalVer = cc.sys.localStorage.getItem(`${window.Key_ABVersion}_${BundleName}`);
  534. if (Ver && LocalVer && Ver == LocalVer) LoadArray.splice(i, 1);
  535. }
  536. }
  537. return LoadArray;
  538. }
  539. });
  540. cc.gPreLoader = new PreLoader();
  541. var SoundHead = '';
  542. var GSoundHead = '';
  543. //音頻
  544. var tagSoundRes = cc.Class({
  545. ctor: function () {
  546. this.m_SoundMap = new Object();
  547. this.m_GameSoundMap = new Object();
  548. this.m_GameIndex = null;
  549. },
  550. //播放声音
  551. PlaySound: function (Key) {
  552. var value = this.GetSoundVolume();
  553. // if (value == 0) return;
  554. if (value == 0) {
  555. return;
  556. };
  557. if (this.m_SoundMap[Key]) {
  558. cc.audioEngine.play(this.m_SoundMap[Key], false, value);
  559. } else {
  560. this.LoadSound(Key, function (audio) {
  561. cc.audioEngine.play(audio, false, value)
  562. }.bind(this));
  563. }
  564. },
  565. //加载声音
  566. LoadSound: function (Key, Callback) {
  567. // console.log("加载声音1:" + Key);
  568. cc.gPreLoader.LoadPublicAudio(Key, function (audio, Param) {
  569. this.m_SoundMap[Param.Key] = audio;
  570. if (this.m_WBGM == Param.Key) this.PlayMusic(Key, false);
  571. if (Callback) Callback(audio);
  572. }.bind(this), { Key: Key });
  573. },
  574. LoadSoundArr: function (SoundArr, Bundle) {
  575. for (var i in SoundArr) {
  576. // console.log("加载声音中2:" ,SoundArr[i][0], SoundArr[i][1]);
  577. cc.gPreLoader.LoadAudio(SoundArr[i][0], SoundArr[i][1], Bundle, function (audio, Param) {
  578. // console.log("加载声音成功11111:" ,SoundArr[i][0], SoundArr[i][1]);
  579. var Key = Param.Key;
  580. this.m_SoundMap[Param.Key] = audio;
  581. if (this.m_WBGM == Key) this.PlayMusic(Key, true);
  582. }.bind(this), { Key: SoundArr[i][0], Bundle: Bundle });
  583. }
  584. },
  585. //播放游戏声音
  586. PlayGameSound: function (Key) {
  587. try {
  588. var value = this.GetSoundVolume();
  589. if (value == 0) return;
  590. var sound = this.m_GameSoundMap[this.m_GameIndex][Key];
  591. if (sound == null) console.log("播放声音失败:" + Key);
  592. console.log(this.m_GameSoundMap);
  593. if (sound) {
  594. cc.audioEngine.play(sound, false, value);
  595. console.log("播放声音成功:" + Key);
  596. }
  597. } catch (e) {
  598. if (window.trapExceptional) {
  599. window.trapExceptional(`cc.gSoundRes.PlayGameSound: ${this.m_GameIndex} => ${Key} ${e}`, `tagSoundRes`);
  600. }
  601. }
  602. },
  603. //加载游戏声音列表
  604. LoadGameSoundArr: function (wKindID, SoundArr) {
  605. if (wKindID == null) return;
  606. if (this.m_GameSoundMap[wKindID] == null) this.m_GameSoundMap[wKindID] = new Object();
  607. this.m_GameIndex = wKindID;
  608. //已加载
  609. if (this.m_GameSoundMap[wKindID].bFinish) return;
  610. //加载资源
  611. for (var i in SoundArr) {
  612. // this.LoadGameSound(SoundArr[i][0], 'Audio/' + SoundArr[i][1]);
  613. // console.log("加载声音中:" ,SoundArr[i][0], 'Audio/' + SoundArr[i][1]);
  614. cc.gPreLoader.LoadAudio(SoundArr[i][0], 'Audio/' + SoundArr[i][1], this.m_GameIndex, function (audio, Param) {
  615. var Key = Param.Key;
  616. var KindID = Param.KindID;
  617. this.m_GameSoundMap[KindID][Key] = audio;
  618. if (audio == null) {
  619. // console.log("加载声音失败:" , audio,Param);
  620. }
  621. // console.log("加载声音成功:" , audio,Param);
  622. if (this.m_WBGM == Key) this.PlayMusic(Key, true);
  623. }.bind(this), { Key: SoundArr[i][0], KindID: this.m_GameIndex });
  624. }
  625. this.m_GameSoundMap[wKindID].bFinish = true;
  626. },
  627. PlaySoundPhrase: function (wItemIndex, sex, bGame) {
  628. var value = this.GetSoundVolume();
  629. if (value == 0) return;
  630. var szName = "Phrase"
  631. if (sex == 0) szName += '_w'
  632. if (sex == 1) szName += '_m'
  633. szName += wItemIndex;
  634. if (bGame) this.PlayGameSound(szName);
  635. else this.PlaySound(szName);
  636. },
  637. //更新BGM音量
  638. UpdateVolume: function () {
  639. var value = this.GetBGMVolume();
  640. cc.audioEngine.setVolume(this.m_PlayingID, value);
  641. },
  642. //播放BGM
  643. PlayMusic: function (Key, bGame) {
  644. this.m_WBGM = Key;
  645. this.m_WBGame = bGame;
  646. cc.audioEngine.stopAll();
  647. if (!bGame && this.m_SoundMap[Key] == null) {
  648. cc.gPreLoader.LoadPublicAudio(Key, function (audio, Param) {
  649. this.m_SoundMap[Param.Key] = audio;
  650. this.PlayMusic(Param.Key, bGame);
  651. }.bind(this), { Key: Key });
  652. return;
  653. }
  654. if (bGame && this.m_GameSoundMap[this.m_GameIndex][Key] == null) return
  655. var value = this.GetBGMVolume();
  656. this.m_WBGM = null;
  657. if (bGame) {
  658. this.m_PlayingID = cc.audioEngine.play(this.m_GameSoundMap[this.m_GameIndex][Key], true, value);
  659. } else {
  660. this.m_PlayingID = cc.audioEngine.play(this.m_SoundMap[Key], true, value);
  661. }
  662. },
  663. //停止BGM
  664. StopMusic: function () {
  665. cc.audioEngine.stop(this.m_PlayingID);
  666. },
  667. GetBGMVolume: function () {
  668. return parseFloat(window.g_Setting[window.SetKey_Music]);
  669. },
  670. GetSoundVolume: function () {
  671. return parseFloat(window.g_Setting[window.SetKey_Sound]);
  672. },
  673. });
  674. cc.gSoundRes = new tagSoundRes();