feature:添加开发者按钮

This commit is contained in:
2026-07-15 18:41:39 +08:00
parent 470efd00d1
commit 3a6df84f88
20 changed files with 1796 additions and 2105 deletions
+54 -1
View File
@@ -1,4 +1,4 @@
import { _decorator, animation, Animation, AnimationComponent, Button, Component, EventTouch, Input, input, instantiate, Label, math, Node, Prefab, randomRange, randomRangeInt, screen, Screen, tween, Vec2, Vec3, view } from 'cc';
import { _decorator, animation, Animation, AnimationComponent, Button, Color, Component, EventTouch, HorizontalTextAlignment, Input, input, instantiate, Label, math, Node, Prefab, randomRange, randomRangeInt, screen, Screen, tween, UITransform, Vec2, Vec3, VerticalTextAlignment, view } from 'cc';
import { PanelBase } from '../framework/ui/PanelBase';
import { FPSCameraController } from '../FPSCameraController';
import { GameController } from '../GameController';
@@ -12,6 +12,7 @@ import { AudioMgr } from '../framework/audio/AudioMgr';
import { AssetController } from '../AssetController';
import { Ragdoll } from '../../Ragdoll/Ragdoll';
import { LocalSaveMgr } from '../framework/data/LocalSaveMgr';
import { LevelState } from '../EnumFile';
const { ccclass, property } = _decorator;
@ccclass('PlayPanel')
@@ -112,10 +113,62 @@ export class PlayPanel extends PanelBase {
this.qingBaoResultBtn.node.on(Button.EventType.CLICK, this.onClickQingBaoResult, this);
this.saoMiao.node.on(Button.EventType.CLICK, this.onClickSaoMiao, this);
this.setting.node.on(Button.EventType.CLICK, this.onClickSetting, this);
this.createDeveloperButtons()
EventCenter.onEnemyDie.on(null, this.refreshTargetCount).bind(this)
}
/** 为测试关卡提供快捷操作,仅显示文字,避免与正式功能图标混淆。 */
private createDeveloperButtons() {
this.createDeveloperButton('DEV_KillEnemies', '开发:杀死敌人', new Vec3(350, 830, 0), this.onClickDevKillEnemies)
this.createDeveloperButton('DEV_CompleteLevel', '开发:完成过关', new Vec3(350, 760, 0), this.onClickDevCompleteLevel)
}
private createDeveloperButton(name: string, text: string, position: Vec3, callback: () => void) {
const buttonNode = new Node(name)
buttonNode.name = name
buttonNode.layer = this.setting.node.layer
buttonNode.setParent(this.setting.node.parent)
buttonNode.setPosition(position)
buttonNode.addComponent(UITransform).setContentSize(220, 60)
const button = buttonNode.addComponent(Button)
const labelNode = new Node('Label')
labelNode.layer = buttonNode.layer
labelNode.setParent(buttonNode)
labelNode.addComponent(UITransform).setContentSize(220, 60)
const label = labelNode.addComponent(Label)
label.string = text
label.fontSize = 24
label.lineHeight = 32
label.color = new Color(255, 220, 90, 255)
label.horizontalAlign = HorizontalTextAlignment.CENTER
label.verticalAlign = VerticalTextAlignment.CENTER
button.node.on(Button.EventType.CLICK, callback, this)
}
private onClickDevKillEnemies() {
const level = GameController.getInstance().curLevel
if (level.levelState !== LevelState.Running) return
AudioMgr.inst.playOneShot(AssetController.instance.click)
for (const enemy of level.enemies) {
if (!enemy.isDie) {
enemy.setEnabled(true)
}
}
}
private onClickDevCompleteLevel() {
const level = GameController.getInstance().curLevel
if (level.levelState !== LevelState.Running) return
AudioMgr.inst.playOneShot(AssetController.instance.click)
level.win()
}
onClickSetting() {
AudioMgr.inst.playOneShot(AssetController.instance.click)
UIManager.instance.openPanel(SettingPanel)