备份,准备做双端
This commit is contained in:
@@ -344,9 +344,13 @@ public class Animation_GenerateJudgementSituationPrefab : MonoBehaviour
|
||||
if (obj == null) yield break;
|
||||
if (settings == null) settings = judgePopup;
|
||||
|
||||
SpriteRenderer[] renderers = obj.GetComponentsInChildren<SpriteRenderer>(true);
|
||||
Graphic[] graphics = obj.GetComponentsInChildren<Graphic>(true);
|
||||
CanvasGroup canvasGroup = obj.GetComponent<CanvasGroup>();
|
||||
// Pooled popup instances keep the same child renderer/graphic set for their lifetime,
|
||||
// so cache the (otherwise-allocating) GetComponentsInChildren sweeps on the instance
|
||||
// and reuse them on every replay instead of re-scanning per judgement.
|
||||
PopupRenderableCache cache = GetPopupRenderableCache(obj);
|
||||
SpriteRenderer[] renderers = cache.renderers;
|
||||
Graphic[] graphics = cache.graphics;
|
||||
CanvasGroup canvasGroup = cache.canvasGroup;
|
||||
|
||||
float elapsed = 0f;
|
||||
float vVelocity = settings.jumpForce;
|
||||
@@ -433,6 +437,28 @@ public class Animation_GenerateJudgementSituationPrefab : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
// Caches the child SpriteRenderer/Graphic arrays + CanvasGroup of a pooled popup instance
|
||||
// so AnimatePopup doesn't re-run allocating GetComponentsInChildren on every replay.
|
||||
private sealed class PopupRenderableCache : MonoBehaviour
|
||||
{
|
||||
public SpriteRenderer[] renderers;
|
||||
public Graphic[] graphics;
|
||||
public CanvasGroup canvasGroup;
|
||||
}
|
||||
|
||||
private static PopupRenderableCache GetPopupRenderableCache(GameObject obj)
|
||||
{
|
||||
var cache = obj.GetComponent<PopupRenderableCache>();
|
||||
if (cache == null)
|
||||
{
|
||||
cache = obj.AddComponent<PopupRenderableCache>();
|
||||
cache.renderers = obj.GetComponentsInChildren<SpriteRenderer>(true);
|
||||
cache.graphics = obj.GetComponentsInChildren<Graphic>(true);
|
||||
cache.canvasGroup = obj.GetComponent<CanvasGroup>();
|
||||
}
|
||||
return cache;
|
||||
}
|
||||
|
||||
private static void SetRenderersAlpha(SpriteRenderer[] renderers, float alpha)
|
||||
{
|
||||
if (renderers == null)
|
||||
|
||||
Reference in New Issue
Block a user