2修
This commit is contained in:
+49
@@ -26,6 +26,9 @@ public class iNumberPrefabController : MonoBehaviour
|
||||
public GameObject ally04_number_toput;
|
||||
public GameObject ally05_number_toput;
|
||||
|
||||
[Header("Prewarm")]
|
||||
[SerializeField] private int defaultPrewarmPerPrefab = 12;
|
||||
|
||||
private bool _warnedMissingPrefab;
|
||||
private bool _warnedMissingParents;
|
||||
private Transform pooledRoot;
|
||||
@@ -47,6 +50,52 @@ public class iNumberPrefabController : MonoBehaviour
|
||||
{
|
||||
TryAutoBindParentsFromTeamUI();
|
||||
TryAutoBindPrefabFromScene();
|
||||
PrewarmNumberPopups(defaultPrewarmPerPrefab);
|
||||
}
|
||||
|
||||
public static void PrewarmRuntime(int perPrefab)
|
||||
{
|
||||
if (Instance == null) return;
|
||||
Instance.PrewarmNumberPopups(perPrefab);
|
||||
}
|
||||
|
||||
public void PrewarmNumberPopups(int perPrefab)
|
||||
{
|
||||
int count = Mathf.Max(0, perPrefab);
|
||||
if (count <= 0) return;
|
||||
|
||||
PrewarmPrefab(ally_number_prefab, count);
|
||||
PrewarmPrefab(enemy_number_prefab, count);
|
||||
}
|
||||
|
||||
private void PrewarmPrefab(GameObject prefab, int count)
|
||||
{
|
||||
if (prefab == null || pooledRoot == null) return;
|
||||
|
||||
if (!pools.TryGetValue(prefab, out var pool))
|
||||
{
|
||||
pool = new System.Collections.Generic.Stack<playerInstantNumbersPrefab>();
|
||||
pools[prefab] = pool;
|
||||
}
|
||||
|
||||
int missing = Mathf.Max(0, count - pool.Count);
|
||||
for (int i = 0; i < missing; i++)
|
||||
{
|
||||
var go = Instantiate(prefab, pooledRoot, false);
|
||||
if (go == null) continue;
|
||||
|
||||
var view = go.GetComponent<playerInstantNumbersPrefab>();
|
||||
if (view == null)
|
||||
{
|
||||
Destroy(go);
|
||||
continue;
|
||||
}
|
||||
|
||||
sourcePrefabs[view] = prefab;
|
||||
view.ResetForReuse();
|
||||
go.SetActive(false);
|
||||
pool.Push(view);
|
||||
}
|
||||
}
|
||||
|
||||
private void TryAutoBindParentsFromTeamUI()
|
||||
|
||||
Reference in New Issue
Block a user