SamsaraGame/assets/Script/utils/DebugModeUtil.ts
2025-04-24 17:03:28 +08:00

99 lines
4.5 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

const { ccclass, property } = cc._decorator;
@ccclass
export default class DebugModeUtil extends cc.Component {
static shared = new DebugModeUtil();
@property(cc.Node)
debugBg: cc.Node = null;
@property(cc.Label)
debugLabel: cc.Label = null;
debugMode: boolean = false;
static showFps() {
cc.debug.setDisplayStats(true)
}
static hideFps() {
cc.debug.setDisplayStats(false)
}
static openDebug() {
this.shared.debugBg = cc.find("Canvas/Debug")
this.shared.debugLabel = cc.find("Canvas/Debug/label").getComponent(cc.Label)
this.shared.debugMode = true;
this.shared.debugBg.active = true;
}
countNodeNum(node) {
var num = 0;
if (!node) return 0;
function check(node) {
for (let i in node.children) {
num += node.children[i].childrenCount
if (node.children[i].childrenCount > 0) {
check(node.children[i])
}
}
}
check(node)
return num;
}
update() {
if (!DebugModeUtil.shared.debugMode) return;
var cacheNum = Object.keys(cc.loader["_cache"]).length;
var pNode = cc.find("Canvas")
var mapUI = cc.find("MapUI", pNode)
var battleLayer = cc.find("BattleLayer", pNode)
var battleUILayer = cc.find("BattleUILayer", pNode)
var mainUI = cc.find("MainUI", pNode)
var autoSearch = cc.find("autoSearch", pNode)
var autoPatrol = cc.find("autoPatrol", pNode)
var PalaceNotice = cc.find("PalaceNotice", pNode)
var numArr = [
this.countNodeNum(mapUI),
this.countNodeNum(battleLayer),
this.countNodeNum(battleUILayer),
this.countNodeNum(mainUI),
this.countNodeNum(autoSearch),
this.countNodeNum(autoPatrol),
this.countNodeNum(PalaceNotice)
]
DebugModeUtil.shared.debugLabel.string = `緩存數量:${cacheNum}\nMapUI節點數量${numArr[0]}\nBattleLayer節點數量${numArr[1]}\nBattleUILayer節點數量${numArr[2]}\nMainUI節點數量${numArr[3]}\nautoSearch節點數量${numArr[4]}\nautoPatrol節點數量${numArr[5]}\nPalaceNotice節點數量${numArr[6]}`
// var battleUILayer = cc.find("BattleUILayer", pNode)
// var OpeTimer = cc.find("BattleUI/OpeTimer", battleUILayer)
// var infolayer = cc.find("BattleUI/infolayer", battleUILayer)
// var returnskill = cc.find("BattleUI/returnskill", battleUILayer)
// var btnlayer = cc.find("BattleUI/btnlayer", battleUILayer)
// var petBtnLayer = cc.find("BattleUI/petBtnLayer", battleUILayer)
// var skillpanel = cc.find("BattleUI/skillpanel", battleUILayer)
// var petskillpanel = cc.find("BattleUI/petskillpanel", battleUILayer)
// var autoskillpanel = cc.find("BattleUI/autoskillpanel", battleUILayer)
// var autopetskillpanel = cc.find("BattleUI/autopetskillpanel", battleUILayer)
// var petpanel = cc.find("BattleUI/petpanel", battleUILayer)
// var BattleUIItemPanel = cc.find("BattleUI/BattleUIItemPanel", battleUILayer)
// var pkTitle = cc.find("BattleUI/pkTitle", battleUILayer)
// var numArr = [
// this.countNodeNum(battleUILayer),
// this.countNodeNum(OpeTimer),
// this.countNodeNum(infolayer),
// this.countNodeNum(returnskill),
// this.countNodeNum(btnlayer),
// this.countNodeNum(petBtnLayer),
// this.countNodeNum(skillpanel),
// this.countNodeNum(petskillpanel),
// this.countNodeNum(autoskillpanel),
// this.countNodeNum(autopetskillpanel),
// this.countNodeNum(petpanel),
// this.countNodeNum(BattleUIItemPanel),
// this.countNodeNum(pkTitle)
// ]
// var co = 0
// for (let i = 1; i < 13; i++) {
// co += numArr[i]
// }
// this.ceshi.string = `緩存數量:${num}\nBattleUILayer節點數量${numArr[0]}\nOpeTimer節點數量${numArr[1]}\ninfolayer節點數量${numArr[2]}\nreturnskill節點數量${numArr[3]}\nbtnlayer節點數量${numArr[4]}\npetBtnLayer節點數量${numArr[5]}\nskillpanel節點數量${numAr r[6]}\npetskillpanel節點數量${numArr[7]}\nautoskillpanel節點數量${numArr[8]}\nautopetskillpanel節點數量${numArr[9]}\npetpanel節點數量${numArr[10]}\nBattleUIItemPanel節點數量${numArr[11]}\npkTitle節點數量${numArr[12]}\n總計數量${co}`
}
}