觉醒时刻
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
juexingshike/assets/FrameWork/Mgr/TimerUtils.ts

95 lines
2.4 KiB

1 week ago
/*
* @Descripttion:
* @version: 1.0.0
* @Author: YeeChan
* @Date: 2020-07-23 16:59:58
*/
/**
* Timer工具
*/
export class TimerUtils {
/**
*
* @param handler
* @param interval
* @param repeat repeat + 1
* @param delay
*/
public static loopNum_custom(handler: Function, interval: number, repeat: number, delay: number) {
return this.schedule_custom(handler, interval, repeat, delay);
}
/**
*
* @param handler
* @param delayTime
*/
public static once_custom(handler: Function, delayTime: number = 0) {
return this.scheduleOnce_custom(handler, delayTime);
}
/**
*
* @param handler
* @param intervlTime 0
* @param delay
*/
public static loop_custom(handler: Function, intervlTime: number = 0, delay: number = 0) {
return this.schedule_custom(handler, intervlTime ? intervlTime : 0.02, cc.macro.REPEAT_FOREVER, delay);
}
/**
* Timer
* @param handler
*/
public static removeTimer_custom(handler: Function) {
this.unschedule_custom(handler);
}
/**
* Timer
*/
public static removeAllTimers_custom() {
cc.director.getScheduler().unscheduleAllForTarget(this)
}
/**
*
* @param handler
* @param delay
*/
private static scheduleOnce_custom(handler: Function, delay: number) {
this.schedule_custom(handler, 0, 0, delay);
return handler;
}
/**
* Timer开始调度
* @param handler
* @param interval
* @param repeat repeat + 1
* @param delay
*/
private static schedule_custom(handler: Function, interval: number, repeat: number, delay: number) {
cc.director.getScheduler().schedule(handler, this, interval, repeat, delay);
return handler;
}
/**
*
* @param handler
*/
private static unschedule_custom(handler: Function) {
if (!handler) return;
cc.director.getScheduler().unschedule(handler, this);
}
}