2修
This commit is contained in:
@@ -10,6 +10,11 @@ public class Animation_GenerateJudgementSituationPrefab : MonoBehaviour
|
||||
public GameObject prefabSource;
|
||||
}
|
||||
|
||||
private sealed class PooledTrackSkillTag : MonoBehaviour
|
||||
{
|
||||
public GameObject prefabSource;
|
||||
}
|
||||
|
||||
public static Animation_GenerateJudgementSituationPrefab Instance;
|
||||
|
||||
[Header("Inspector")]
|
||||
@@ -103,6 +108,8 @@ public class Animation_GenerateJudgementSituationPrefab : MonoBehaviour
|
||||
private Coroutine prewarmJudgeCoroutine;
|
||||
private readonly Dictionary<GameObject, Stack<GameObject>> judgePools = new Dictionary<GameObject, Stack<GameObject>>();
|
||||
private readonly HashSet<GameObject> rentedJudges = new HashSet<GameObject>();
|
||||
private readonly Dictionary<GameObject, Stack<GameObject>> trackSkillPools = new Dictionary<GameObject, Stack<GameObject>>();
|
||||
private readonly HashSet<GameObject> rentedTrackSkills = new HashSet<GameObject>();
|
||||
private float lastTrackSkillSpawnTime = -999f;
|
||||
private int trackSkillBurstCount = 0;
|
||||
|
||||
@@ -226,7 +233,7 @@ public class Animation_GenerateJudgementSituationPrefab : MonoBehaviour
|
||||
if (spawnPoint == null)
|
||||
return;
|
||||
|
||||
GameObject instance = Instantiate(trackSkill_prefab, spawnPoint, false);
|
||||
GameObject instance = GetPooledTrackSkill(trackSkill_prefab, spawnPoint);
|
||||
if (instance == null)
|
||||
return;
|
||||
|
||||
@@ -289,7 +296,8 @@ public class Animation_GenerateJudgementSituationPrefab : MonoBehaviour
|
||||
perfect_judge_prefab,
|
||||
great_judge_prefab,
|
||||
good_judge_prefab,
|
||||
miss_judge_prefab
|
||||
miss_judge_prefab,
|
||||
trackSkill_prefab
|
||||
};
|
||||
|
||||
int count = Mathf.Max(1, perPrefab);
|
||||
@@ -303,12 +311,24 @@ public class Animation_GenerateJudgementSituationPrefab : MonoBehaviour
|
||||
GameObject instance = null;
|
||||
try
|
||||
{
|
||||
instance = CreatePooledJudge(prefab);
|
||||
if (instance != null)
|
||||
if (prefab == trackSkill_prefab)
|
||||
{
|
||||
rentedJudges.Add(instance);
|
||||
instance = CreatePooledTrackSkill(prefab);
|
||||
if (instance != null)
|
||||
{
|
||||
rentedTrackSkills.Add(instance);
|
||||
}
|
||||
ReturnTrackSkillToPool(instance);
|
||||
}
|
||||
else
|
||||
{
|
||||
instance = CreatePooledJudge(prefab);
|
||||
if (instance != null)
|
||||
{
|
||||
rentedJudges.Add(instance);
|
||||
}
|
||||
ReturnJudgeToPool(instance);
|
||||
}
|
||||
ReturnJudgeToPool(instance);
|
||||
}
|
||||
catch { }
|
||||
|
||||
@@ -407,7 +427,7 @@ public class Animation_GenerateJudgementSituationPrefab : MonoBehaviour
|
||||
if (obj != null)
|
||||
{
|
||||
if (destroyAtEnd)
|
||||
Destroy(obj);
|
||||
ReturnTrackSkillToPool(obj);
|
||||
else
|
||||
ReturnJudgeToPool(obj);
|
||||
}
|
||||
@@ -573,6 +593,81 @@ public class Animation_GenerateJudgementSituationPrefab : MonoBehaviour
|
||||
return instance;
|
||||
}
|
||||
|
||||
private GameObject GetPooledTrackSkill(GameObject prefab, Transform parent)
|
||||
{
|
||||
if (prefab == null || parent == null)
|
||||
return null;
|
||||
|
||||
if (!trackSkillPools.TryGetValue(prefab, out var pool))
|
||||
{
|
||||
pool = new Stack<GameObject>();
|
||||
trackSkillPools[prefab] = pool;
|
||||
}
|
||||
|
||||
GameObject instance = null;
|
||||
while (pool.Count > 0 && instance == null)
|
||||
{
|
||||
instance = pool.Pop();
|
||||
}
|
||||
|
||||
if (instance == null)
|
||||
{
|
||||
instance = CreatePooledTrackSkill(prefab);
|
||||
}
|
||||
|
||||
if (instance == null)
|
||||
return null;
|
||||
|
||||
instance.transform.SetParent(parent, false);
|
||||
instance.SetActive(true);
|
||||
rentedTrackSkills.Add(instance);
|
||||
return instance;
|
||||
}
|
||||
|
||||
private GameObject CreatePooledTrackSkill(GameObject prefab)
|
||||
{
|
||||
if (prefab == null)
|
||||
return null;
|
||||
|
||||
GameObject instance = Instantiate(prefab, transform);
|
||||
var tag = instance.GetComponent<PooledTrackSkillTag>();
|
||||
if (tag == null)
|
||||
tag = instance.AddComponent<PooledTrackSkillTag>();
|
||||
tag.prefabSource = prefab;
|
||||
|
||||
EnsureRenderableTrackSkillInstance(instance);
|
||||
instance.SetActive(false);
|
||||
return instance;
|
||||
}
|
||||
|
||||
private void ReturnTrackSkillToPool(GameObject instance)
|
||||
{
|
||||
if (instance == null)
|
||||
return;
|
||||
|
||||
if (!rentedTrackSkills.Remove(instance))
|
||||
return;
|
||||
|
||||
var tag = instance.GetComponent<PooledTrackSkillTag>();
|
||||
if (tag == null || tag.prefabSource == null)
|
||||
{
|
||||
Destroy(instance);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!trackSkillPools.TryGetValue(tag.prefabSource, out var pool))
|
||||
{
|
||||
pool = new Stack<GameObject>();
|
||||
trackSkillPools[tag.prefabSource] = pool;
|
||||
}
|
||||
|
||||
instance.transform.SetParent(transform, false);
|
||||
instance.transform.localPosition = new Vector3(99999f, 99999f, 0f);
|
||||
instance.transform.localRotation = Quaternion.identity;
|
||||
instance.SetActive(false);
|
||||
pool.Push(instance);
|
||||
}
|
||||
|
||||
private void ReturnJudgeToPool(GameObject instance)
|
||||
{
|
||||
if (instance == null)
|
||||
|
||||
Reference in New Issue
Block a user