This commit is contained in:
SoulliesOfficial
2025-07-26 04:20:25 -04:00
parent bae0bfbc20
commit abf81ece7b
196 changed files with 3909 additions and 964 deletions

View File

@@ -1,3 +1,4 @@
using System;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;
@@ -44,6 +45,8 @@ namespace Ichni.Menu.UI
public float bottomBound = 0f;
private Vector2 targetPosition; // 【新增】内容的目标位置
private float targetX = 1500f;
public bool isDuringSnap = false;
public RectTransform closestTab;
void Start()
{
@@ -52,6 +55,27 @@ namespace Ichni.Menu.UI
targetX = -1500f;
}
private void Update()
{
RectTransform closestItem = closestTab;
float cloesestY = Mathf.Infinity;
foreach (RectTransform item in songItems)
{
float distance = Mathf.Abs(item.position.y - centerPoint.position.y);
if (distance < cloesestY)
{
cloesestY = distance;
closestItem = item;
}
}
if (closestItem != null && closestTab != closestItem)
{
closestTab = closestItem;
MenuAudioManager.instance.audioContainer.PlaySoundFX("SelectTab");
}
}
// 使用LateUpdate来处理所有位置更新防止抖动
void LateUpdate()
{
@@ -103,6 +127,8 @@ namespace Ichni.Menu.UI
{
StartCoroutine(SnapToItem(songItems[0], true));
}
closestTab = songItems[0];
}
public void GenerateSongTabs()
@@ -189,12 +215,18 @@ namespace Ichni.Menu.UI
}
}
public IEnumerator SnapCoroutine;
public IEnumerator SnapToTab(SongSelectionTab tab)
{
selectedTab?.SetSelection(false);
selectedTab = null; // 清除当前选中的Tab
if(isDuringSnap && SnapCoroutine != null) StopCoroutine(SnapCoroutine);
yield return StartCoroutine(SnapToItem(tab.GetComponent<RectTransform>(), false));
SnapCoroutine = SnapToItem(tab.GetComponent<RectTransform>(), false);
yield return StartCoroutine(SnapCoroutine);
}
private IEnumerator SnapToItem(RectTransform targetItem, bool immediate)
@@ -211,7 +243,7 @@ namespace Ichni.Menu.UI
SongItemData connectedSong = selectedTab.connectedSong;
MenuManager.instance.songSelectionUIPage.selectedSong = connectedSong;
MenuManager.instance.songSelectionUIPage.selectedSave = GameSaveManager.instance.SongSaveModule.GetSongStatusSave(connectedSong.songName);
Vector3 closestItemLocalPos = viewport.InverseTransformPoint(targetItem.position);
Vector3 centerPointLocalPos = viewport.InverseTransformPoint(centerPoint.position);
@@ -229,6 +261,7 @@ namespace Ichni.Menu.UI
}
else
{
isDuringSnap = true;
// 动画模式只更新Target让LateUpdate中的Lerp来完成动画
targetPosition = finalTargetPosition;
@@ -243,11 +276,13 @@ namespace Ichni.Menu.UI
content.anchoredPosition = targetPosition;
}
Debug.Log($"已对齐到: {targetItem.name}");
selectedTab.SetPreview();
Debug.Log($"已对齐到: {targetItem.GetComponent<SongSelectionTab>().songNameText.text}");
SongSelectionManager.instance.SetPreview(connectedSong, selectedTab.isLocked);
MenuManager.instance.songSelectionUIPage.difficultySelectionContainer.SetUp(connectedSong.difficultyDataList);
MenuManager.instance.songSelectionUIPage.songInfoUI.SetIllustration(connectedSong.illustration, connectedSong.illustratorName);
isDuringSnap = false;
}
}
}