4786bbfdf50a42aea50cc153020c274342f10c1d.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  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(...args) {
  54. super(...args);
  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(...args) {}
  96. /**
  97. * 处理初始化参数
  98. */
  99. initArgs(...args) {
  100. args.forEach(arg => {
  101. if (!arg) {
  102. return;
  103. }
  104. if (typeof arg === 'function') {
  105. this._onStateChangeCall = arg;
  106. } else if (typeof arg === 'object') {
  107. if (arg instanceof Map) {
  108. this._stateLogicMap = arg;
  109. } else {
  110. this._animationPlayer = arg;
  111. }
  112. }
  113. });
  114. }
  115. updateAnimator() {
  116. // 混合当前动画播放速度
  117. let playSpeed = this._ac.curState.speed;
  118. if (this._ac.curState.multi) {
  119. var _this$_ac$params$getN;
  120. playSpeed *= (_this$_ac$params$getN = this._ac.params.getNumber(this._ac.curState.multi)) != null ? _this$_ac$params$getN : 1;
  121. }
  122. this.scaleTime(playSpeed); // 更新动画状态逻辑
  123. if (this._stateLogicMap) {
  124. let curLogic = this._stateLogicMap.get(this._ac.curState.name);
  125. curLogic && curLogic.onUpdate();
  126. } // 更新状态机逻辑
  127. this._ac.updateAnimator();
  128. }
  129. update() {
  130. if (this._hasInit && this.AutoUpdate) {
  131. this.updateAnimator();
  132. }
  133. }
  134. /**
  135. * 手动调用更新
  136. */
  137. manualUpdate() {
  138. if (this._hasInit && !this.AutoUpdate) {
  139. this.updateAnimator();
  140. }
  141. }
  142. /**
  143. * 解析状态机json文件
  144. */
  145. initJson(json) {
  146. this._ac = new (_crd && AnimatorController === void 0 ? (_reportPossibleCrUseOfAnimatorController({
  147. error: Error()
  148. }), AnimatorController) : AnimatorController)(this, json);
  149. }
  150. /**
  151. * 动画结束的回调
  152. */
  153. onAnimFinished() {
  154. var _this$_animationPlaye2;
  155. this._ac.onAnimationComplete();
  156. (_this$_animationPlaye2 = this._animationPlayer) == null || _this$_animationPlaye2.onFinishedCallback(this);
  157. }
  158. /**
  159. * 播放动画
  160. * @virtual
  161. * @param animName 动画名
  162. * @param loop 是否循环播放
  163. */
  164. playAnimation(animName, loop) {}
  165. /**
  166. * 缩放动画播放速率
  167. * @virtual
  168. * @param scale 缩放倍率
  169. */
  170. scaleTime(scale) {}
  171. /**
  172. * 状态切换时的逻辑(状态机内部方法,不能由外部直接调用)
  173. */
  174. onStateChange(fromState, toState) {
  175. this.playAnimation(toState.motion, toState.loop);
  176. let fromStateName = fromState ? fromState.name : '';
  177. if (this._stateLogicMap) {
  178. let fromLogic = this._stateLogicMap.get(fromStateName);
  179. fromLogic && fromLogic.onExit();
  180. let toLogic = this._stateLogicMap.get(toState.name);
  181. toLogic && toLogic.onEntry();
  182. }
  183. this._onStateChangeCall && this._onStateChangeCall(fromStateName, toState.name);
  184. }
  185. /**
  186. * 设置boolean类型参数的值
  187. */
  188. setBool(key, value) {
  189. this._ac.params.setBool(key, value);
  190. }
  191. /**
  192. * 获取boolean类型参数的值
  193. */
  194. getBool(key) {
  195. return this._ac.params.getBool(key) !== 0;
  196. }
  197. /**
  198. * 设置number类型参数的值
  199. */
  200. setNumber(key, value) {
  201. this._ac.params.setNumber(key, value);
  202. }
  203. /**
  204. * 获取number类型参数的值
  205. */
  206. getNumber(key) {
  207. return this._ac.params.getNumber(key);
  208. }
  209. /**
  210. * 设置trigger类型参数的值
  211. */
  212. setTrigger(key) {
  213. this._ac.params.setTrigger(key);
  214. }
  215. /**
  216. * 重置trigger类型参数的值
  217. */
  218. resetTrigger(key) {
  219. this._ac.params.resetTrigger(key);
  220. }
  221. /**
  222. * 设置autoTrigger类型参数的值(autoTrigger类型参数不需要主动reset,每次状态机更新结束后会自动reset)
  223. */
  224. autoTrigger(key) {
  225. this._ac.params.autoTrigger(key);
  226. }
  227. /**
  228. * 无视条件直接跳转状态
  229. * @param 状态名
  230. */
  231. play(stateName) {
  232. if (!this._hasInit) {
  233. return;
  234. }
  235. this._ac.play(stateName);
  236. }
  237. }, (_descriptor = _applyDecoratedDescriptor(_class2.prototype, "AssetRawUrl", [_dec3], {
  238. configurable: true,
  239. enumerable: true,
  240. writable: true,
  241. initializer: function () {
  242. return null;
  243. }
  244. }), _descriptor2 = _applyDecoratedDescriptor(_class2.prototype, "PlayOnStart", [_dec4], {
  245. configurable: true,
  246. enumerable: true,
  247. writable: true,
  248. initializer: function () {
  249. return true;
  250. }
  251. }), _descriptor3 = _applyDecoratedDescriptor(_class2.prototype, "AutoUpdate", [_dec5], {
  252. configurable: true,
  253. enumerable: true,
  254. writable: true,
  255. initializer: function () {
  256. return true;
  257. }
  258. })), _class2)) || _class) || _class) || _class));
  259. _cclegacy._RF.pop();
  260. _crd = false;
  261. }
  262. };
  263. });
  264. //# sourceMappingURL=4786bbfdf50a42aea50cc153020c274342f10c1d.js.map