Add behavior picker component

This commit is contained in:
2022-04-02 19:25:57 +08:00
parent cfbb52afa5
commit 555648dbb0
9 changed files with 234 additions and 31 deletions
+30 -1
View File
@@ -315,8 +315,12 @@ class Group extends CtrlObject {
public addBehavior(behavior: Behavior | Behavior[]): this {
if (Array.isArray(behavior)) {
this.behaviors = this.behaviors.concat(behavior);
for (let i = 0; i < behavior.length; i++) {
behavior[i].mount(this, this.model);
}
} else {
this.behaviors.push(behavior);
behavior.mount(this, this.model);
}
// 按照优先级
@@ -326,6 +330,27 @@ class Group extends CtrlObject {
return this;
}
/**
* 删除行为
* @param behavior 添加行为
*/
public deleteBehavior(behavior: Behavior): this {
let deleteIndex = -1;
for (let i = 0; i < this.behaviors.length; i++) {
if (this.behaviors[i].id === behavior.id) {
deleteIndex = i;
}
}
if (deleteIndex >= 0) {
this.behaviors[deleteIndex].unmount(this, this.model);
this.behaviors.splice(deleteIndex, 1);
}
return this;
}
/**
* 执行行为影响
* @param
@@ -333,7 +358,11 @@ class Group extends CtrlObject {
public runner(t: number, effectType: "finalEffect" | "effect" | "afterEffect" ): void {
this.individuals.forEach((individual) => {
for(let j = 0; j < this.behaviors.length; j++) {
this.behaviors[j][effectType](individual, this, this.model, t);
if (this.behaviors[j].isDeleted()) {
continue;
} else {
this.behaviors[j][effectType](individual, this, this.model, t);
}
}
});
}