使用ecs系统进行重构
This commit is contained in:
50
assets/script/game/heros/HeroComponent.ts
Normal file
50
assets/script/game/heros/HeroComponent.ts
Normal file
@@ -0,0 +1,50 @@
|
||||
import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
|
||||
|
||||
import { _decorator, Node } from 'cc';
|
||||
const { ccclass } = _decorator;
|
||||
|
||||
// 继承框架的ECComponent
|
||||
|
||||
// 基础属性组件
|
||||
@ecs.register('HeroBase')
|
||||
export class HeroBase extends ecs.Comp {
|
||||
// 定义需要序列化的字段
|
||||
static serializeFields = ['hp', 'attack', 'node'];
|
||||
|
||||
hp: number = 100;
|
||||
attack: number = 10;
|
||||
node: Node = null;
|
||||
|
||||
reset() {
|
||||
this.hp = 100;
|
||||
this.attack = 10;
|
||||
this.node = null;
|
||||
}
|
||||
}
|
||||
|
||||
// 技能组件
|
||||
@ecs.register('HeroSkill')
|
||||
export class HeroSkill extends ecs.Comp {
|
||||
static serializeFields = ['skillId'];
|
||||
|
||||
skillId: string = "";
|
||||
cooldown: number = 0;
|
||||
|
||||
reset() {
|
||||
this.skillId = "";
|
||||
this.cooldown = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// 状态组件
|
||||
@ecs.register('HeroState')
|
||||
export class HeroState extends ecs.Comp {
|
||||
current: 'idle' | 'attack' | 'die' = 'idle';
|
||||
previous: 'idle' | 'attack' | 'die' = 'idle';
|
||||
|
||||
reset() {
|
||||
this.current = 'idle';
|
||||
this.previous = 'idle';
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user