123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155 |
- System.register(["cc"], function (_export, _context) {
- "use strict";
- var _cclegacy, __checkObsolete__, __checkObsoleteInNamespace__, _decorator, Component, Node, quat, tween, Tween, Vec3, _dec, _dec2, _dec3, _dec4, _class, _class2, _descriptor, _descriptor2, _descriptor3, _crd, ccclass, property, ModelRotator;
- function _initializerDefineProperty(target, property, descriptor, context) { if (!descriptor) return; Object.defineProperty(target, property, { enumerable: descriptor.enumerable, configurable: descriptor.configurable, writable: descriptor.writable, value: descriptor.initializer ? descriptor.initializer.call(context) : void 0 }); }
- function _applyDecoratedDescriptor(target, property, decorators, descriptor, context) { var desc = {}; Object.keys(descriptor).forEach(function (key) { desc[key] = descriptor[key]; }); desc.enumerable = !!desc.enumerable; desc.configurable = !!desc.configurable; if ('value' in desc || desc.initializer) { desc.writable = true; } desc = decorators.slice().reverse().reduce(function (desc, decorator) { return decorator(target, property, desc) || desc; }, desc); if (context && desc.initializer !== void 0) { desc.value = desc.initializer ? desc.initializer.call(context) : void 0; desc.initializer = undefined; } if (desc.initializer === void 0) { Object.defineProperty(target, property, desc); desc = null; } return desc; }
- function _initializerWarningHelper(descriptor, context) { throw new Error('Decorating class property failed. Please ensure that ' + 'transform-class-properties is enabled and runs after the decorators transform.'); }
- return {
- setters: [function (_cc) {
- _cclegacy = _cc.cclegacy;
- __checkObsolete__ = _cc.__checkObsolete__;
- __checkObsoleteInNamespace__ = _cc.__checkObsoleteInNamespace__;
- _decorator = _cc._decorator;
- Component = _cc.Component;
- Node = _cc.Node;
- quat = _cc.quat;
- tween = _cc.tween;
- Tween = _cc.Tween;
- Vec3 = _cc.Vec3;
- }],
- execute: function () {
- _crd = true;
- _cclegacy._RF.push({}, "70003AYwQ5EK6B4bgpBRvvR", "ModelRotator", undefined);
- __checkObsolete__(['_decorator', 'Component', 'EventTouch', 'Input', 'input', 'Node', 'quat', 'Quat', 'tween', 'Tween', 'Vec3']);
- ({
- ccclass,
- property
- } = _decorator);
- _export("ModelRotator", ModelRotator = (_dec = ccclass('ModelRotator'), _dec2 = property({
- tooltip: '初始旋转速度(度/秒)'
- }), _dec3 = property({
- tooltip: '触摸后的减速系数(0-1)'
- }), _dec4 = property({
- tooltip: '斜角旋转的X轴角度(度)'
- }), _dec(_class = (_class2 = class ModelRotator extends Component {
- constructor() {
- super(...arguments);
- _initializerDefineProperty(this, "speed", _descriptor, this);
- _initializerDefineProperty(this, "touchDeceleration", _descriptor2, this);
- _initializerDefineProperty(this, "tiltAngle", _descriptor3, this);
- // 改为36度斜角
- // 新增Canvas节点引用
- this.canvasNode = null;
- this._targetQuat = quat();
- this._currentSpeed = 0;
- this._touchStartX = 0;
- this._isDragging = false;
- this._baseRotation = new Vec3();
- }
- start() {
- this.canvasNode = this.node.parent.parent; // 设置斜角旋转(X轴36度 + Z轴旋转)
- this._baseRotation.set(this.tiltAngle, 0, -this.tiltAngle); // 增加Z轴倾斜
- this.node.setRotationFromEuler(this._baseRotation); // 删除冗余的全局input监听
- this.canvasNode.on(Node.EventType.TOUCH_START, this.onTouchStart, this);
- this.canvasNode.on(Node.EventType.TOUCH_MOVE, this.onTouchMove, this);
- this.canvasNode.on(Node.EventType.TOUCH_END, this.onTouchEnd, this); // 初始化自动旋转
- this._currentSpeed = this.speed;
- this.startAutoRotation();
- }
- startAutoRotation() {
- tween(this.node).by(1, {
- //改为绕Z轴旋转
- eulerAngles: new Vec3(this._currentSpeed, 0, -this._currentSpeed)
- }).repeatForever().start();
- }
- onTouchMove(event) {
- if (!this._isDragging) return; // 改进差值计算方式
- var currentX = event.getUILocation().x;
- var deltaX = currentX - this._touchStartX;
- this._touchStartX = currentX; // 改为同时更新Z轴旋转
- var currentEuler = this.node.eulerAngles.clone();
- currentEuler.z += deltaX * 0.5; // 绕Z轴旋转
- this.node.setRotationFromEuler(new Vec3(this.tiltAngle, // 保持X轴斜角
- 0, // 固定Y轴
- currentEuler.z // Z轴旋转
- ));
- }
- onTouchStart(event) {
- this._touchStartX = event.getLocationX();
- this._isDragging = true;
- this._currentSpeed = 0; // 停止自动旋转
- Tween.stopAllByTarget(this.node);
- }
- onTouchEnd() {
- this._isDragging = false; // 添加惯性滑动效果
- this._currentSpeed = this.speed * this.touchDeceleration;
- this.startAutoRotation();
- }
- onDestroy() {
- //改为Canvas节点的事件解绑
- if (this.canvasNode) {
- this.canvasNode.off(Node.EventType.TOUCH_START, this.onTouchStart, this);
- this.canvasNode.off(Node.EventType.TOUCH_MOVE, this.onTouchMove, this);
- this.canvasNode.off(Node.EventType.TOUCH_END, this.onTouchEnd, this);
- }
- }
- }, (_descriptor = _applyDecoratedDescriptor(_class2.prototype, "speed", [_dec2], {
- configurable: true,
- enumerable: true,
- writable: true,
- initializer: function initializer() {
- return 45;
- }
- }), _descriptor2 = _applyDecoratedDescriptor(_class2.prototype, "touchDeceleration", [_dec3], {
- configurable: true,
- enumerable: true,
- writable: true,
- initializer: function initializer() {
- return 0.95;
- }
- }), _descriptor3 = _applyDecoratedDescriptor(_class2.prototype, "tiltAngle", [_dec4], {
- configurable: true,
- enumerable: true,
- writable: true,
- initializer: function initializer() {
- return 36;
- }
- })), _class2)) || _class));
- _cclegacy._RF.pop();
- _crd = false;
- }
- };
- });
- //# sourceMappingURL=b96b47e1de4520b3e54fe6923b0d5370c7a1552f.js.map
|