From 9566f88ba5feee773367293ccd4a3a28792ffe08 Mon Sep 17 00:00:00 2001 From: iwae Date: Thu, 1 Dec 2022 14:43:41 +0800 Subject: [PATCH] Update particle-system.ts (#13615) Even if the rateOverDistance is 0, it will still get the world position and calculate the distance, which is waste. To improve performance, only if the rateOverDistance is above 0, it would get the world position and calculate the distance --- cocos/particle/particle-system.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/cocos/particle/particle-system.ts b/cocos/particle/particle-system.ts index 355e801509..4393f13886 100644 --- a/cocos/particle/particle-system.ts +++ b/cocos/particle/particle-system.ts @@ -1389,10 +1389,13 @@ export class ParticleSystem extends ModelRenderer { } // emit by rateOverDistance - this.node.getWorldPosition(this._curWPos); - const distance = Vec3.distance(this._curWPos, this._oldWPos); - Vec3.copy(this._oldWPos, this._curWPos); - this._emitRateDistanceCounter += distance * this.rateOverDistance.evaluate(this._time / this.duration, 1)!; + const rateOverDistance = this.rateOverDistance.evaluate(this._time / this.duration, 1)!; + if (rateOverDistance > 0) { + Vec3.copy(this._oldWPos, this._curWPos); + this.node.getWorldPosition(this._curWPos); + const distance = Vec3.distance(this._curWPos, this._oldWPos); + this._emitRateDistanceCounter += distance * rateOverDistance; + } if (this._emitRateDistanceCounter > 1) { const emitNum = Math.floor(this._emitRateDistanceCounter);