长音符再修复 加入了关卡连接 优化了一些默认加载

This commit is contained in:
FloatGaming
2026-01-13 11:22:39 +08:00
parent 2738089af1
commit 2f9d4aae0c
426 changed files with 299413 additions and 1050 deletions
@@ -451,4 +451,77 @@ public class AnimationController : MonoBehaviour
}
}
/// <summary>
/// Public API to prewarm particle instances. Call during loading/pause time to avoid hitch on first use.
/// This will instantiate the configured scene particle sources (hit_particular_object / hit_ring_object)
/// and briefly play their ParticleSystems to force any internal setup.
/// </summary>
public void PrewarmParticles(int perTemplate = 2)
{
// start coroutine to avoid blocking main thread with many instantiations
StartCoroutine(PrewarmCoroutine(perTemplate));
}
private IEnumerator PrewarmCoroutine(int perTemplate)
{
// List of templates to warm
var templates = new List<GameObject>();
if (hit_particular_object != null) templates.Add(hit_particular_object);
if (hit_ring_object != null) templates.Add(hit_ring_object);
for (int i = 0; i < templates.Count; i++)
{
var prefab = templates[i];
for (int j = 0; j < perTemplate; j++)
{
GameObject inst = null;
try
{
inst = Instantiate(prefab, this.transform);
inst.SetActive(true);
var systems = inst.GetComponentsInChildren<ParticleSystem>(true);
if (systems != null)
{
foreach (var ps in systems)
{
try { ps.Play(); } catch { }
}
}
}
catch { }
// wait a frame to allow any internal initialization to run
yield return null;
// stop and destroy the instance to free memory - the warmup work is done
if (inst != null)
{
var systems = inst.GetComponentsInChildren<ParticleSystem>(true);
if (systems != null)
{
foreach (var ps in systems)
{
try { ps.Stop(true, ParticleSystemStopBehavior.StopEmittingAndClear); } catch { }
}
}
Destroy(inst);
}
// small yield to spread work across frames
yield return null;
}
}
yield break;
}
/// <summary>
/// Public routine variant that callers can yield on to wait until prewarm completes.
/// Use this when you need to ensure particle templates are fully instantiated and torn down
/// before proceeding (to avoid hiccups at first real use).
/// </summary>
public IEnumerator PrewarmParticlesRoutine(int perTemplate = 2)
{
yield return StartCoroutine(PrewarmCoroutine(perTemplate));
}
}