Load.ts 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. import Plat from "../utils/Palt";
  2. import SubLoad from "../utils/SubLoad";
  3. import PrefabUtil from "../utils/manager/PrefabUtil";
  4. import Log from "../utils/util/Log";
  5. const { ccclass, property } = cc._decorator;
  6. @ccclass
  7. export class Load extends cc.Component {
  8. @property(cc.Sprite)
  9. progressBar: cc.Sprite = null;
  10. @property(cc.Label)
  11. gameVersion: cc.Label = null;
  12. @property(cc.Label)
  13. progressLabel: cc.Label = null;
  14. @property(cc.Sprite)
  15. next: cc.Sprite = null;
  16. onLoad() {
  17. // console.log("第一个脚本--加载脚本--这里执行了哈哈哈111");
  18. // this.gameVersion.string="v_"+Log.game_version+(Log.test==true?"_测试":"");
  19. // cc.sys.localStorage.clear();
  20. // cc.debug.setDisplayStats(false);
  21. this.flags[0] = 0;
  22. this.scheduleOnce(this.startLoad, 0.2);
  23. }
  24. private flags: Array<number> = new Array();
  25. public onnext() {
  26. console.log(123123);
  27. }
  28. public startLoad() {
  29. SubLoad.loadSub(() => {
  30. PrefabUtil.load((() => {
  31. // console.warn("预制体全部加载完成");
  32. cc.director.preloadScene("Main", () => {
  33. // Log.info("main场景预加载成功")
  34. this.flags[0] = 1;
  35. });
  36. }));
  37. })
  38. Plat.init();
  39. // Log.info("---加载开始---")
  40. }
  41. private p = 40;
  42. private frame_ok: boolean = false;
  43. update() {
  44. this.p += 0.5;
  45. if (this.p > 98) {
  46. this.p = 98;
  47. }
  48. if (this.p < 10) {
  49. this.p = 10;
  50. }
  51. // this.progressBar.node.width = 500 * this.p / 100;
  52. this.progressLabel.string = "加载资源中... " + Math.floor(this.p) + "%";
  53. if (this.p > 90 && this.frame_ok == false) {
  54. for (var key in this.flags) {
  55. if (this.flags[key] != 1) {
  56. return;
  57. }
  58. }
  59. cc.director.loadScene("Main", () => {
  60. // Log.info("main场景加载成功")
  61. });
  62. this.frame_ok = true;
  63. }
  64. }
  65. }