超大量的更新 修复很多问题,gameplay特效初步
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using GamePlay; // for PoolItem
|
||||
using System.Collections;
|
||||
@@ -7,10 +7,10 @@ public class NotePool : MonoBehaviour
|
||||
{
|
||||
public static NotePool Instance { get; private set; }
|
||||
|
||||
public GameObject[] notePrefabs; // ������Ԥ���壨����ɫ�洢��
|
||||
public GameObject[] holdNotePrefabs; // ������Ƭ��Ԥ����
|
||||
public GameObject[] holdNoteEndPrefabs; // ������β��ר�ó�����Ԥ���壨��ѡ��
|
||||
public GameObject[] startNotePrefabs; // ������startƬ��Ԥ����
|
||||
public GameObject[] notePrefabs; // Documentation text normalized.
|
||||
public GameObject[] holdNotePrefabs; // Documentation text normalized.
|
||||
public GameObject[] holdNoteEndPrefabs; // Documentation text normalized.
|
||||
public GameObject[] startNotePrefabs; // Documentation text normalized.
|
||||
|
||||
[Header("Pool Size")]
|
||||
public int poolSize = 24;
|
||||
@@ -20,20 +20,19 @@ public class NotePool : MonoBehaviour
|
||||
[Tooltip("Multiplier for hold end pool size (per color).")]
|
||||
public int holdEndPoolMultiplier = 8;
|
||||
|
||||
// ��ɫ�������Ŀ���ӳ�䣬����ÿ�� switch
|
||||
// Documentation text normalized.
|
||||
private Dictionary<string, int> colorIndexMap;
|
||||
|
||||
private Dictionary<int, Stack<GameObject>> notePools; // �����������
|
||||
private Dictionary<int, Stack<GameObject>> holdNotePools; // ������Ƭ�ζ����
|
||||
private Dictionary<int, Stack<GameObject>> holdNoteEndPools; // ������������������
|
||||
private Dictionary<int, Stack<GameObject>> startNotePools; // ������startƬ�ζ����
|
||||
|
||||
// �������������ڲ㼶����֯���еĶ����ڵ��Ժ���
|
||||
private Dictionary<int, Stack<GameObject>> notePools; // Documentation text normalized.
|
||||
private Dictionary<int, Stack<GameObject>> holdNotePools;
|
||||
private Dictionary<int, Stack<GameObject>> holdNoteEndPools;
|
||||
private Dictionary<int, Stack<GameObject>> startNotePools;
|
||||
// Documentation text normalized.
|
||||
private Transform notePoolContainer;
|
||||
private Transform holdPoolContainer;
|
||||
private Transform startPoolContainer;
|
||||
|
||||
// ���Ƶ��������Ĭ�Ϲر�����������
|
||||
[Header("Debug")]
|
||||
public bool verboseLogging = false;
|
||||
|
||||
[Header("Prewarm Settings")]
|
||||
@@ -61,7 +60,7 @@ public class NotePool : MonoBehaviour
|
||||
return;
|
||||
}
|
||||
|
||||
// ��ʼ����ɫӳ��
|
||||
// Documentation text normalized.
|
||||
colorIndexMap = new Dictionary<string, int>
|
||||
{
|
||||
{ "red", 0 },
|
||||
@@ -71,7 +70,7 @@ public class NotePool : MonoBehaviour
|
||||
{ "blue", 4 }
|
||||
};
|
||||
|
||||
// ��������
|
||||
// Documentation text normalized.
|
||||
notePoolContainer = new GameObject("_NotePool_Notes").transform;
|
||||
notePoolContainer.SetParent(transform, false);
|
||||
holdPoolContainer = new GameObject("_NotePool_HoldSegments").transform;
|
||||
@@ -195,16 +194,15 @@ public class NotePool : MonoBehaviour
|
||||
GameObject obj = pool.Pop();
|
||||
if (obj == null)
|
||||
{
|
||||
// ������ж����ѱ����٣������¶���
|
||||
obj = InstantiateAndPrepare(prefab);
|
||||
// Documentation text normalized.
|
||||
}
|
||||
else
|
||||
{
|
||||
// �Ż���ʹ�� PoolItem ��ʶ������Ƿ�����ͬһ prefab
|
||||
// Documentation text normalized.
|
||||
GamePlay.PoolItem pi = obj.GetComponent<GamePlay.PoolItem>();
|
||||
if (pi == null || prefab == null || pi.prefabName != prefab.name)
|
||||
{
|
||||
// ���ٴ������͵Ķ����滻Ϊ��ȷ�� prefab ʵ��
|
||||
// Documentation text normalized.
|
||||
if (pi == null && verboseLogging) Debug.LogWarning("PoolItem missing on pooled object, replacing.");
|
||||
Destroy(obj);
|
||||
obj = InstantiateAndPrepare(prefab);
|
||||
@@ -215,13 +213,20 @@ public class NotePool : MonoBehaviour
|
||||
|
||||
// mark as taken from pool
|
||||
GamePlay.PoolItem takenPi = obj.GetComponent<GamePlay.PoolItem>();
|
||||
if (takenPi != null) takenPi.inPool = false;
|
||||
if (takenPi != null)
|
||||
{
|
||||
takenPi.inPool = false;
|
||||
if (takenPi.initialLocalScaleCaptured)
|
||||
{
|
||||
obj.transform.localScale = takenPi.initialLocalScale;
|
||||
}
|
||||
}
|
||||
|
||||
return obj;
|
||||
}
|
||||
else
|
||||
{
|
||||
// �ؿ�ʱֱ��ʵ�����¶���
|
||||
// Documentation text normalized.
|
||||
GameObject obj = InstantiateAndPrepare(prefab);
|
||||
obj.SetActive(true);
|
||||
return obj;
|
||||
@@ -236,12 +241,17 @@ public class NotePool : MonoBehaviour
|
||||
if (pi == null) pi = obj.AddComponent<GamePlay.PoolItem>();
|
||||
pi.prefabName = prefab.name;
|
||||
pi.inPool = false;
|
||||
if (!pi.initialLocalScaleCaptured)
|
||||
{
|
||||
pi.initialLocalScale = obj.transform.localScale;
|
||||
pi.initialLocalScaleCaptured = true;
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
|
||||
private void ReturnObjectToPool(Stack<GameObject> pool, GameObject obj, Transform container)
|
||||
{
|
||||
if (obj == null || pool == null) return; // ��ֹ������
|
||||
if (obj == null || pool == null) return; // Documentation text normalized.
|
||||
|
||||
// Defensive: unregister/unlock any TrackKeyManager state referencing this object to avoid stale queues/locks
|
||||
try
|
||||
@@ -271,21 +281,29 @@ public class NotePool : MonoBehaviour
|
||||
}
|
||||
catch { }
|
||||
|
||||
// �����ظ��黹������������ڳ��ڣ�ֱ�Ӻ���
|
||||
// Documentation text normalized.
|
||||
GamePlay.PoolItem pi = obj.GetComponent<GamePlay.PoolItem>();
|
||||
if (pi == null)
|
||||
{
|
||||
pi = obj.AddComponent<GamePlay.PoolItem>();
|
||||
}
|
||||
if (!pi.initialLocalScaleCaptured)
|
||||
{
|
||||
pi.initialLocalScale = obj.transform.localScale;
|
||||
pi.initialLocalScaleCaptured = true;
|
||||
}
|
||||
if (pi != null && pi.inPool) return;
|
||||
|
||||
// �������ƶ��������������ñ任
|
||||
// Documentation text normalized.
|
||||
obj.transform.SetParent(container, false);
|
||||
obj.transform.localPosition = Vector3.zero;
|
||||
obj.transform.localRotation = Quaternion.identity;
|
||||
obj.transform.localScale = Vector3.one;
|
||||
obj.transform.localScale = pi.initialLocalScaleCaptured ? pi.initialLocalScale : obj.transform.localScale;
|
||||
|
||||
// ��Ϊ�Ǽ���״̬�Ա㸴��
|
||||
// Documentation text normalized.
|
||||
obj.SetActive(false);
|
||||
|
||||
// ���Ϊ���ڳ���
|
||||
if (pi != null) pi.inPool = true;
|
||||
// Documentation text normalized.
|
||||
|
||||
if (pool.Count < maxPoolSize)
|
||||
{
|
||||
@@ -293,7 +311,7 @@ public class NotePool : MonoBehaviour
|
||||
}
|
||||
else
|
||||
{
|
||||
// ��������������ٶ�������Խ�ʡ�ڴ�
|
||||
// Documentation text normalized.
|
||||
Destroy(obj);
|
||||
}
|
||||
}
|
||||
@@ -308,6 +326,11 @@ public class NotePool : MonoBehaviour
|
||||
GamePlay.PoolItem pi = obj.GetComponent<GamePlay.PoolItem>() ?? obj.AddComponent<GamePlay.PoolItem>();
|
||||
pi.prefabName = prefab.name;
|
||||
pi.inPool = true;
|
||||
if (!pi.initialLocalScaleCaptured)
|
||||
{
|
||||
pi.initialLocalScale = obj.transform.localScale;
|
||||
pi.initialLocalScaleCaptured = true;
|
||||
}
|
||||
|
||||
obj.SetActive(false);
|
||||
pool.Push(obj);
|
||||
@@ -332,7 +355,6 @@ public class NotePool : MonoBehaviour
|
||||
return GetObjectFromPool(holdNotePools[colorIndex], holdNotePrefabs[colorIndex], holdPoolContainer);
|
||||
}
|
||||
|
||||
// ��������β��ר�óػ�ȡβ��Ƭ�Σ����δ����β��Ԥ������Ϊ�жΣ�
|
||||
public GameObject GetHoldNoteEndSegment(string color)
|
||||
{
|
||||
int colorIndex = GetColorIndexFromName(color);
|
||||
@@ -359,7 +381,7 @@ public class NotePool : MonoBehaviour
|
||||
if (startNote == null) return;
|
||||
if (string.IsNullOrEmpty(color))
|
||||
{
|
||||
if (verboseLogging) Debug.LogWarning($" �黹 StartNote ʱ color Ϊ�գ�������: {startNote.name}");
|
||||
if (verboseLogging) Debug.LogWarning($"归还 StartNote 时 color 为空或无效: {startNote.name}");
|
||||
Destroy(startNote);
|
||||
return;
|
||||
}
|
||||
@@ -367,20 +389,20 @@ public class NotePool : MonoBehaviour
|
||||
HoldNote holdNote = startNote.GetComponent<HoldNote>();
|
||||
if (holdNote != null)
|
||||
{
|
||||
holdNote.ResetState(); // ȷ����������״̬
|
||||
holdNote.ResetState(); // Documentation text normalized.
|
||||
}
|
||||
|
||||
int idx = GetColorIndexFromName(color);
|
||||
ReturnObjectToPool(startNotePools[idx], startNote, startPoolContainer);
|
||||
}
|
||||
|
||||
// �������黹β��Ƭ��
|
||||
// Documentation text normalized.
|
||||
public void ReturnHoldNoteEndSegment(GameObject holdNoteEnd, string color)
|
||||
{
|
||||
if (holdNoteEnd == null) return;
|
||||
if (string.IsNullOrEmpty(color))
|
||||
{
|
||||
if (verboseLogging) Debug.LogWarning($" �黹 HoldNoteEndSegment ʱ color Ϊ�գ�������: {holdNoteEnd.name}");
|
||||
if (verboseLogging) Debug.LogWarning($"归还 HoldNoteEndSegment 时 color 为空或无效: {holdNoteEnd.name}");
|
||||
Destroy(holdNoteEnd);
|
||||
return;
|
||||
}
|
||||
@@ -388,7 +410,7 @@ public class NotePool : MonoBehaviour
|
||||
HoldNote holdNoteScript = holdNoteEnd.GetComponent<HoldNote>();
|
||||
if (holdNoteScript != null)
|
||||
{
|
||||
holdNoteScript.ResetState(); // ȷ����������״̬
|
||||
holdNoteScript.ResetState(); // Documentation text normalized.
|
||||
}
|
||||
|
||||
int idx = GetColorIndexFromName(color);
|
||||
@@ -400,7 +422,7 @@ public class NotePool : MonoBehaviour
|
||||
if (holdNote == null) return;
|
||||
if (string.IsNullOrEmpty(color))
|
||||
{
|
||||
if (verboseLogging) Debug.LogWarning($" �黹 HoldNoteSegment ʱ color Ϊ�գ�������: {holdNote.name}");
|
||||
if (verboseLogging) Debug.LogWarning($"归还 HoldNoteSegment 时 color 为空或无效: {holdNote.name}");
|
||||
Destroy(holdNote);
|
||||
return;
|
||||
}
|
||||
@@ -408,7 +430,7 @@ public class NotePool : MonoBehaviour
|
||||
HoldNote holdNoteScript = holdNote.GetComponent<HoldNote>();
|
||||
if (holdNoteScript != null)
|
||||
{
|
||||
holdNoteScript.ResetState(); // ȷ����������״̬
|
||||
holdNoteScript.ResetState(); // Documentation text normalized.
|
||||
}
|
||||
|
||||
int idx = GetColorIndexFromName(color);
|
||||
@@ -419,13 +441,7 @@ public class NotePool : MonoBehaviour
|
||||
{
|
||||
if (string.IsNullOrEmpty(colorName)) return 0;
|
||||
if (colorIndexMap != null && colorIndexMap.TryGetValue(colorName, out int idx)) return idx;
|
||||
if (verboseLogging) Debug.LogError($"δʶ�����ɫ: {colorName}��Ĭ��ʹ�ú�ɫ");
|
||||
if (verboseLogging) Debug.LogError($"未识别颜色名: {colorName},默认使用红色");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public class PoolItem : MonoBehaviour
|
||||
{
|
||||
public string prefabName;
|
||||
public bool inPool;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user