FlyTreasureChest.ts 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import { instantiate, Widget } from 'cc';
  2. import { _decorator, Component, Node, Animation, Prefab } from 'cc';
  3. import { ResourcesUtils } from '../core/resourceManager/ResourcesUtils';
  4. import { OpenWindow } from '../core/ui/window/OpenWindow';
  5. import { ConfigData } from '../Data/ConfigData';
  6. import { g } from '../Data/g';
  7. import { RotatingLightAnim } from '../SpecialEffects/RotatingLightAnim';
  8. const { ccclass, property } = _decorator;
  9. @ccclass('FlyTreasureChest')
  10. export class FlyTreasureChest extends Component {
  11. @property({ tooltip: "宝箱飞行动作节点", type: Node })
  12. public flyBox: Node;
  13. @property({ tooltip: "光效预制体根目录" })
  14. public lightEfficiency = '';
  15. @property({ tooltip: "光效父节点", type: Node })
  16. public lightEfficiencyBox: Node;
  17. // @property({ tooltip: "打开新窗口界面按钮", type: Node })
  18. // public toGetGoldWin: Node;
  19. public temp: Animation;
  20. start() {
  21. }
  22. public setData() {
  23. // this.temp.play('boxMove');
  24. this.node.getComponent(Widget).left = -200;
  25. let moveAnim: Animation = this.node.getComponent(Animation);
  26. moveAnim.play('boxMove');
  27. let flyAnim: Animation = this.flyBox.getComponent(Animation);
  28. flyAnim.play();
  29. this.setLight();
  30. }
  31. /**
  32. * 设置光效
  33. */
  34. public async setLight() {
  35. let prefabsData = await ResourcesUtils.load<Prefab>(this.lightEfficiency, null, this.node);
  36. var lightNode = instantiate(prefabsData);
  37. lightNode.parent = this.lightEfficiencyBox;
  38. let rotatingLight = lightNode.getComponent(RotatingLightAnim);
  39. rotatingLight.set_Data(300, 300, 0.5, false);
  40. }
  41. /**
  42. * 动画结束回调
  43. */
  44. public test() {
  45. this.node.removeFromParent();
  46. this.destroy();
  47. }
  48. /**
  49. * 点击宝箱回调
  50. */
  51. public openNewWindow() {
  52. let config = ConfigData.configMap.get("flyBox")
  53. let type = g.userData.lv == 0 ? 1 : g.userData.lv;
  54. this.getComponent(OpenWindow).open([0, config.prizeList[type - 1].prize, config.videoMultiple]);
  55. this.test();
  56. }
  57. }