635d373e206601884c96847cb1eeeefae856f2ab.js 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. System.register(["__unresolved_0", "cc", "__unresolved_1", "__unresolved_2"], function (_export, _context) {
  2. "use strict";
  3. var _reporterNs, _cclegacy, __checkObsolete__, __checkObsoleteInNamespace__, _decorator, Component, director, find, Vec3, Cube_Infor, Cube_State, Container_Manager, _dec, _class, _crd, ccclass, property, CreateIdiom;
  4. function _reportPossibleCrUseOfCube_Infor(extras) {
  5. _reporterNs.report("Cube_Infor", "./Cube_Infor", _context.meta, extras);
  6. }
  7. function _reportPossibleCrUseOfCube_State(extras) {
  8. _reporterNs.report("Cube_State", "./Cube_Infor", _context.meta, extras);
  9. }
  10. function _reportPossibleCrUseOfContainer_Manager(extras) {
  11. _reporterNs.report("Container_Manager", "./Container_Manager", _context.meta, extras);
  12. }
  13. return {
  14. setters: [function (_unresolved_) {
  15. _reporterNs = _unresolved_;
  16. }, function (_cc) {
  17. _cclegacy = _cc.cclegacy;
  18. __checkObsolete__ = _cc.__checkObsolete__;
  19. __checkObsoleteInNamespace__ = _cc.__checkObsoleteInNamespace__;
  20. _decorator = _cc._decorator;
  21. Component = _cc.Component;
  22. director = _cc.director;
  23. find = _cc.find;
  24. Vec3 = _cc.Vec3;
  25. }, function (_unresolved_2) {
  26. Cube_Infor = _unresolved_2.Cube_Infor;
  27. Cube_State = _unresolved_2.Cube_State;
  28. }, function (_unresolved_3) {
  29. Container_Manager = _unresolved_3.Container_Manager;
  30. }],
  31. execute: function () {
  32. _crd = true;
  33. _cclegacy._RF.push({}, "3b901oU5ZJHnp8TtJiYjZWZ", "CreateIdiom", undefined);
  34. __checkObsolete__(['_decorator', 'Component', 'debug', 'director', 'find', 'instantiate', 'Layers', 'Node', 'NodePool', 'Prefab', 'tween', 'Vec3']);
  35. ({
  36. ccclass,
  37. property
  38. } = _decorator);
  39. _export("CreateIdiom", CreateIdiom = (_dec = ccclass('CreateIdiom'), _dec(_class = class CreateIdiom extends Component {
  40. constructor(...args) {
  41. super(...args);
  42. this.count = 0;
  43. this.Container = void 0;
  44. }
  45. onLoad() {
  46. this.Container = find('Container').getComponent(_crd && Container_Manager === void 0 ? (_reportPossibleCrUseOfContainer_Manager({
  47. error: Error()
  48. }), Container_Manager) : Container_Manager);
  49. }
  50. update(deltaTime) {}
  51. nodeMoving() {
  52. this.node.setPosition(new Vec3(0, 1.6, 0));
  53. let startPos = this.node.position; // 起点,抛物线开始的坐标
  54. let middlePos = new Vec3(this.node.position.x, this.node.position.y + 2, 0); // 中间控制点
  55. let destPos = new Vec3(this.node.position.x, this.node.position.y + 4, 0); // 终点,抛物线上升顶点
  56. // 保持原来贝塞尔曲线和螺旋效果的计算
  57. let twoBezier = (t, p1, cp, p2) => {
  58. // 贝塞尔曲线计算
  59. let x = (1 - t) * (1 - t) * p1.x + 2 * t * (1 - t) * cp.x + t * t * p2.x;
  60. let y = (1 - t) * (1 - t) * p1.y + 2 * t * (1 - t) * cp.y + t * t * p2.y;
  61. let z = (1 - t) * (1 - t) * p1.z + 2 * t * (1 - t) * cp.z + t * t * p2.z; // 螺旋运动计算
  62. let angle = t * Math.PI * 6; // 螺旋角度变化,增加圈数
  63. let radius = t * 3.5; // 螺旋半径逐渐增大
  64. let xOffset = Math.cos(angle) * radius; // x 轴偏移
  65. let zOffset = Math.sin(angle) * radius; // z 轴偏移
  66. // 返回最终点,带有螺旋效果
  67. return new Vec3(x + xOffset, y, z + zOffset);
  68. };
  69. let createdNodes = 0; // 已生成的节点计数
  70. let animationStopped = false; // 控制动画是否已经停止
  71. let t = 0; // 进度 t,0 为起点,1 为终点
  72. const updatePosition = () => {
  73. if (animationStopped) return; // 如果动画已停止,则不继续执行
  74. // 继续使用贝塞尔曲线计算,带螺旋效果
  75. this.node.position = twoBezier(t, startPos, middlePos, destPos); // 根据进度生成新节点
  76. let cube = this.Container.getCube();
  77. if (cube != null && cube.getComponent(_crd && Cube_Infor === void 0 ? (_reportPossibleCrUseOfCube_Infor({
  78. error: Error()
  79. }), Cube_Infor) : Cube_Infor).state === (_crd && Cube_State === void 0 ? (_reportPossibleCrUseOfCube_State({
  80. error: Error()
  81. }), Cube_State) : Cube_State).live) {
  82. let newNode = cube;
  83. newNode.parent = director.getScene();
  84. newNode.setPosition(this.node.position);
  85. this.Container.nodeReferences.push(newNode);
  86. console.log(cube.getComponent(_crd && Cube_Infor === void 0 ? (_reportPossibleCrUseOfCube_Infor({
  87. error: Error()
  88. }), Cube_Infor) : Cube_Infor).Text);
  89. createdNodes++; // 记录生成的方块
  90. } // 如果没有方块,停止动画
  91. if (cube == null && !animationStopped) {
  92. animationStopped = true; // 设置动画停止标志
  93. console.log("没有方块,停止动画");
  94. this.node.setPosition(this.node.position); // 防止继续更新位置
  95. } // 获取 Container 中的当前方块数量
  96. let totalCubes = this.Container.idioms.length * 2; // 假设 idioms 存储了所有方块的信息
  97. // 如果所有方块都已生成,停止动画
  98. if (createdNodes >= totalCubes) {
  99. animationStopped = true;
  100. this.Container.canTouch = true;
  101. console.log("所有方块已拿完,停止动画");
  102. } // 更新 t 和重新调用动画
  103. if (t < 1) {
  104. t += 0.01; // 每次更新进度
  105. requestAnimationFrame(updatePosition); // 使用 requestAnimationFrame 来继续更新位置
  106. }
  107. }; // 启动动画
  108. updatePosition();
  109. }
  110. }) || _class));
  111. _cclegacy._RF.pop();
  112. _crd = false;
  113. }
  114. };
  115. });
  116. //# sourceMappingURL=635d373e206601884c96847cb1eeeefae856f2ab.js.map