|
|
@@ -21,11 +21,11 @@ export default class TimerSystem extends cc.Component {
|
|
|
for (var i: number = 0; i < this.timerArr.length; i++) {
|
|
|
var gameTimer: Timer = this.timerArr[i];
|
|
|
var callBack: Function = gameTimer.callBack;
|
|
|
- var object: any = gameTimer.object;
|
|
|
+ var target: any = gameTimer.target;
|
|
|
gameTimer.curTime--;
|
|
|
if (gameTimer.curTime <= 0) {
|
|
|
gameTimer.curTime = gameTimer.totalTime;
|
|
|
- callBack.call(object);
|
|
|
+ callBack.call(target);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -35,26 +35,26 @@ export default class TimerSystem extends cc.Component {
|
|
|
* @description
|
|
|
* @param time 计时的时间
|
|
|
* @param callBack 计时结束之后的回调
|
|
|
- * @param object 计时绑定的对象
|
|
|
+ * @param target 计时绑定的脚本对象
|
|
|
*/
|
|
|
- public addTimer(time: number, callBack: Function, object: any) {
|
|
|
- if (!this.ifHasSameTimer(callBack, object)) {
|
|
|
+ public addTimer(time: number, callBack: Function, target: any) {
|
|
|
+ if (!this.ifHasSameTimer(callBack, target)) {
|
|
|
let gameTimer = new Timer();
|
|
|
gameTimer.curTime = time;
|
|
|
gameTimer.totalTime = time;
|
|
|
gameTimer.callBack = callBack;
|
|
|
- gameTimer.object = object;
|
|
|
+ gameTimer.target = target;
|
|
|
this.timerArr.push(gameTimer);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 是否有相同的时间管理器
|
|
|
- * @param callBack 比对的回调
|
|
|
- * @param object 比对的对象
|
|
|
+ * @param callBack 回调方法
|
|
|
+ * @param target 绑定的对象
|
|
|
*/
|
|
|
- private ifHasSameTimer(callBack: Function, object: any): boolean {
|
|
|
- if (this.getTimer(callBack, object)) {
|
|
|
+ private ifHasSameTimer(callBack: Function, target: any): boolean {
|
|
|
+ if (this.getTimer(callBack, target)) {
|
|
|
//重复添加时间计时器
|
|
|
return true;
|
|
|
}
|
|
|
@@ -63,11 +63,15 @@ export default class TimerSystem extends cc.Component {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- /** 获取时间管理器 */
|
|
|
- private getTimer(callBack: Function, object: any): Timer {
|
|
|
+ /**
|
|
|
+ * 获取时间管理器
|
|
|
+ * @param callBack 回调方法
|
|
|
+ * @param target 绑定的对象
|
|
|
+ */
|
|
|
+ private getTimer(callBack: Function, target: any): Timer {
|
|
|
for (var i: number = this.timerArr.length - 1; i >= 0; i--) {
|
|
|
let gameTimer: Timer = this.timerArr[i];
|
|
|
- if (gameTimer.callBack == callBack && gameTimer.object == object) {
|
|
|
+ if (gameTimer.callBack == callBack && gameTimer.target == target) {
|
|
|
return gameTimer;
|
|
|
}
|
|
|
}
|
|
|
@@ -76,13 +80,13 @@ export default class TimerSystem extends cc.Component {
|
|
|
|
|
|
/**
|
|
|
* 移除时间管理器
|
|
|
- * @param callBack
|
|
|
- * @param object
|
|
|
+ * @param callBack 回调方法
|
|
|
+ * @param target 绑定的对象
|
|
|
*/
|
|
|
- public removeTimer(callBack: Function, object: any) {
|
|
|
+ public removeTimer(callBack: Function, target: any) {
|
|
|
for (var i: number = this.timerArr.length - 1; i >= 0; i--) {
|
|
|
let timer: Timer = this.timerArr[i];
|
|
|
- if (timer.callBack == callBack && timer.object == object) {
|
|
|
+ if (timer.callBack == callBack && timer.target == target) {
|
|
|
this.timerArr.splice(i, 1)
|
|
|
//gameTimer = null; //要不要加null 看最后的效果
|
|
|
return;
|
|
|
@@ -100,5 +104,5 @@ export class Timer {
|
|
|
/** 计时的回调 */
|
|
|
callBack: Function = null;
|
|
|
/** 绑定的脚本对象 */
|
|
|
- object: any = null;
|
|
|
+ target: any = null;
|
|
|
}
|