This commit is contained in:
2026-07-16 20:16:05 +08:00
parent d0902c6ba8
commit efce942e52
21 changed files with 1655 additions and 195 deletions
+13
View File
@@ -128,6 +128,7 @@ public class EffectAutoReturn : MonoBehaviour
private ParticleSystem[] particles;
private float checkTimer;
private const float MinPlayTime = 0.3f; // 至少播 0.3s 再检测,避免第一帧 IsAlive=false 误判
private const float MaxLifetime = 6f; // ⭐ 兜底:超过 6 秒强制回池,防止 looping 残留导致特效永生
/// <summary>重新播放所有粒子</summary>
public void Play()
@@ -140,6 +141,11 @@ public class EffectAutoReturn : MonoBehaviour
{
if (p != null)
{
// ⭐ 强制关闭 looping:有些预制体子级 ParticleSystem 设了 looping=1,
// 会导致 IsAlive(true) 永远返回 true,特效一直累加直至内存爆满死机
var main = p.main;
main.loop = false;
p.Clear(true);
p.Play(true);
}
@@ -151,6 +157,13 @@ public class EffectAutoReturn : MonoBehaviour
checkTimer += Time.deltaTime;
if (checkTimer < MinPlayTime) return;
// ⭐ 6 秒兜底:无论是否还存活,超过 6 秒强制回池
if (checkTimer >= MaxLifetime)
{
EffectPool.Instance.Return(gameObject);
return;
}
// 所有粒子都播完 → 回池
if (particles == null || particles.Length == 0)
{