mirror of
https://github.com/wyb10a10/cocos_creator_framework.git
synced 2026-05-19 16:56:07 +08:00
25 lines
512 B
TypeScript
25 lines
512 B
TypeScript
export class Counter {
|
||
|
||
private _min: number;
|
||
private _max: number;
|
||
private _last: number;
|
||
|
||
constructor(min: number = 1, max: number = Number.MAX_SAFE_INTEGER) {
|
||
this._min = min;
|
||
this._max = max;
|
||
this._last = max;
|
||
}
|
||
|
||
/** 复位:从新从0开始计数 */
|
||
reset() {
|
||
this._last = this._max;
|
||
}
|
||
|
||
getNext() {
|
||
return this._last >= this._max ? (this._last = this._min) : ++this._last;
|
||
}
|
||
|
||
getlast() {
|
||
return this._last;
|
||
}
|
||
} |