FlyContainer.ts 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. import { _decorator, Component, Node } from "cc";
  2. import BaseUI from "../../scripts/base/BaseUI";
  3. import PoolM, { PoolType } from "../../scripts/mgr/PoolM";
  4. import Utils from "../../scripts/utils/Utils";
  5. import UIUtils from "../../scripts/base/UIUtils";
  6. import { GoodInfo } from "../../scripts/api/UserM";
  7. import { GoodsId } from "../../scripts/api/GoodsId";
  8. import { Vec3 } from "cc";
  9. import { instantiate } from "cc";
  10. const { ccclass, property } = _decorator;
  11. export enum FlyType {
  12. POG = 1,
  13. GEM = 2,
  14. }
  15. @ccclass("FlyContainer")
  16. export class FlyContainer extends BaseUI {
  17. private slot_gem: Node;
  18. private slot_pog: Node;
  19. private slot_storage: Node;
  20. protected onLoad(): void {
  21. super.onLoad();
  22. FlyContainer._ins = this;
  23. this.slot_gem = this.FindNode("slot_gem");
  24. this.slot_pog = this.FindNode("slot_pog");
  25. this.slot_storage = this.FindNode("slot_storage");
  26. }
  27. private static _ins: FlyContainer = null;
  28. public static get ins(): FlyContainer {
  29. return FlyContainer._ins;
  30. }
  31. public onReward(RewardItem: Node, good: GoodInfo) {
  32. let nP = null;
  33. if (good.id == GoodsId.AIR) {
  34. return;
  35. }
  36. switch (good.id) {
  37. case GoodsId.GEM:
  38. case GoodsId.DIAMOND_10:
  39. nP = this.slot_gem;
  40. break;
  41. case GoodsId.POG:
  42. case GoodsId.POG_10:
  43. nP = this.slot_pog;
  44. break;
  45. }
  46. if (nP == null) {
  47. nP = this.slot_storage;
  48. }
  49. let a = RewardItem.getChildByName("icon_layout");
  50. UIUtils.moveToNewParent(nP, a);
  51. UIUtils.AnimBezierMoveAndTranslate(a, new Vec3(0, 0, 0), 1, 1, () => {
  52. a.destroy();
  53. });
  54. }
  55. public async fly(type: FlyType) {
  56. let toPosition = null;
  57. if (type == FlyType.POG) {
  58. toPosition = this.FindNode("slot_pog");
  59. } else if (type == FlyType.GEM) {
  60. toPosition = this.FindNode("slot_gem");
  61. } else {
  62. toPosition = this.slot_storage;
  63. }
  64. if (!toPosition) {
  65. return;
  66. }
  67. for (let i = 0; i < 3; i++) {
  68. this.flyOne(i, type, toPosition);
  69. }
  70. }
  71. async flyOne(i: number, type: FlyType, toPosition: Node) {
  72. //@ts-ignore
  73. let node: Node = await PoolM.ins.getGem();
  74. node.parent = this.node;
  75. node.setPosition(0, 0, 0);
  76. UIUtils.AnimBezierMoveAndTranslate(
  77. node,
  78. toPosition.position,
  79. 1,
  80. 0.5,
  81. () => {
  82. //@ts-ignore
  83. PoolM.ins.put(type, node as Node);
  84. }
  85. );
  86. }
  87. }