123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165 |
- import Tools from "./Tools";
- export class AttributeUnit {
- /** 名字-单元资源包 */
- bundleName: string;
- /** 名字-单元配置文件 */
- configName: string;
- /** bundle */
- bundle: cc.AssetManager.Bundle;
- /** config */
- config: AttributeGame[];
- }
- export class AttributeGame {
- /** 名字-视频 */
- videoName?: string;
- /** 名字-预制体 */
- prefabName?: string;
- /** 名字-脚本 */
- scriptName: string;
- }
- class common {
- private static _instance: common;
- public static getInstance(): common {
- if (this._instance) {
- return this._instance;
- }
- this._instance = new common();
- this._instance.editSpineRun();
- return this._instance;
- };
- isDebug: boolean = false;
- project: string = "luojigou_yinliu";
- unitCur: number = 3;// 第几集,从1开始
- pageCur: number = 6;// 第几个游戏,从1开始
- isCanPlayVideo = false;
- attributeMap: any = {};// 内部形式为 { "0" : AttributeUtil }
- getUnitNum() {
- return this.unitCur > 0 ? this.unitCur : 1;
- };
- setUnitNum(unitNum) {
- this.unitCur = unitNum;
- };
- getPageNum() {
- return this.pageCur > 0 ? this.pageCur : 1;
- };
- setPageNum(pageNum) {
- this.pageCur = pageNum;
- };
- //隐藏页面loading
- hideLoading() {
- var splash = document.getElementById('splash');
- splash.style.visibility = 'hidden';
- console.log("--hideLoading--: 隐藏加载界面");
- }
- /** 获取当前游戏的本地数据 */
- getGameFormLocal(): number {
- let objLocal: any = Tools.getLocalStorage(this.project, null);
- objLocal = JSON.parse(objLocal);
- this.log("获取本地数据:", JSON.stringify(objLocal, null, 4));
- if (!objLocal) return -1;
- if (!objLocal.objUnit) return -1;
- let unitOne = objLocal.objUnit[this.getUnitNum()];
- if (!unitOne) return -1;
- let gameOne = unitOne[this.getPageNum()];
- return Number(gameOne);
- };
- /** 设置当前游戏标志 */
- setGameToLocal(): void {
- let unit = this.getUnitNum();
- let page = this.getPageNum();
- let objLocal: any = Tools.getLocalStorage(this.project, null);
- objLocal = JSON.parse(objLocal);
- if (objLocal) {
- if (!objLocal.objUnit) {
- objLocal.objUnit = {};
- }
- if (!objLocal.objUnit[unit]) {
- objLocal.objUnit[unit] = {};
- }
- if (objLocal.objUnit[unit][page]) {
- return;
- }
- else {
- objLocal.objUnit[unit][page] = page;
- }
- }
- else {
- objLocal = {};
- objLocal.project = this.project;
- objLocal.objUnit = {};
- objLocal.objUnit[unit] = {};
- objLocal.objUnit[unit][page] = page;
- }
- this.log("设置本地数据:", JSON.stringify(objLocal, null, 4));
- Tools.setLocalStorage(this.project, JSON.stringify(objLocal));
- };
- /** cocos日志打印 */
- log(...params: any) {
- // if (!CC_DEBUG) return;
- var logContent = [];
- for (var i in params) {
- logContent.push(typeof (params[i]) == "object" ? JSON.stringify(params[i]) : params[i]);
- }
- console.log(" #cocos# " + logContent.join(""));
- };
- /** 设置编译器spine播放 */
- editSpineRun() {
- if (!CC_EDITOR) {
- return;
- }
- // 重写update方法 达到在编辑模式下 自动播放动画的功能
- sp.Skeleton.prototype["update"] = function (dt) {
- cc["engine"]._animatingInEditMode = 1;
- cc["engine"].animatingInEditMode = 1;
- if (this.paused) return;
- dt *= this.timeScale * sp["timeScale"];
- if (this.isAnimationCached()) {
- // Cache mode and has animation queue.
- if (this._isAniComplete) {
- if (this._animationQueue.length === 0 && !this._headAniInfo) {
- let frameCache = this._frameCache;
- if (frameCache && frameCache.isInvalid()) {
- frameCache.updateToFrame();
- let frames = frameCache.frames;
- this._curFrame = frames[frames.length - 1];
- }
- return;
- }
- if (!this._headAniInfo) {
- this._headAniInfo = this._animationQueue.shift();
- }
- this._accTime += dt;
- if (this._accTime > this._headAniInfo.delay) {
- let aniInfo = this._headAniInfo;
- this._headAniInfo = null;
- this.setAnimation(0, aniInfo.animationName, aniInfo.loop);
- }
- return;
- }
- this._updateCache(dt);
- } else {
- this._updateRealtime(dt);
- }
- }
- }
- };
- export default common.getInstance();
|