4efee4d45a67b1b88aec3633ffce1bf66a05cb6d.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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, ...args) {
  26. this._list.push(actionCreat(...args));
  27. }
  28. /**检测和进入行为*/
  29. check_entry() {
  30. var _this$_current;
  31. if ((_this$_current = this._current) != null && _this$_current.check()) return;
  32. for (let i = 0; i < this._list.length; i++) {
  33. if (this._current != this._list[i] && this._list[i].check()) {
  34. this._current = this._list[i];
  35. this._current.entry();
  36. return;
  37. }
  38. }
  39. this._current = null;
  40. }
  41. /**是否有正在执行的行为 */
  42. get isAction() {
  43. return this._current != null;
  44. }
  45. /**执行行为*/
  46. do(dt) {
  47. if (this._current) this._current.do(dt);
  48. }
  49. /**清除所有行为*/
  50. clean() {
  51. for (let i = 0; i < this._list.length; i++) {
  52. this._list[i].dispose();
  53. }
  54. this._list.length = 0;
  55. this._current = null;
  56. }
  57. /*例子
  58. public test():void{
  59. const who={state:0};
  60. this.add((who:{state:number})=>{
  61. const w = who;
  62. let time:number=0;
  63. return{
  64. check:()=>{
  65. if(w.state==0){
  66. return true;
  67. }
  68. return false;
  69. },
  70. entry:()=>{
  71. time=0;
  72. console.log("entry 行为1",time);
  73. },
  74. do:(dt:number)=>{
  75. time+=dt;
  76. if(time>=2){
  77. console.log("do",time);
  78. w.state=1;
  79. };
  80. }
  81. }
  82. },who);
  83. this.add((who:{state:number})=>{
  84. const w = who;
  85. let time:number=0;
  86. return{
  87. check:()=>{
  88. if(w.state==1){
  89. return true;
  90. }
  91. return false;
  92. },
  93. entry:()=>{
  94. time=0;
  95. console.log("entry 行为2",time);
  96. },
  97. do:(dt:number)=>{
  98. time+=dt;
  99. if(time>=2){
  100. console.log("do",time);
  101. w.state=0;
  102. };
  103. }
  104. }
  105. },who);
  106. }*/
  107. };
  108. _cclegacy._RF.pop();
  109. _crd = false;
  110. }
  111. };
  112. });
  113. //# sourceMappingURL=4efee4d45a67b1b88aec3633ffce1bf66a05cb6d.js.map