SelectTroopsBottom.ts 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. import { _decorator, Button, Component, director, Node, Sprite, SpriteFrame } from 'cc';
  2. import { GameInfo } from '../../GameInfo';
  3. const { ccclass, property } = _decorator;
  4. @ccclass('SelectTroopsBottom')
  5. export class SelectTroopsBottom extends Component {
  6. private _btnNext: Node = null;
  7. private _characterSlot: Node = null;
  8. private _names: string[] = [];
  9. protected onLoad(): void {
  10. this._btnNext = this.node.getChildByName("BtnNext");
  11. this._characterSlot = this.node.getChildByName("CharacterSlot");
  12. }
  13. start() {
  14. this._btnNext.getComponent(Button).node.on(Button.EventType.CLICK, this._onBtnNext, this);
  15. }
  16. private _onBtnNext() {
  17. this._names = this._getNames();
  18. if (this._names) {
  19. GameInfo.Instance.setRoleImgNames(this._names);
  20. director.loadScene("GameScene");
  21. }
  22. }
  23. private _getNames(): string[] {
  24. for (const element of this._characterSlot.children) {
  25. const name: SpriteFrame = element.getChildByName("Sprite").getComponent(Sprite).spriteFrame;
  26. if (name) {
  27. this._names.push(name.name)
  28. }
  29. }
  30. return this._names;
  31. }
  32. }