123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142 |
- 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=9eb6b220c6a487fe6196ff6a55fbce691884fc85.js.map
|