8a9034108f6f9a1a4af078b3eac080d89de67710.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  1. System.register(["__unresolved_0", "cc", "__unresolved_1"], function (_export, _context) {
  2. "use strict";
  3. var _reporterNs, _cclegacy, __checkObsolete__, __checkObsoleteInNamespace__, Component, JsonAsset, _decorator, AnimatorController, _dec, _dec2, _dec3, _dec4, _dec5, _class, _class2, _descriptor, _descriptor2, _descriptor3, _crd, ccclass, property, executionOrder, menu, AnimatorBase;
  4. function _initializerDefineProperty(target, property, descriptor, context) { if (!descriptor) return; Object.defineProperty(target, property, { enumerable: descriptor.enumerable, configurable: descriptor.configurable, writable: descriptor.writable, value: descriptor.initializer ? descriptor.initializer.call(context) : void 0 }); }
  5. function _applyDecoratedDescriptor(target, property, decorators, descriptor, context) { var desc = {}; Object.keys(descriptor).forEach(function (key) { desc[key] = descriptor[key]; }); desc.enumerable = !!desc.enumerable; desc.configurable = !!desc.configurable; if ('value' in desc || desc.initializer) { desc.writable = true; } desc = decorators.slice().reverse().reduce(function (desc, decorator) { return decorator(target, property, desc) || desc; }, desc); if (context && desc.initializer !== void 0) { desc.value = desc.initializer ? desc.initializer.call(context) : void 0; desc.initializer = undefined; } if (desc.initializer === void 0) { Object.defineProperty(target, property, desc); desc = null; } return desc; }
  6. function _initializerWarningHelper(descriptor, context) { throw new Error('Decorating class property failed. Please ensure that ' + 'transform-class-properties is enabled and runs after the decorators transform.'); }
  7. function _reportPossibleCrUseOfAnimatorController(extras) {
  8. _reporterNs.report("AnimatorController", "./AnimatorController", _context.meta, extras);
  9. }
  10. function _reportPossibleCrUseOfAnimatorState(extras) {
  11. _reporterNs.report("AnimatorState", "./AnimatorState", _context.meta, extras);
  12. }
  13. function _reportPossibleCrUseOfAnimatorStateLogic(extras) {
  14. _reporterNs.report("AnimatorStateLogic", "./AnimatorStateLogic", _context.meta, extras);
  15. }
  16. return {
  17. setters: [function (_unresolved_) {
  18. _reporterNs = _unresolved_;
  19. }, function (_cc) {
  20. _cclegacy = _cc.cclegacy;
  21. __checkObsolete__ = _cc.__checkObsolete__;
  22. __checkObsoleteInNamespace__ = _cc.__checkObsoleteInNamespace__;
  23. Component = _cc.Component;
  24. JsonAsset = _cc.JsonAsset;
  25. _decorator = _cc._decorator;
  26. }, function (_unresolved_2) {
  27. AnimatorController = _unresolved_2.default;
  28. }],
  29. execute: function () {
  30. _crd = true;
  31. _cclegacy._RF.push({}, "7ff14NOug1NAIB1XgQlC9Gc", "AnimatorBase", undefined);
  32. __checkObsolete__(['Component', 'JsonAsset', '_decorator']);
  33. ({
  34. ccclass,
  35. property,
  36. executionOrder,
  37. menu
  38. } = _decorator);
  39. /**
  40. * 自定义控制动画播放的接口
  41. */
  42. /**
  43. * 状态机组件基类 优先执行生命周期
  44. */
  45. _export("default", AnimatorBase = (_dec = executionOrder(-1000), _dec2 = menu('animator/AnimatorBase'), _dec3 = property({
  46. type: JsonAsset,
  47. tooltip: '状态机json文件'
  48. }), _dec4 = property({
  49. tooltip: '是否在start中自动启动状态机'
  50. }), _dec5 = property({
  51. tooltip: '是否在update中自动触发状态机逻辑更新'
  52. }), ccclass(_class = _dec(_class = _dec2(_class = (_class2 = class AnimatorBase extends Component {
  53. constructor() {
  54. super(...arguments);
  55. /** ---------- 后续扩展代码 结束 ---------- */
  56. _initializerDefineProperty(this, "AssetRawUrl", _descriptor, this);
  57. _initializerDefineProperty(this, "PlayOnStart", _descriptor2, this);
  58. _initializerDefineProperty(this, "AutoUpdate", _descriptor3, this);
  59. /** 是否初始化 */
  60. this._hasInit = false;
  61. /** 状态机控制 */
  62. this._ac = null;
  63. /** 各个状态逻辑控制,key为状态名 */
  64. this._stateLogicMap = null;
  65. /** 状态切换时的回调 */
  66. this._onStateChangeCall = null;
  67. /** 自定义的动画播放控制器 */
  68. this._animationPlayer = null;
  69. }
  70. /** ---------- 后续扩展代码 开始 ---------- */
  71. /** 三维骨骼动画动画帧自定义事件 */
  72. onFrameEvent(param) {
  73. var _this$_animationPlaye;
  74. (_this$_animationPlaye = this._animationPlayer) == null || _this$_animationPlaye.onFrameEventCallback(param, this);
  75. }
  76. /** 当前状态名 */
  77. get curStateName() {
  78. return this._ac.curState.name;
  79. }
  80. /** 当前动画名 */
  81. get curStateMotion() {
  82. return this._ac.curState.motion;
  83. }
  84. /** 获取指定状态 */
  85. getState(name) {
  86. return this._ac.states.get(name);
  87. }
  88. /**
  89. * 手动初始化状态机,可传入0-3个参数,类型如下
  90. * - onStateChangeCall 状态切换时的回调
  91. * - stateLogicMap 各个状态逻辑控制
  92. * - animationPlayer 自定义动画控制
  93. * @virtual
  94. */
  95. onInit() {}
  96. /**
  97. * 处理初始化参数
  98. */
  99. initArgs() {
  100. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  101. args[_key] = arguments[_key];
  102. }
  103. args.forEach(arg => {
  104. if (!arg) {
  105. return;
  106. }
  107. if (typeof arg === 'function') {
  108. this._onStateChangeCall = arg;
  109. } else if (typeof arg === 'object') {
  110. if (arg instanceof Map) {
  111. this._stateLogicMap = arg;
  112. } else {
  113. this._animationPlayer = arg;
  114. }
  115. }
  116. });
  117. }
  118. updateAnimator() {
  119. // 混合当前动画播放速度
  120. var playSpeed = this._ac.curState.speed;
  121. if (this._ac.curState.multi) {
  122. var _this$_ac$params$getN;
  123. playSpeed *= (_this$_ac$params$getN = this._ac.params.getNumber(this._ac.curState.multi)) != null ? _this$_ac$params$getN : 1;
  124. }
  125. this.scaleTime(playSpeed); // 更新动画状态逻辑
  126. if (this._stateLogicMap) {
  127. var curLogic = this._stateLogicMap.get(this._ac.curState.name);
  128. curLogic && curLogic.onUpdate();
  129. } // 更新状态机逻辑
  130. this._ac.updateAnimator();
  131. }
  132. update() {
  133. if (this._hasInit && this.AutoUpdate) {
  134. this.updateAnimator();
  135. }
  136. }
  137. /**
  138. * 手动调用更新
  139. */
  140. manualUpdate() {
  141. if (this._hasInit && !this.AutoUpdate) {
  142. this.updateAnimator();
  143. }
  144. }
  145. /**
  146. * 解析状态机json文件
  147. */
  148. initJson(json) {
  149. this._ac = new (_crd && AnimatorController === void 0 ? (_reportPossibleCrUseOfAnimatorController({
  150. error: Error()
  151. }), AnimatorController) : AnimatorController)(this, json);
  152. }
  153. /**
  154. * 动画结束的回调
  155. */
  156. onAnimFinished() {
  157. var _this$_animationPlaye2;
  158. this._ac.onAnimationComplete();
  159. (_this$_animationPlaye2 = this._animationPlayer) == null || _this$_animationPlaye2.onFinishedCallback(this);
  160. }
  161. /**
  162. * 播放动画
  163. * @virtual
  164. * @param animName 动画名
  165. * @param loop 是否循环播放
  166. */
  167. playAnimation(animName, loop) {}
  168. /**
  169. * 缩放动画播放速率
  170. * @virtual
  171. * @param scale 缩放倍率
  172. */
  173. scaleTime(scale) {}
  174. /**
  175. * 状态切换时的逻辑(状态机内部方法,不能由外部直接调用)
  176. */
  177. onStateChange(fromState, toState) {
  178. this.playAnimation(toState.motion, toState.loop);
  179. var fromStateName = fromState ? fromState.name : '';
  180. if (this._stateLogicMap) {
  181. var fromLogic = this._stateLogicMap.get(fromStateName);
  182. fromLogic && fromLogic.onExit();
  183. var toLogic = this._stateLogicMap.get(toState.name);
  184. toLogic && toLogic.onEntry();
  185. }
  186. this._onStateChangeCall && this._onStateChangeCall(fromStateName, toState.name);
  187. }
  188. /**
  189. * 设置boolean类型参数的值
  190. */
  191. setBool(key, value) {
  192. this._ac.params.setBool(key, value);
  193. }
  194. /**
  195. * 获取boolean类型参数的值
  196. */
  197. getBool(key) {
  198. return this._ac.params.getBool(key) !== 0;
  199. }
  200. /**
  201. * 设置number类型参数的值
  202. */
  203. setNumber(key, value) {
  204. this._ac.params.setNumber(key, value);
  205. }
  206. /**
  207. * 获取number类型参数的值
  208. */
  209. getNumber(key) {
  210. return this._ac.params.getNumber(key);
  211. }
  212. /**
  213. * 设置trigger类型参数的值
  214. */
  215. setTrigger(key) {
  216. this._ac.params.setTrigger(key);
  217. }
  218. /**
  219. * 重置trigger类型参数的值
  220. */
  221. resetTrigger(key) {
  222. this._ac.params.resetTrigger(key);
  223. }
  224. /**
  225. * 设置autoTrigger类型参数的值(autoTrigger类型参数不需要主动reset,每次状态机更新结束后会自动reset)
  226. */
  227. autoTrigger(key) {
  228. this._ac.params.autoTrigger(key);
  229. }
  230. /**
  231. * 无视条件直接跳转状态
  232. * @param 状态名
  233. */
  234. play(stateName) {
  235. if (!this._hasInit) {
  236. return;
  237. }
  238. this._ac.play(stateName);
  239. }
  240. }, (_descriptor = _applyDecoratedDescriptor(_class2.prototype, "AssetRawUrl", [_dec3], {
  241. configurable: true,
  242. enumerable: true,
  243. writable: true,
  244. initializer: function initializer() {
  245. return null;
  246. }
  247. }), _descriptor2 = _applyDecoratedDescriptor(_class2.prototype, "PlayOnStart", [_dec4], {
  248. configurable: true,
  249. enumerable: true,
  250. writable: true,
  251. initializer: function initializer() {
  252. return true;
  253. }
  254. }), _descriptor3 = _applyDecoratedDescriptor(_class2.prototype, "AutoUpdate", [_dec5], {
  255. configurable: true,
  256. enumerable: true,
  257. writable: true,
  258. initializer: function initializer() {
  259. return true;
  260. }
  261. })), _class2)) || _class) || _class) || _class));
  262. _cclegacy._RF.pop();
  263. _crd = false;
  264. }
  265. };
  266. });
  267. //# sourceMappingURL=8a9034108f6f9a1a4af078b3eac080d89de67710.js.map