c1ddb3f39b92f3b2053abafc56a08e0b6049aa42.js 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. System.register(["cc"], function (_export, _context) {
  2. "use strict";
  3. var _cclegacy, __checkObsolete__, __checkObsoleteInNamespace__, Node, Vec2, js, v3, _crd, _DragEvent;
  4. return {
  5. setters: [function (_cc) {
  6. _cclegacy = _cc.cclegacy;
  7. __checkObsolete__ = _cc.__checkObsolete__;
  8. __checkObsoleteInNamespace__ = _cc.__checkObsoleteInNamespace__;
  9. Node = _cc.Node;
  10. Vec2 = _cc.Vec2;
  11. js = _cc.js;
  12. v3 = _cc.v3;
  13. }],
  14. execute: function () {
  15. _crd = true;
  16. _cclegacy._RF.push({}, "1a072/udu9MtbdbyL5xB8iR", "NodeDragExt", undefined);
  17. /** 节点拖拽功能 */
  18. //@ts-ignore
  19. __checkObsolete__(['EventTouch', 'Node', 'Vec2', 'js', 'v3']);
  20. if (!Node.prototype["__$NodeDragExt$__"]) {
  21. //@ts-ignore
  22. Node.prototype["__$NodeDragExt$__"] = true;
  23. _DragEvent = {
  24. DRAG_START: "drag_start",
  25. DRAG_MOVE: "drag_move",
  26. DRAG_END: "drag_end"
  27. };
  28. js.mixin(Node, {
  29. DragEvent: _DragEvent
  30. }); //---------------- Node 添加 拖拽属性 ----------------
  31. js.mixin(Node.prototype, {
  32. _draggable: false,
  33. _dragging: false,
  34. _dragTesting: false,
  35. _dragStartPoint: null,
  36. initDrag: function initDrag() {
  37. if (this._draggable) {
  38. this.on(Node.EventType.TOUCH_START, this.onTouchBegin_0, this);
  39. this.on(Node.EventType.TOUCH_MOVE, this.onTouchMove_0, this);
  40. this.on(Node.EventType.TOUCH_END, this.onTouchEnd_0, this);
  41. this.on(Node.EventType.TOUCH_CANCEL, this.onTouchCancel_0, this);
  42. } else {
  43. this.off(Node.EventType.TOUCH_START, this.onTouchBegin_0, this);
  44. this.off(Node.EventType.TOUCH_MOVE, this.onTouchMove_0, this);
  45. this.off(Node.EventType.TOUCH_END, this.onTouchEnd_0, this);
  46. this.off(Node.EventType.TOUCH_CANCEL, this.onTouchCancel_0, this);
  47. }
  48. },
  49. onTouchBegin_0: function onTouchBegin_0(event) {
  50. if (this._dragStartPoint == null) {
  51. this._dragStartPoint = new Vec2();
  52. } // DEV && console.log(`NodeDragExt -> onTouchBegin_0 ${this.name}`);
  53. // event.preventSwallow = true;
  54. var pos = event.getUILocation();
  55. this._dragStartPoint.set(pos);
  56. this._dragTesting = true;
  57. },
  58. onTouchMove_0: function onTouchMove_0(event) {
  59. if (!this._dragging && this._draggable && this._dragTesting) {
  60. var sensitivity = 10;
  61. var pos = event.getUILocation();
  62. if (Math.abs(this._dragStartPoint.x - pos.x) < sensitivity && Math.abs(this._dragStartPoint.y - pos.y) < sensitivity) {
  63. return;
  64. } // event.preventSwallow = true;
  65. this._dragging = true;
  66. this._dragTesting = false;
  67. this.emit(Node.DragEvent.DRAG_START, event);
  68. }
  69. if (this._dragging) {
  70. var delta = event.getUIDelta(); // /** 这里除以 世界缩放,在有缩放的时候拖拽不至于很怪 */
  71. // this.position = this.position.add(v3(delta.x / this.worldScale.x, delta.y / this.worldScale.y, 0));
  72. var newPos = v3(delta.x, delta.y, 0).add(this.position);
  73. this.position = newPos;
  74. this.emit(Node.DragEvent.DRAG_MOVE, event);
  75. }
  76. },
  77. onTouchEnd_0: function onTouchEnd_0(event) {
  78. if (this._dragging) {
  79. this._dragging = false;
  80. this.emit(Node.DragEvent.DRAG_END, event);
  81. } // DEV && console.log(`NodeDragExt -> onTouchEnd_0 ${this.name}, _dragging: ${this._dragging}`);
  82. },
  83. onTouchCancel_0: function onTouchCancel_0(event) {
  84. if (this._dragging) {
  85. this._dragging = false;
  86. this.emit(Node.DragEvent.DRAG_END, event);
  87. } // DEV && console.log(`NodeDragExt -> onTouchCancel_0 ${this.name}, _dragging: ${this._dragging}`);
  88. },
  89. startDrag: function startDrag() {
  90. // 此节点是否在场景中激活
  91. if (!this.activeInHierarchy) {
  92. return;
  93. }
  94. this.dragBegin();
  95. },
  96. dragBegin: function dragBegin() {
  97. this._dragging = true;
  98. this._dragTesting = true;
  99. this.on(Node.EventType.TOUCH_MOVE, this.onTouchMove_0, this);
  100. this.on(Node.EventType.TOUCH_END, this.onTouchEnd_0, this);
  101. this.on(Node.EventType.TOUCH_CANCEL, this.onTouchCancel_0, this);
  102. },
  103. dragEnd: function dragEnd() {
  104. if (this._dragging) {
  105. this._dragTesting = false;
  106. this._dragging = false;
  107. }
  108. },
  109. // 停止拖拽
  110. stopDrag: function stopDrag() {
  111. this.dragEnd();
  112. },
  113. // 移除 touch 事件
  114. removeDragEvent: function removeDragEvent() {
  115. this.off(Node.EventType.TOUCH_START, this.onTouchBegin_0, this);
  116. this.off(Node.EventType.TOUCH_MOVE, this.onTouchMove_0, this);
  117. this.off(Node.EventType.TOUCH_END, this.onTouchEnd_0, this);
  118. this.off(Node.EventType.TOUCH_CANCEL, this.onTouchCancel_0, this);
  119. }
  120. }); // 如果 node 设置 node.draggable = true, 则启用 拖拽
  121. Object.defineProperty(Node.prototype, "draggable", {
  122. get: function get() {
  123. return this._draggable;
  124. },
  125. set: function set(value) {
  126. if (this._draggable != value) {
  127. this._draggable = value;
  128. this.initDrag();
  129. }
  130. },
  131. enumerable: true,
  132. configurable: true
  133. });
  134. Object.defineProperty(Node.prototype, "dragTesting", {
  135. get: function get() {
  136. return this._dragTesting;
  137. },
  138. set: function set(value) {
  139. if (this._dragTesting != value) {
  140. this._dragTesting = value;
  141. }
  142. },
  143. enumerable: true,
  144. configurable: true
  145. }); //---------------- Node 添加 拖拽属性 ----------------
  146. }
  147. _cclegacy._RF.pop();
  148. _crd = false;
  149. }
  150. };
  151. });
  152. //# sourceMappingURL=c1ddb3f39b92f3b2053abafc56a08e0b6049aa42.js.map