Support particle start delay time (#2431)

* feat: support particle start delay time
This commit is contained in:
ChenMo
2024-11-11 21:36:16 +08:00
committed by GitHub
parent 9b39b66986
commit a1599259a9
2 changed files with 20 additions and 1 deletions

View File

@@ -121,6 +121,8 @@ export class ParticleGenerator {
private _firstActiveTransformedBoundingBox = 0;
@ignoreClone
private _firstFreeTransformedBoundingBox = 0;
@ignoreClone
private _playStartDelay = 0;
/**
* Whether the particle generator is contain alive or is still creating particles.
@@ -187,6 +189,8 @@ export class ParticleGenerator {
if (this.useAutoRandomSeed) {
this._resetGlobalRandSeed(Math.floor(Math.random() * 0xffffffff)); // 2^32 - 1
}
this._playStartDelay = this.main.startDelay.evaluate(undefined, this.main._startDelayRand.random());
}
}
@@ -266,8 +270,20 @@ export class ParticleGenerator {
const { main, emission } = this;
const duration = main.duration;
const lastPlayTime = this._playTime;
const deltaTime = elapsedTime * main.simulationSpeed;
this._playTime += elapsedTime * main.simulationSpeed;
// Process start delay time
if (this._playStartDelay > 0) {
const remainingDelay = (this._playStartDelay -= deltaTime);
if (remainingDelay < 0) {
this._playTime -= remainingDelay;
this._playStartDelay = 0;
} else {
return;
}
}
this._playTime += deltaTime;
this._retireActiveParticles();
this._freeRetiredParticles();

View File

@@ -63,6 +63,9 @@ export class MainModule implements ICustomClone {
_maxParticleBuffer = 1000;
/** @internal */
@ignoreClone
readonly _startDelayRand = new Rand(0, ParticleRandomSubSeeds.StartDelay);
/** @internal */
@ignoreClone
readonly _startSpeedRand = new Rand(0, ParticleRandomSubSeeds.StartSpeed);
/** @internal */
@ignoreClone