super-hero/assets/cc-game/scripts/global/DelayTimeNode.ts

44 lines
1.1 KiB
TypeScript

import { _decorator, Component, Node } from 'cc';
import { GameGlobalData } from './GameGlobalData';
import { UmLog } from '../../../cc-common/cc-util/UmLog';
const { ccclass, property } = _decorator;
@ccclass('DelayTimeNode')
export class DelayTimeNode extends Component {
enableDelayTime = false;
time: number = 0;
callback: Function = null;
nodeCall: Node = null;
setDelayData(nodeCall: Node, time: number, callback: Function)
{
this.nodeCall = nodeCall;
this.time = time;
this.callback = callback;
this.enableDelayTime = true;
}
update(deltaTime: number) {
if (!GameGlobalData.Instance.isStatePlay()) return;
if (!this.enableDelayTime)
return;
UmLog.log("DELAY TIME => ", this.time);
this.time -= deltaTime;
if (this.time < 0)
{
if (this.nodeCall)
this.callback?.();
this.callback = null;
this.nodeCall = null;
this.enableDelayTime = false;
this.node?.destroy();
}
}
}