| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173 |
- System.register(["cc"], function (_export, _context) {
- "use strict";
- var _cclegacy, __checkObsolete__, __checkObsoleteInNamespace__, Node, Vec2, js, v3, _crd, _DragEvent;
- return {
- setters: [function (_cc) {
- _cclegacy = _cc.cclegacy;
- __checkObsolete__ = _cc.__checkObsolete__;
- __checkObsoleteInNamespace__ = _cc.__checkObsoleteInNamespace__;
- Node = _cc.Node;
- Vec2 = _cc.Vec2;
- js = _cc.js;
- v3 = _cc.v3;
- }],
- execute: function () {
- _crd = true;
- _cclegacy._RF.push({}, "1a072/udu9MtbdbyL5xB8iR", "NodeDragExt", undefined);
- /** 节点拖拽功能 */
- //@ts-ignore
- __checkObsolete__(['EventTouch', 'Node', 'Vec2', 'js', 'v3']);
- if (!Node.prototype["__$NodeDragExt$__"]) {
- //@ts-ignore
- Node.prototype["__$NodeDragExt$__"] = true;
- _DragEvent = {
- DRAG_START: "drag_start",
- DRAG_MOVE: "drag_move",
- DRAG_END: "drag_end"
- };
- js.mixin(Node, {
- DragEvent: _DragEvent
- }); //---------------- Node 添加 拖拽属性 ----------------
- js.mixin(Node.prototype, {
- _draggable: false,
- _dragging: false,
- _dragTesting: false,
- _dragStartPoint: null,
- initDrag: function initDrag() {
- if (this._draggable) {
- this.on(Node.EventType.TOUCH_START, this.onTouchBegin_0, this);
- this.on(Node.EventType.TOUCH_MOVE, this.onTouchMove_0, this);
- this.on(Node.EventType.TOUCH_END, this.onTouchEnd_0, this);
- this.on(Node.EventType.TOUCH_CANCEL, this.onTouchCancel_0, this);
- } else {
- this.off(Node.EventType.TOUCH_START, this.onTouchBegin_0, this);
- this.off(Node.EventType.TOUCH_MOVE, this.onTouchMove_0, this);
- this.off(Node.EventType.TOUCH_END, this.onTouchEnd_0, this);
- this.off(Node.EventType.TOUCH_CANCEL, this.onTouchCancel_0, this);
- }
- },
- onTouchBegin_0: function onTouchBegin_0(event) {
- if (this._dragStartPoint == null) {
- this._dragStartPoint = new Vec2();
- } // DEV && console.log(`NodeDragExt -> onTouchBegin_0 ${this.name}`);
- // event.preventSwallow = true;
- var pos = event.getUILocation();
- this._dragStartPoint.set(pos);
- this._dragTesting = true;
- },
- onTouchMove_0: function onTouchMove_0(event) {
- if (!this._dragging && this._draggable && this._dragTesting) {
- var sensitivity = 10;
- var pos = event.getUILocation();
- if (Math.abs(this._dragStartPoint.x - pos.x) < sensitivity && Math.abs(this._dragStartPoint.y - pos.y) < sensitivity) {
- return;
- } // event.preventSwallow = true;
- this._dragging = true;
- this._dragTesting = false;
- this.emit(Node.DragEvent.DRAG_START, event);
- }
- if (this._dragging) {
- var delta = event.getUIDelta(); // /** 这里除以 世界缩放,在有缩放的时候拖拽不至于很怪 */
- // this.position = this.position.add(v3(delta.x / this.worldScale.x, delta.y / this.worldScale.y, 0));
- var newPos = v3(delta.x, delta.y, 0).add(this.position);
- this.position = newPos;
- this.emit(Node.DragEvent.DRAG_MOVE, event);
- }
- },
- onTouchEnd_0: function onTouchEnd_0(event) {
- if (this._dragging) {
- this._dragging = false;
- this.emit(Node.DragEvent.DRAG_END, event);
- } // DEV && console.log(`NodeDragExt -> onTouchEnd_0 ${this.name}, _dragging: ${this._dragging}`);
- },
- onTouchCancel_0: function onTouchCancel_0(event) {
- if (this._dragging) {
- this._dragging = false;
- this.emit(Node.DragEvent.DRAG_END, event);
- } // DEV && console.log(`NodeDragExt -> onTouchCancel_0 ${this.name}, _dragging: ${this._dragging}`);
- },
- startDrag: function startDrag() {
- // 此节点是否在场景中激活
- if (!this.activeInHierarchy) {
- return;
- }
- this.dragBegin();
- },
- dragBegin: function dragBegin() {
- this._dragging = true;
- this._dragTesting = true;
- this.on(Node.EventType.TOUCH_MOVE, this.onTouchMove_0, this);
- this.on(Node.EventType.TOUCH_END, this.onTouchEnd_0, this);
- this.on(Node.EventType.TOUCH_CANCEL, this.onTouchCancel_0, this);
- },
- dragEnd: function dragEnd() {
- if (this._dragging) {
- this._dragTesting = false;
- this._dragging = false;
- }
- },
- // 停止拖拽
- stopDrag: function stopDrag() {
- this.dragEnd();
- },
- // 移除 touch 事件
- removeDragEvent: function removeDragEvent() {
- this.off(Node.EventType.TOUCH_START, this.onTouchBegin_0, this);
- this.off(Node.EventType.TOUCH_MOVE, this.onTouchMove_0, this);
- this.off(Node.EventType.TOUCH_END, this.onTouchEnd_0, this);
- this.off(Node.EventType.TOUCH_CANCEL, this.onTouchCancel_0, this);
- }
- }); // 如果 node 设置 node.draggable = true, 则启用 拖拽
- Object.defineProperty(Node.prototype, "draggable", {
- get: function get() {
- return this._draggable;
- },
- set: function set(value) {
- if (this._draggable != value) {
- this._draggable = value;
- this.initDrag();
- }
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(Node.prototype, "dragTesting", {
- get: function get() {
- return this._dragTesting;
- },
- set: function set(value) {
- if (this._dragTesting != value) {
- this._dragTesting = value;
- }
- },
- enumerable: true,
- configurable: true
- }); //---------------- Node 添加 拖拽属性 ----------------
- }
- _cclegacy._RF.pop();
- _crd = false;
- }
- };
- });
- //# sourceMappingURL=778a8862dad114913c07b0c98b7c902f198b09dd.js.map
|