UNPKG

laya-coreui-es

Version:

laya核心库、ui库es版本,剔除了媒体、TTF等功能。基于 LayaAir-release_2.12.0 修改

120 lines (119 loc) 4.32 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.SceneLoader = void 0; const Loader_1 = require("./Loader"); const ILaya_1 = require("./../../ILaya"); const AtlasInfoManager_1 = require("./AtlasInfoManager"); const LoaderManager_1 = require("./LoaderManager"); const Event_1 = require("../events/Event"); const EventDispatcher_1 = require("../events/EventDispatcher"); const Handler_1 = require("../utils/Handler"); const Utils_1 = require("../utils/Utils"); class SceneLoader extends EventDispatcher_1.EventDispatcher { constructor() { super(); this._completeHandler = new Handler_1.Handler(this, this.onOneLoadComplete); this.reset(); } reset() { this._toLoadList = []; this._isLoading = false; this.totalCount = 0; } get leftCount() { if (this._isLoading) return this._toLoadList.length + 1; return this._toLoadList.length; } get loadedCount() { return this.totalCount - this.leftCount; } load(url, is3D = false, ifCheck = true) { if (url instanceof Array) { var i, len; len = url.length; for (i = 0; i < len; i++) { this._addToLoadList(url[i], is3D); } } else { this._addToLoadList(url, is3D); } if (ifCheck) this._checkNext(); } _addToLoadList(url, is3D = false) { if (this._toLoadList.indexOf(url) >= 0) return; if (Loader_1.Loader.getRes(url)) return; if (is3D) { this._toLoadList.push({ url: url }); } else this._toLoadList.push(url); this.totalCount++; } _checkNext() { if (!this._isLoading) { if (this._toLoadList.length == 0) { this.event(Event_1.Event.COMPLETE); return; } var tItem; tItem = this._toLoadList.pop(); if (typeof (tItem) == 'string') { this.loadOne(tItem); } else { this.loadOne(tItem.url, true); } } } loadOne(url, is3D = false) { this._curUrl = url; var type = Utils_1.Utils.getFileExtension(this._curUrl); if (is3D) { ILaya_1.ILaya.loader.create(url, this._completeHandler); } else if (SceneLoader.LoadableExtensions[type]) { ILaya_1.ILaya.loader.load(url, this._completeHandler, null, SceneLoader.LoadableExtensions[type]); } else if (url != AtlasInfoManager_1.AtlasInfoManager.getFileLoadPath(url) || SceneLoader.No3dLoadTypes[type] || !LoaderManager_1.LoaderManager.createMap[type]) { ILaya_1.ILaya.loader.load(url, this._completeHandler); } else { ILaya_1.ILaya.loader.create(url, this._completeHandler); } } onOneLoadComplete() { this._isLoading = false; if (!Loader_1.Loader.getRes(this._curUrl)) { console.log("Fail to load:", this._curUrl); } var type = Utils_1.Utils.getFileExtension(this._curUrl); if (SceneLoader.LoadableExtensions[type]) { var dataO; dataO = Loader_1.Loader.getRes(this._curUrl); if (dataO) { if (dataO.loadList) { this.load(dataO.loadList, false, false); } if (dataO.loadList3D) { this.load(dataO.loadList3D, true, false); } } } if (type == "sk") { this.load(this._curUrl.replace(".sk", ".png"), false, false); } this.event(Event_1.Event.PROGRESS, this.getProgress()); this._checkNext(); } getProgress() { return this.loadedCount / this.totalCount; } } exports.SceneLoader = SceneLoader; SceneLoader.LoadableExtensions = { "scene": Loader_1.Loader.JSON, "scene3d": Loader_1.Loader.JSON, "ani": Loader_1.Loader.JSON, "ui": Loader_1.Loader.JSON, "prefab": Loader_1.Loader.PREFAB }; SceneLoader.No3dLoadTypes = { "png": true, "jpg": true, "txt": true };