UIDebugPanel.ts 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import GameDataCenter from "../../data/GameDataCenter";
  2. import { uiCommon } from "../../utils/UICommon";
  3. import UIHelp from "../ui/UIHelp";
  4. const { ccclass, property } = cc._decorator;
  5. interface DebugParam {
  6. btnName: string,
  7. btnFunc: Function,
  8. showInput: boolean,
  9. defaultInput?: string
  10. }
  11. @ccclass
  12. export default class UIDebugPanel extends cc.Component {
  13. @property(cc.Node) debugItem: cc.Node = null;
  14. @property(cc.Node) content: cc.Node = null;
  15. start() {
  16. this.AddLayerDebug();
  17. }
  18. // protected onEnable(): void {
  19. // cc.sys.localStorage.getItem("DebugXhid", "");
  20. // }
  21. private AddDebugItem(param: DebugParam) {
  22. let item = cc.instantiate(this.debugItem);
  23. this.content.addChild(item);
  24. item.active = true;
  25. let input = item.getChildByName("EbInput");
  26. item.getChildByName("EbInput").active = param.showInput;
  27. let btn = item.getChildByName("DebugItemBtn");
  28. btn.getChildByName("Background").getChildByName("Label").getComponent(cc.Label).string = param.btnName;
  29. uiCommon.onRegisterEvent(btn, () => {
  30. param.btnFunc(param.showInput ? input.getComponent(cc.EditBox).string : "");
  31. }, this);
  32. if (param.showInput && param.defaultInput) {
  33. input.getComponent(cc.EditBox).string = param.defaultInput;
  34. }
  35. }
  36. private AddLayerDebug() {
  37. }
  38. }