import { Label } from 'cc'; import { Button } from 'cc'; import { _decorator, Component, Node } from 'cc'; import { UmStorageManager } from '../../../cc-common/cc-util/UmStorageManager'; import { profiler } from 'cc'; import { PhysicsSystem2D } from 'cc'; import { EPhysics2DDrawFlags } from 'cc'; const { ccclass, property } = _decorator; @ccclass('DebugFPS') export class DebugFPS extends Component { @property(Button) spfBtn: Button = null!; @property(Button) physicBtn: Button = null!; @property(Label) title: Label = null!; protected onLoad(): void { this.spfBtn?.node.on(Button.EventType.CLICK, this.setFPS, this); this.physicBtn?.node.on(Button.EventType.CLICK, this.setPhysicDebug, this); this.setDebugFPSActive(this.getStatus()); // PhysicsSystem2D.instance.debugDrawFlags = true ? EPhysics2DDrawFlags.Shape : EPhysics2DDrawFlags.None; } private setFPS() { var isOn = this.getStatus(); this.setStatus(!isOn); this.setDebugFPSActive(!isOn); } isPhysicDebug = false; private setPhysicDebug() { this.isPhysicDebug = !this.isPhysicDebug; this.scheduleOnce(() => { PhysicsSystem2D.instance.debugDrawFlags = this.isPhysicDebug ? EPhysics2DDrawFlags.Shape : EPhysics2DDrawFlags.None; }, 0); } getStatus() { return UmStorageManager.instance.getBooleanByKey("show_fps", false); } setStatus(isOn: boolean) { UmStorageManager.instance.setBooleanByKey("show_fps", isOn); } setDebugFPSActive(isActive: boolean) { isActive ? profiler.showStats() : profiler.hideStats(); this.title.string = isActive ? "ON" : "OFF"; } }