9eb6b220c6a487fe6196ff6a55fbce691884fc85.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. System.register(["cc"], function (_export, _context) {
  2. "use strict";
  3. var _cclegacy, ActionCenter, _crd;
  4. function get_new_action_center() {
  5. return new ActionCenter();
  6. }
  7. _export("default", get_new_action_center);
  8. return {
  9. setters: [function (_cc) {
  10. _cclegacy = _cc.cclegacy;
  11. }],
  12. execute: function () {
  13. _crd = true;
  14. _cclegacy._RF.push({}, "24a1fbkvW9AQJ+cc5f2eMnl", "Action", undefined);
  15. /**行为机*/
  16. ActionCenter = class ActionCenter {
  17. constructor() {
  18. this._list = [];
  19. this._current = void 0;
  20. }
  21. /**加入一个创建行为的闭包的函数
  22. * ActionCreat = (...args: any) => Action;
  23. * Action ={check:() => boolean,entry:() => void,do:(dt:number)=>void}
  24. */
  25. add(actionCreat) {
  26. for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
  27. args[_key - 1] = arguments[_key];
  28. }
  29. this._list.push(actionCreat(...args));
  30. }
  31. /**检测和进入行为*/
  32. check_entry() {
  33. var _this$_current;
  34. if ((_this$_current = this._current) != null && _this$_current.check()) return;
  35. for (var i = 0; i < this._list.length; i++) {
  36. if (this._current != this._list[i] && this._list[i].check()) {
  37. this._current = this._list[i];
  38. this._current.entry();
  39. return;
  40. }
  41. }
  42. this._current = null;
  43. }
  44. /**是否有正在执行的行为 */
  45. get isAction() {
  46. return this._current != null;
  47. }
  48. /**执行行为*/
  49. do(dt) {
  50. if (this._current) this._current.do(dt);
  51. }
  52. /**清除所有行为*/
  53. clean() {
  54. for (var i = 0; i < this._list.length; i++) {
  55. this._list[i].dispose();
  56. }
  57. this._list.length = 0;
  58. this._current = null;
  59. }
  60. /*例子
  61. public test():void{
  62. const who={state:0};
  63. this.add((who:{state:number})=>{
  64. const w = who;
  65. let time:number=0;
  66. return{
  67. check:()=>{
  68. if(w.state==0){
  69. return true;
  70. }
  71. return false;
  72. },
  73. entry:()=>{
  74. time=0;
  75. console.log("entry 行为1",time);
  76. },
  77. do:(dt:number)=>{
  78. time+=dt;
  79. if(time>=2){
  80. console.log("do",time);
  81. w.state=1;
  82. };
  83. }
  84. }
  85. },who);
  86. this.add((who:{state:number})=>{
  87. const w = who;
  88. let time:number=0;
  89. return{
  90. check:()=>{
  91. if(w.state==1){
  92. return true;
  93. }
  94. return false;
  95. },
  96. entry:()=>{
  97. time=0;
  98. console.log("entry 行为2",time);
  99. },
  100. do:(dt:number)=>{
  101. time+=dt;
  102. if(time>=2){
  103. console.log("do",time);
  104. w.state=0;
  105. };
  106. }
  107. }
  108. },who);
  109. }*/
  110. };
  111. _cclegacy._RF.pop();
  112. _crd = false;
  113. }
  114. };
  115. });
  116. //# sourceMappingURL=9eb6b220c6a487fe6196ff6a55fbce691884fc85.js.map