You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
126 lines
3.6 KiB
126 lines
3.6 KiB
import { error, log, warn } from "cc";
|
|
import { MINIGAME, PREVIEW } from "cc/env";
|
|
|
|
const emptyCall =()=>{};
|
|
|
|
/**
|
|
* 打印台扩展
|
|
*/
|
|
export default class ConsoleEx {
|
|
static readonly OnLine:boolean = false && MINIGAME;
|
|
/**是否使用Cocos的日志进行输出 */
|
|
static readonly isCLog: boolean = false;
|
|
/**是否将普通日志改为包含执行路径的错误日志 */
|
|
static readonly logOutPath: boolean = false;
|
|
|
|
// /**SDK是否登录 */
|
|
// static SDKLogin:boolean = false;
|
|
// private static _LogManager = null;
|
|
// static get LogManager(){
|
|
// if (!this._LogManager) {
|
|
// if (window["tt"] && window["tt"].getLogManager) {
|
|
// this._LogManager = window["tt"].getLogManager();
|
|
// }
|
|
// }
|
|
// return this._LogManager;
|
|
// }
|
|
|
|
/**
|
|
*
|
|
* @param level 日志等级
|
|
* @param styleColor 背景颜色
|
|
* @param title 日志标题
|
|
* @param titleColor 标题颜色
|
|
* @param txtColor 文本颜色
|
|
* @returns
|
|
*/
|
|
static create(level: 'log' | 'warn' | 'error', styleColor: string, title: string, titleColor = '#fff',txtColor = '#000') {
|
|
if (PREVIEW) {
|
|
return window.console[level].bind(window.console,
|
|
'%c %s %c ',//%s
|
|
`background:${styleColor}; padding: 2px; border-radius: 5px 0 0 5px; border: 1px solid ${styleColor}; color: ${titleColor}; font-weight: normal;`,
|
|
`${title} ${new Date().toLocaleString()}`,
|
|
`background:#ffffff ; padding: 2px; border-radius: 0 5px 5px 0; border: 1px solid ${styleColor}; color: ${txtColor}; font-weight: normal;`
|
|
);
|
|
}
|
|
return window.console[level].bind(window.console,
|
|
`${title} [${new Date().toLocaleString()}]`
|
|
);
|
|
}
|
|
|
|
//#region 外部调用
|
|
|
|
private static Print(Fun:any,list:any[]){
|
|
switch (list.length) {
|
|
case 1:
|
|
Fun(list[0])
|
|
break;
|
|
case 2:
|
|
Fun(list[0],list[1])
|
|
break;
|
|
case 3:
|
|
Fun(list[0],list[1],list[2])
|
|
break;
|
|
case 4:
|
|
Fun(list[0],list[1],list[2],list[3])
|
|
break;
|
|
case 5:
|
|
Fun(list[0],list[1],list[2],list[3],list[4])
|
|
break;
|
|
case 6:
|
|
Fun(list[0],list[1],list[2],list[3],list[4],list[5])
|
|
break;
|
|
default:
|
|
Fun(list)
|
|
break;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 包装普通消息
|
|
* @param any 内容
|
|
*/
|
|
public static get Log() {
|
|
if (this.OnLine) { return emptyCall; }
|
|
return this.create('log','#9BA4B4','[普通]','#fff');
|
|
}
|
|
|
|
/**
|
|
* 包装普通轻消息
|
|
* @param any 内容
|
|
*/
|
|
public static get LogLight() {
|
|
if (this.OnLine) { return emptyCall; }
|
|
return this.create('log', '#EBEBEB', '[普通Ex]', '#776d8a');
|
|
}
|
|
|
|
/**
|
|
* 包装成功消息
|
|
* @param any 内容
|
|
*/
|
|
public static get Com() {
|
|
if (this.OnLine) { return emptyCall; }
|
|
return this.create('log', '#ade498', '[完成]', '#fff');
|
|
}
|
|
|
|
/**
|
|
* 包装警告消息
|
|
* @param any 内容
|
|
*/
|
|
public static get Warn() {
|
|
//if (this.OnLine) { return any; }
|
|
return this.create('warn', '#ffa931', '[警告]', '#5c6e06');
|
|
}
|
|
|
|
/**
|
|
* 包装错误消息
|
|
* @param any 内容
|
|
*/
|
|
public static get Error() {
|
|
return this.create('error', '#ec0101', '[错误]', '#fff');
|
|
}
|
|
//#endregion
|
|
|
|
}
|
|
|
|
window["ConsoleEx"] = ConsoleEx;
|