长音符再修复 加入了关卡连接 优化了一些默认加载
This commit is contained in:
@@ -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));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user