修复短音符延迟
This commit is contained in:
@@ -42,8 +42,12 @@ public class Animation_GenerateJudgementSituationPrefab : MonoBehaviour
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
if (Instance == null) Instance = this;
|
||||
else
|
||||
if (Instance == null)
|
||||
{
|
||||
Instance = this;
|
||||
DontDestroyOnLoad(gameObject);
|
||||
}
|
||||
else if (Instance != this)
|
||||
{
|
||||
Destroy(gameObject);
|
||||
return;
|
||||
@@ -52,10 +56,27 @@ public class Animation_GenerateJudgementSituationPrefab : MonoBehaviour
|
||||
CacheSpawnPoints();
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
// Ensure spawn points are cached after all scene objects are initialized
|
||||
if (redSpawn == null && redEffect != null)
|
||||
{
|
||||
CacheSpawnPoints();
|
||||
}
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
// In case this object survives scene changes / references are assigned late.
|
||||
if (redSpawn == null && redEffect != null) CacheSpawnPoints();
|
||||
if (Instance == null)
|
||||
{
|
||||
Instance = this;
|
||||
}
|
||||
|
||||
if (redSpawn == null && redEffect != null)
|
||||
{
|
||||
CacheSpawnPoints();
|
||||
}
|
||||
}
|
||||
|
||||
private void CacheSpawnPoints()
|
||||
@@ -66,15 +87,42 @@ public class Animation_GenerateJudgementSituationPrefab : MonoBehaviour
|
||||
yellowSpawn = yellowEffect != null ? yellowEffect.transform : null;
|
||||
purpleSpawn = purpleEffect != null ? purpleEffect.transform : null;
|
||||
blueSpawn = blueEffect != null ? blueEffect.transform : null;
|
||||
|
||||
if (GameConfig.verboseLogs)
|
||||
{
|
||||
Debug.Log($"[Animation_Generate] Cached spawn points: red={redSpawn!=null}, green={greenSpawn!=null}, yellow={yellowSpawn!=null}, purple={purpleSpawn!=null}, blue={blueSpawn!=null}");
|
||||
}
|
||||
}
|
||||
|
||||
public void SpawnJudgePrefab(string color, string judgeResult)
|
||||
{
|
||||
if (string.IsNullOrEmpty(color))
|
||||
{
|
||||
Debug.LogError("[Animation_Generate] SpawnJudgePrefab called with empty color!");
|
||||
return;
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(judgeResult))
|
||||
{
|
||||
Debug.LogError("[Animation_Generate] SpawnJudgePrefab called with empty judgeResult!");
|
||||
return;
|
||||
}
|
||||
|
||||
Transform spawnPoint = GetSpawnPoint(color);
|
||||
if (spawnPoint == null) return;
|
||||
if (spawnPoint == null)
|
||||
{
|
||||
Debug.LogError($"[Animation_Generate] Could not find spawn point for color: {color}");
|
||||
return;
|
||||
}
|
||||
|
||||
GameObject prefabToUse = GetJudgePrefab(judgeResult);
|
||||
if (prefabToUse == null) return;
|
||||
if (prefabToUse == null)
|
||||
{
|
||||
Debug.LogError($"[Animation_Generate] Could not find judge prefab for result: {judgeResult}. Available: perfect={perfect_judge_prefab != null}, great={great_judge_prefab != null}, good={good_judge_prefab != null}, miss={miss_judge_prefab != null}");
|
||||
return;
|
||||
}
|
||||
|
||||
if (GameConfig.verboseLogs) Debug.Log($"[Animation_Generate] Spawning judge prefab: color={color}, result={judgeResult}, prefab={prefabToUse.name}");
|
||||
|
||||
GameObject instance = Instantiate(prefabToUse, spawnPoint);
|
||||
instance.transform.localPosition = Vector3.zero;
|
||||
@@ -159,7 +207,7 @@ public class Animation_GenerateJudgementSituationPrefab : MonoBehaviour
|
||||
sr.color = c;
|
||||
}
|
||||
|
||||
// 等待渲染完成,防止闪除
|
||||
// 等待渲染完成,防止闪删
|
||||
yield return new WaitForEndOfFrame();
|
||||
|
||||
if (obj != null) Destroy(obj);
|
||||
@@ -172,30 +220,52 @@ public class Animation_GenerateJudgementSituationPrefab : MonoBehaviour
|
||||
// If references were destroyed (Unity fake null) try to rebuild cache once.
|
||||
if (redSpawn == null && greenSpawn == null && yellowSpawn == null && purpleSpawn == null && blueSpawn == null)
|
||||
{
|
||||
if (GameConfig.verboseLogs) Debug.Log("[Animation_Generate] Rebuilding spawn point cache");
|
||||
CacheSpawnPoints();
|
||||
}
|
||||
|
||||
Transform point = null;
|
||||
switch (color.ToLower())
|
||||
{
|
||||
case "red": return redSpawn;
|
||||
case "green": return greenSpawn;
|
||||
case "yellow": return yellowSpawn;
|
||||
case "purple": return purpleSpawn;
|
||||
case "blue": return blueSpawn;
|
||||
default: return null;
|
||||
case "red": point = redSpawn; break;
|
||||
case "green": point = greenSpawn; break;
|
||||
case "yellow": point = yellowSpawn; break;
|
||||
case "purple": point = purpleSpawn; break;
|
||||
case "blue": point = blueSpawn; break;
|
||||
default:
|
||||
Debug.LogWarning($"[Animation_Generate] Unknown color: {color}");
|
||||
return null;
|
||||
}
|
||||
|
||||
if (point == null)
|
||||
{
|
||||
Debug.LogError($"[Animation_Generate] Spawn point for color {color} is null. Check if effects are assigned in inspector. Make sure the effect object is active in the scene.");
|
||||
}
|
||||
|
||||
return point;
|
||||
}
|
||||
|
||||
private GameObject GetJudgePrefab(string result)
|
||||
{
|
||||
if (string.IsNullOrEmpty(result)) return null;
|
||||
|
||||
GameObject prefab = null;
|
||||
switch (result.ToLower())
|
||||
{
|
||||
case "perfect": return perfect_judge_prefab;
|
||||
case "great": return great_judge_prefab;
|
||||
case "good": return good_judge_prefab;
|
||||
case "miss": return miss_judge_prefab;
|
||||
default: return null;
|
||||
case "perfect": prefab = perfect_judge_prefab; break;
|
||||
case "great": prefab = great_judge_prefab; break;
|
||||
case "good": prefab = good_judge_prefab; break;
|
||||
case "miss": prefab = miss_judge_prefab; break;
|
||||
default:
|
||||
Debug.LogWarning($"[Animation_Generate] Unknown judge result: {result}");
|
||||
return null;
|
||||
}
|
||||
|
||||
if (prefab == null)
|
||||
{
|
||||
Debug.LogError($"[Animation_Generate] Judge prefab for '{result}' is not assigned in inspector! Check Animation_GenerateJudgementSituationPrefab component.");
|
||||
}
|
||||
|
||||
return prefab;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user