puppet.ts 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. import { Vec3, Node, MeshRenderer, Color, RenderableComponent, Material, CapsuleCollider } from "cc";
  2. import { ViewUtil } from "../../../../extensions/oops-plugin-framework/assets/core/utils/ViewUtil";
  3. import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
  4. import { PuppetModelComp } from "./model/PuppetModelComp";
  5. import { PuppetViewComp } from "./view/PuppetViewComp";
  6. import { PathFindComp } from "../common/ecs/path/PathFind";
  7. import { PuppetPathSystem } from "./bll/PuppetPath";
  8. import { PuppetSKinEnum } from "./model/PuppetEnum";
  9. /**
  10. * 人物实体
  11. */
  12. @ecs.register('Puppet')
  13. export class Puppet extends ecs.Entity {
  14. PuppetModel!: PuppetModelComp;
  15. PathFind!: PathFindComp;
  16. PuppetView!: PuppetViewComp;
  17. protected init() {
  18. // 添加关卡数据组件
  19. this.addComponents<ecs.Comp>(PuppetModelComp);
  20. }
  21. destroy(): void {
  22. // 如果该组件对象是由ecs系统外部创建的,则不可回收,需要用户自己手动进行回收。
  23. this.remove(PuppetViewComp);
  24. super.destroy();
  25. }
  26. /** 加载关卡显示对象(cc.Component在创建后,添加到ECS框架中,使实体上任何一个ECS组件都可以通过 ECS API 获取到视图层对象 */
  27. load(parent: Node, color: string, pos: Vec3 = Vec3.ZERO, skinId: number = 1) {
  28. const node = ViewUtil.createPrefabNode(this.getSkinModelPath(skinId))
  29. var mv = node.getComponent(PuppetViewComp)!;
  30. if (!this.PuppetModel.withColider) node.getComponent(CapsuleCollider)?.destroy()
  31. this.add(mv);
  32. this.PuppetView.changeColor(color)
  33. node.parent = parent;
  34. node.setPosition(pos);
  35. }
  36. // loadWithOutColider(parent: Node, color: string, pos: Vec3 = Vec3.ZERO, skinId: number = 1){
  37. // const node = ViewUtil.createPrefabNode(this.getSkinModelPath(skinId))
  38. // var mv = node.getComponent(PuppetViewComp)!;
  39. // node.getComponent(CapsuleCollider)?.destroy()
  40. // this.add(mv);
  41. // this.PuppetView.changeColor(color)
  42. // node.parent = parent;
  43. // node.setPosition(pos);
  44. // }
  45. changeSkin(skinId: number) {
  46. const { position, parent } = this.PuppetView.node
  47. const { curState } = this.PuppetView.animator
  48. this.remove(PuppetViewComp)
  49. this.load(parent, this.PuppetModel.color, position, skinId)
  50. this.PuppetView?.animator.playAni(curState)
  51. }
  52. getSkinModelPath(skinId: number) {
  53. if (skinId === PuppetSKinEnum.Balloon) {
  54. return "game/prefab/man_balloon";
  55. } else if (skinId === PuppetSKinEnum.Hat) {
  56. return "game/prefab/man_hat";
  57. } else if (skinId === PuppetSKinEnum.Cane) {
  58. return "game/prefab/man_cane";
  59. }
  60. return "game/prefab/man";
  61. }
  62. }
  63. export class EcsPuppetSystem extends ecs.System {
  64. constructor() {
  65. super();
  66. // this.add(new PuppetPathSystem())
  67. }
  68. }