长音符再修复 加入了关卡连接 优化了一些默认加载

This commit is contained in:
FloatGaming
2026-01-13 11:22:39 +08:00
parent 2738089af1
commit 2f9d4aae0c
426 changed files with 299413 additions and 1050 deletions
@@ -161,6 +161,15 @@ public class SongButton : MonoBehaviour
{
selectedInfo.UpdateSelectedSongDisplay();
}
// Save per-DLC selected song index to PlayerPrefs
string dlcKey = SongSelectUI.CurrentDlcKey;
if (string.IsNullOrEmpty(dlcKey)) dlcKey = "default_0";
string prefsKey = "song_selected_" + dlcKey;
int index = GetIndexAmongSongButtons();
PlayerPrefs.SetInt(prefsKey, index);
PlayerPrefs.Save();
Debug.Log($"SongButton: saved selected song index {index} for key {prefsKey}");
}
else
{
@@ -168,6 +177,23 @@ public class SongButton : MonoBehaviour
}
}
private int GetIndexAmongSongButtons()
{
// Use parent traversal to find only SongButton siblings, to avoid mismatch when other UI children exist.
var parent = transform.parent;
if (parent == null) return 0;
int idx = 0;
for (int i = 0; i < parent.childCount; i++)
{
var child = parent.GetChild(i);
var sb = child != null ? child.GetComponent<SongButton>() : null;
if (sb == null) continue;
if (sb == this) return idx;
idx++;
}
return 0;
}
private void FadeInSelectedBorder()
{
if (selected_boarder != null)
@@ -12,9 +12,4 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 7c972c378bd4832459dead70062eeb5c, type: 3}
m_Name: SongList
m_EditorClassIdentifier:
songs:
- {fileID: 11400000, guid: 955a44007aeca3245a438a8af3e97e04, type: 2}
- {fileID: 11400000, guid: 23248216085203145b3c154e9da5a0dd, type: 2}
- {fileID: 11400000, guid: 0737633aca7fca844b2b4ae0572dcc87, type: 2}
- {fileID: 11400000, guid: e8e4a1801ca7b1f47b60f5d67f792d7b, type: 2}
- {fileID: 11400000, guid: 958379745549ed54ba4da95ba82b0049, type: 2}
songs: []
@@ -2,6 +2,7 @@
using UnityEngine.UI;
using TMPro;
using UnityEngine.SceneManagement;
using System.Collections;
using System.Collections.Generic;
public class SongSelectUI : MonoBehaviour
@@ -13,6 +14,12 @@ public class SongSelectUI : MonoBehaviour
[SerializeField] Button button_Main;
[SerializeField] string ui_Main_Scene_Name = "UI_UI";
// Current DLC key used for per-DLC saved song selection
public static string CurrentDlcKey = "dlc_default_0";
// Track pending restore to avoid multiple overlapping restores
private Coroutine restoreCoroutine;
void Start()
{
if (songList == null || songButtonPrefab == null || contentPanel == null)
@@ -35,6 +42,9 @@ public class SongSelectUI : MonoBehaviour
{
InstantiateSongButton(song);
}
if (restoreCoroutine != null) StopCoroutine(restoreCoroutine);
restoreCoroutine = StartCoroutine(RestoreSelectedSongNextFrame());
}
// Instantiate from a provided list (used by dlcButton to show DLC songs)
@@ -45,6 +55,63 @@ public class SongSelectUI : MonoBehaviour
if (list == null) return;
foreach (var song in list)
InstantiateSongButton(song);
// After populating, attempt to restore per-DLC selected song (next frame to avoid stale objects)
if (restoreCoroutine != null) StopCoroutine(restoreCoroutine);
restoreCoroutine = StartCoroutine(RestoreSelectedSongNextFrame());
}
private IEnumerator RestoreSelectedSongNextFrame()
{
// Wait one frame so Destroy() in ClearSongList fully completes and stale SongButtons are gone.
yield return null;
RestoreSelectedSongForCurrentDlc();
restoreCoroutine = null;
}
private void RestoreSelectedSongForCurrentDlc()
{
// read saved index using CurrentDlcKey
string dlcKey = (string.IsNullOrEmpty(CurrentDlcKey) ? "default_0" : CurrentDlcKey);
string key = "song_selected_" + dlcKey;
// collect song buttons under contentPanel
var allSongButtons = contentPanel.GetComponentsInChildren<SongButton>(true);
if (allSongButtons == null || allSongButtons.Length == 0)
{
Debug.LogWarning("SongSelectUI.RestoreSelectedSongForCurrentDlc: no song buttons found to restore selection");
return;
}
// Ensure every DLC has a default persisted value (0)
int savedIndex;
if (!PlayerPrefs.HasKey(key))
{
PlayerPrefs.SetInt(key, 0);
PlayerPrefs.Save();
savedIndex = 0;
}
else
{
savedIndex = PlayerPrefs.GetInt(key, 0);
}
if (savedIndex < 0) savedIndex = 0;
if (savedIndex >= allSongButtons.Length) savedIndex = 0;
var btn = allSongButtons[savedIndex];
if (btn == null)
{
// hard fallback to first
btn = allSongButtons[0];
}
if (btn != null)
{
// simulate click
btn.OnSongButtonClick();
Debug.Log($"SongSelectUI: restored and clicked song index={savedIndex} for key={key}, totalButtons={allSongButtons.Length}");
}
}
private void ClearSongList()
@@ -193,7 +193,7 @@ RectTransform:
m_AnchorMin: {x: 0.5, y: 0.5}
m_AnchorMax: {x: 0.5, y: 0.5}
m_AnchoredPosition: {x: -131.06, y: 2}
m_SizeDelta: {x: 80, y: 80}
m_SizeDelta: {x: 70, y: 70}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!222 &4297944811495197019
CanvasRenderer:
@@ -270,6 +270,7 @@ RectTransform:
- {fileID: 570804039580569020}
- {fileID: 333634122881333044}
- {fileID: 3306384613169609027}
- {fileID: 4819405071236471537}
m_Father: {fileID: 0}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0.5, y: 0.5}
@@ -376,7 +377,9 @@ MonoBehaviour:
dlcID: {fileID: 115205934777297662}
dlcProducer: {fileID: 2931296379136689410}
dlcPubliushDate: {fileID: 3713972282091736206}
dlc_nowSelectedImageBoarder: {fileID: 2824183749825073581}
dlcDescription: {fileID: 0}
dlcDataSO: {fileID: 0}
dlcContent:
- {fileID: 0}
editorSearchFolder: Assets/Resources/dlc_dlcIndex
@@ -460,6 +463,81 @@ MonoBehaviour:
m_VerticalOverflow: 0
m_LineSpacing: 1
m_Text: dlcNameHere
--- !u!1 &6799314756353582751
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 4819405071236471537}
- component: {fileID: 9008192983113540843}
- component: {fileID: 2824183749825073581}
m_Layer: 5
m_Name: boarder
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &4819405071236471537
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6799314756353582751}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 5010078828579475845}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0.5, y: 0.5}
m_AnchorMax: {x: 0.5, y: 0.5}
m_AnchoredPosition: {x: -0.0897, y: 1}
m_SizeDelta: {x: 364.8207, y: 100}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!222 &9008192983113540843
CanvasRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6799314756353582751}
m_CullTransparentMesh: 1
--- !u!114 &2824183749825073581
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6799314756353582751}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: fe87c0e1cc204ed48ad3b37840f39efc, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 0.2264151, g: 0.2264151, b: 0.2264151, a: 1}
m_RaycastTarget: 1
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
m_Maskable: 1
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_Sprite: {fileID: 21300000, guid: 7f3b1220317607e44bbb8f0e1998044a, type: 3}
m_Type: 1
m_PreserveAspect: 0
m_FillCenter: 0
m_FillMethod: 4
m_FillAmount: 1
m_FillClockwise: 1
m_FillOrigin: 0
m_UseSpriteMesh: 0
m_PixelsPerUnitMultiplier: 3
--- !u!1 &8646457970808721701
GameObject:
m_ObjectHideFlags: 0
@@ -494,8 +572,8 @@ RectTransform:
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0.5, y: 0.5}
m_AnchorMax: {x: 0.5, y: 0.5}
m_AnchoredPosition: {x: 98.09924, y: -37.3367}
m_SizeDelta: {x: 160, y: 16}
m_AnchoredPosition: {x: 94.8, y: -36.5}
m_SizeDelta: {x: 160, y: 12}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!222 &2498827089920741302
CanvasRenderer:
@@ -527,7 +605,7 @@ MonoBehaviour:
m_Calls: []
m_FontData:
m_Font: {fileID: 12800000, guid: 775c674e81662c644b64550d2e8f74e0, type: 3}
m_FontSize: 14
m_FontSize: 12
m_FontStyle: 0
m_BestFit: 0
m_MinSize: 1