type Action = {check:() => boolean,entry:() => void,do:(dt:number)=>void,exit:() => void}; export type ActionCreat = (...args: any) => Action; /**行为机*/ export class ActionMgr { private _list:Action[]=[]; private _current:Action; /**加入一个创建行为的闭包的函数 * ActionCreat = (...args: any) => Action; * Action ={check:() => boolean,entry:() => void,do:(dt:number)=>void} */ public add(actionCreat:ActionCreat,...args: any):void{ this._list.push(actionCreat(...args)); } /**检测和进入行为*/ public check_entry():void{ if(this._current?.check()) return; this._current?.exit() for(let i=0;i{ const w = who; let time:number=0; return{ check:()=>{ if(w.state==0){ return true; } return false; }, entry:()=>{ time=0; console.log("entry 行为1",time); }, do:(dt:number)=>{ time+=dt; if(time>=2){ console.log("do",time); w.state=1; }; } } },who); this.add((who:{state:number})=>{ const w = who; let time:number=0; return{ check:()=>{ if(w.state==1){ return true; } return false; }, entry:()=>{ time=0; console.log("entry 行为2",time); }, do:(dt:number)=>{ time+=dt; if(time>=2){ console.log("do",time); w.state=0; }; } } },who); }*/ }