123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154 |
- System.register(["cc"], function (_export, _context) {
- "use strict";
- var _cclegacy, __checkObsolete__, __checkObsoleteInNamespace__, _decorator, Label, math, _dec, _dec2, _class, _class2, _descriptor, _crd, ccclass, property, NumRaiseLable;
- 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;
- Label = _cc.Label;
- math = _cc.math;
- }],
- execute: function () {
- _crd = true;
- _cclegacy._RF.push({}, "3f43dXREG5P1LIco7w9mkJo", "NumRaiseLable", undefined);
- __checkObsolete__(['_decorator', 'Component', 'Label', 'math', 'Node']);
- ({
- ccclass,
- property
- } = _decorator);
- /**
- * 调用事例
- * this.combatLable.startCounting(data.total);
- */
- //数字自增长
- _export("NumRaiseLable", NumRaiseLable = (_dec = ccclass('NumRaiseLable'), _dec2 = property({
- tooltip: '数字增长动画持续时间(秒)'
- }), _dec(_class = (_class2 = class NumRaiseLable extends Label {
- constructor() {
- super(...arguments);
- // 动画持续时间(秒)
- _initializerDefineProperty(this, "_duration", _descriptor, this);
- // 当前显示的数字
- this._currentValue = 0;
- // 目标数字
- this._targetValue = 0;
- // 是否正在播放动画
- this._isAnimating = false;
- // 每帧增量
- this._incrementPerFrame = 0;
- }
- get duration() {
- return this._duration;
- }
- set duration(value) {
- this._duration = math.clamp(value, 0.1, 5);
- }
- /**
- * 开始数字增长动画
- * @param targetValue 目标数值
- * @param duration 可选,动画持续时间(秒),默认使用组件设置的duration
- */
- startCounting(targetValue, duration) {
- if (this._isAnimating) {
- this.stopCounting();
- } //使用传入的duration或默认值
- var animDuration = duration != null ? duration : this._duration;
- this._targetValue = targetValue;
- this._currentValue = 0;
- this._isAnimating = true; //计算每帧增量(假设60FPS)
- this._incrementPerFrame = this._targetValue / (animDuration * 60); //取消之前的调度
- this.unschedule(this.updateNumber); //开始新的调度
- this.schedule(this.updateNumber, 1 / 60);
- }
- /**
- * 停止数字增长动画
- */
- stopCounting() {
- this._isAnimating = false;
- this.unschedule(this.updateNumber);
- this._currentValue = this._targetValue;
- this.updateDisplay();
- }
- /**
- * 立即完成动画
- */
- completeCounting() {
- this.stopCounting();
- this._currentValue = this._targetValue;
- this.updateDisplay();
- }
- /**
- * 每帧更新数字
- */
- updateNumber() {
- if (!this._isAnimating) return;
- this._currentValue += this._incrementPerFrame; //确保不超过目标值
- if (this._currentValue >= this._targetValue) {
- this._currentValue = this._targetValue;
- this._isAnimating = false;
- this.unschedule(this.updateNumber);
- }
- this.updateDisplay();
- }
- /**
- * 更新显示文本
- */
- updateDisplay() {
- this.string = Math.floor(this._currentValue).toString();
- } //组件销毁时清理
- onDestroy() {
- this.unschedule(this.updateNumber);
- }
- }, (_descriptor = _applyDecoratedDescriptor(_class2.prototype, "_duration", [_dec2], {
- configurable: true,
- enumerable: true,
- writable: true,
- initializer: function initializer() {
- return 0.5;
- }
- }), _applyDecoratedDescriptor(_class2.prototype, "duration", [property], Object.getOwnPropertyDescriptor(_class2.prototype, "duration"), _class2.prototype)), _class2)) || _class));
- _cclegacy._RF.pop();
- _crd = false;
- }
- };
- });
- //# sourceMappingURL=ba907ee3b30856981d888e17fe9cc9d245e64503.js.map
|