mirror of
https://github.com/galacean/engine.git
synced 2026-06-20 20:06:02 +08:00
Support particle start delay time (#2431)
* feat: support particle start delay time
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user