UnLockHero.ts 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import { _decorator, Component, Node, Prefab, instantiate, Vec2, Vec3, UITransform, Sprite, UIOpacity, find } from 'cc';
  2. import { ResourceLoader } from '../core/resourceManager/ResourceLoader';
  3. import { UITween } from '../core/ui/tween/UITween';
  4. import { Window } from '../core/ui/window/Window';
  5. import { UnLockHeroItem } from './UnLockHeroItem';
  6. const { ccclass, property, requireComponent } = _decorator;
  7. /**武将解锁 */
  8. @ccclass('UnLockHero')
  9. @requireComponent(ResourceLoader)
  10. export class UnLockHero extends Component {
  11. @property({ type: Node, tooltip: "武将节点" }) heroNode: Node;
  12. @property({ type: Node, tooltip: "内容节点" }) contentNode: Node;
  13. @property({ type: Node, tooltip: "背景节点" }) bgNode: Node;
  14. @property({ type: Node, tooltip: "移除位置节点" }) targetNode: Node;
  15. @property({ type: UITween, tooltip: "关闭动画" }) tween: UITween;
  16. @property({ type: Window, tooltip: "关闭动画" }) win: Window;
  17. private res: ResourceLoader;
  18. private heroArr = [];
  19. private async openHandler(data: any) {
  20. this.tween.targetData[0].propsData.position = this.targetNode.position;
  21. this.res = this.getComponent(ResourceLoader);
  22. this.scheduleOnce(() => {
  23. this.win.close();
  24. }, 5);
  25. if (data.heroDatas.length) {
  26. if (data.heroDatas.length > 3) {
  27. this.contentNode.getComponent(UITransform).height = 610;
  28. }
  29. for (let i = 0; i < data.heroDatas.length; i++) {
  30. let prefab = await this.res.load<Prefab>('prefabs/ui/barracks/unLockHeroItem', Prefab);
  31. let node = instantiate(prefab);
  32. let item = node.getComponent(UnLockHeroItem);
  33. item.setData(data.heroDatas[i]);
  34. node.parent = this.heroNode;
  35. this.heroArr.push(item);
  36. }
  37. }
  38. }
  39. private onClose() {
  40. this.bgNode.active = false;
  41. }
  42. }