System.register(["cc"], function (_export, _context) { "use strict"; var _cclegacy, ActionCenter, _crd; function get_new_action_center() { return new ActionCenter(); } _export("default", get_new_action_center); return { setters: [function (_cc) { _cclegacy = _cc.cclegacy; }], execute: function () { _crd = true; _cclegacy._RF.push({}, "24a1fbkvW9AQJ+cc5f2eMnl", "Action", undefined); /**行为机*/ ActionCenter = class ActionCenter { constructor() { this._list = []; this._current = void 0; } /**加入一个创建行为的闭包的函数 * ActionCreat = (...args: any) => Action; * Action ={check:() => boolean,entry:() => void,do:(dt:number)=>void} */ add(actionCreat) { for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { args[_key - 1] = arguments[_key]; } this._list.push(actionCreat(...args)); } /**检测和进入行为*/ check_entry() { var _this$_current; if ((_this$_current = this._current) != null && _this$_current.check()) return; for (var i = 0; i < this._list.length; i++) { if (this._current != this._list[i] && this._list[i].check()) { this._current = this._list[i]; this._current.entry(); return; } } this._current = null; } /**是否有正在执行的行为 */ get isAction() { return this._current != null; } /**执行行为*/ do(dt) { if (this._current) this._current.do(dt); } /**清除所有行为*/ clean() { for (var i = 0; i < this._list.length; i++) { this._list[i].dispose(); } this._list.length = 0; this._current = null; } /*例子 public test():void{ const who={state:0}; this.add((who:{state:number})=>{ 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); }*/ }; _cclegacy._RF.pop(); _crd = false; } }; }); //# sourceMappingURL=4efee4d45a67b1b88aec3633ffce1bf66a05cb6d.js.map