mirror of
https://github.com/MartinKral/Slash-The-Hordes
synced 2025-09-24 04:39:05 +00:00
Death effect
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
import { _decorator, Component, Animation, Vec3 } from "cc";
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
@ccclass("EnemyDeathEffect")
|
||||
export class EnemyDeathEffect extends Component {
|
||||
@property(Animation) private animation: Animation;
|
||||
|
||||
public setup(worldPosition: Vec3): void {
|
||||
this.node.setWorldPosition(worldPosition);
|
||||
this.node.active = true;
|
||||
|
||||
this.animation.play("DeathEffect");
|
||||
}
|
||||
}
|
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "213a96b0-ec0c-4951-93e9-e2b498a03f81",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
@@ -0,0 +1,39 @@
|
||||
import { _decorator, Component, Node, Prefab } from "cc";
|
||||
|
||||
import { ObjectPool } from "../../../../Services/ObjectPool";
|
||||
import { delay } from "../../../../Services/Utils/AsyncUtils";
|
||||
import { Enemy } from "../Enemy";
|
||||
import { EnemyManager } from "../EnemyManager";
|
||||
import { EnemyDeathEffect } from "./EnemyDeathEffect";
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
@ccclass("EnemyDeathEffectSpawner")
|
||||
export class EnemyDeathEffectSpawner extends Component {
|
||||
@property(Prefab) private deathEffectPrefab: Prefab;
|
||||
|
||||
private effectPool: ObjectPool<EnemyDeathEffect>;
|
||||
|
||||
public init(enemyManager: EnemyManager): void {
|
||||
enemyManager.EnemyAddedEvent.on(this.onEnemyAdded, this);
|
||||
enemyManager.EnemyRemovedEvent.on(this.onEnemyRemoved, this);
|
||||
|
||||
this.effectPool = new ObjectPool(this.deathEffectPrefab, this.node, 5, "EnemyDeathEffect");
|
||||
}
|
||||
|
||||
private onEnemyAdded(enemy: Enemy): void {
|
||||
enemy.DeathEvent.on(this.animateDeathEffect, this);
|
||||
}
|
||||
|
||||
private onEnemyRemoved(enemy: Enemy): void {
|
||||
enemy.DeathEvent.off(this.animateDeathEffect);
|
||||
}
|
||||
|
||||
private async animateDeathEffect(enemy: Enemy): Promise<void> {
|
||||
const deathEffect = this.effectPool.borrow();
|
||||
deathEffect.setup(enemy.node.worldPosition);
|
||||
|
||||
await delay(360);
|
||||
|
||||
this.effectPool.return(deathEffect);
|
||||
}
|
||||
}
|
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "3d207f4e-7b88-466f-8280-409925d8bbb2",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
Reference in New Issue
Block a user