修复了选曲的问题 优化了ui
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine.SceneManagement;
|
||||
using System.Collections;
|
||||
|
||||
public class SongButton : MonoBehaviour
|
||||
{
|
||||
@@ -18,27 +19,47 @@ public class SongButton : MonoBehaviour
|
||||
[Header("头图")]
|
||||
public Image profileImage;
|
||||
public int song_songSerialID;
|
||||
[Header("select mark")]
|
||||
public Image selected_boarder;
|
||||
public Image fade_image;
|
||||
|
||||
[Header("Fade Image Settings")]
|
||||
public float minAlpha = 0f;
|
||||
public float maxAlpha = 1f;
|
||||
public float blinkDuration = 0.5f;
|
||||
|
||||
private static SongButton currentSelected;
|
||||
private Coroutine fadeCoroutine;
|
||||
private Coroutine blinkCoroutine;
|
||||
|
||||
public void Start()
|
||||
{
|
||||
if (selected_boarder != null)
|
||||
{
|
||||
Color c = selected_boarder.color;
|
||||
c.a = 0f;
|
||||
selected_boarder.color = c;
|
||||
}
|
||||
if (fade_image != null)
|
||||
{
|
||||
Color c = fade_image.color;
|
||||
c.a = 0f;
|
||||
fade_image.color = c;
|
||||
}
|
||||
}
|
||||
|
||||
public void SetButtonData(string songName, int highestScore, int difficultyID, Sprite songSprite, int songID)
|
||||
{
|
||||
Debug.Log("SetButtonData 被调用, songID 参数: " + songID);
|
||||
|
||||
// try to load SongData by id and populate fields from SO when available
|
||||
var sd = SongDataLibrary.Instance != null ? SongDataLibrary.Instance.GetSongDataByID(songID) : null;
|
||||
if (sd != null)
|
||||
{
|
||||
// song name
|
||||
if (songNameText != null) songNameText.text = sd.songName;
|
||||
|
||||
// multi name text: 音乐:artist | 曲绘:painter | 制谱:level_creator
|
||||
if (multiNameText != null)
|
||||
multiNameText.text = "音乐:" + sd.artistName + " | 曲绘:" + sd.painter + " | 制谱:" + sd.level_creator;
|
||||
|
||||
// song join time and DLC
|
||||
if (joinTime_and_dlcName_Text != null)
|
||||
{
|
||||
string join = string.IsNullOrEmpty(sd.thisLevel_addDateString) ? "未知" : sd.thisLevel_addDateString;
|
||||
@@ -46,13 +67,11 @@ public class SongButton : MonoBehaviour
|
||||
joinTime_and_dlcName_Text.text = "歌曲收录时间:" + join + " | " + "所属DLC:" + dlc;
|
||||
}
|
||||
|
||||
// song overall description
|
||||
if (songOverallDescriptionText != null)
|
||||
{
|
||||
songOverallDescriptionText.text = string.IsNullOrEmpty(sd.thisLevel_overallDescription) ? "暂无歌曲简介。" : sd.thisLevel_overallDescription;
|
||||
}
|
||||
|
||||
// compute highest total (chart personal + idol) and its difficulty
|
||||
int bestTotal = 0;
|
||||
int bestDiff = -1;
|
||||
if (sd.personalRecordMap != null)
|
||||
@@ -71,7 +90,6 @@ public class SongButton : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
// fallback: use stored personalRecord and selected difficulty if maps empty
|
||||
if (bestDiff == -1)
|
||||
{
|
||||
bestTotal = sd.personalRecord;
|
||||
@@ -80,7 +98,6 @@ public class SongButton : MonoBehaviour
|
||||
|
||||
if (highestScoreText != null) highestScoreText.text = bestTotal.ToString();
|
||||
|
||||
// difficultyIDText: show difficultyLEVEL from ChartFileEntry of bestDiff if available, else show numeric id
|
||||
string diffDisplay = bestDiff.ToString();
|
||||
if (sd.chartFiles != null)
|
||||
{
|
||||
@@ -95,10 +112,8 @@ public class SongButton : MonoBehaviour
|
||||
}
|
||||
if (difficultyIDText != null) difficultyIDText.text = diffDisplay;
|
||||
|
||||
// button image
|
||||
if (buttonImage != null) buttonImage.sprite = sd.backgroudPIC;
|
||||
|
||||
// profile image: use card_profileImage from SO
|
||||
if (profileImage != null)
|
||||
{
|
||||
profileImage.sprite = sd.card_profileImage;
|
||||
@@ -109,7 +124,6 @@ public class SongButton : MonoBehaviour
|
||||
}
|
||||
else
|
||||
{
|
||||
// hide if no sprite
|
||||
profileImage.enabled = false;
|
||||
}
|
||||
}
|
||||
@@ -119,7 +133,6 @@ public class SongButton : MonoBehaviour
|
||||
}
|
||||
else
|
||||
{
|
||||
// fallback to original behavior if SO not found
|
||||
if (songNameText != null) songNameText.text = songName;
|
||||
if (highestScoreText != null) highestScoreText.text = "PR: " + highestScore.ToString();
|
||||
if (difficultyIDText != null) difficultyIDText.text = difficultyID.ToString();
|
||||
@@ -135,12 +148,95 @@ public class SongButton : MonoBehaviour
|
||||
SongData selectedSong = SongDataLibrary.Instance.GetSongDataByID(song_songSerialID);
|
||||
if (selectedSong != null)
|
||||
{
|
||||
if (currentSelected != null && currentSelected != this)
|
||||
{
|
||||
currentSelected.FadeOutSelectedBorder();
|
||||
}
|
||||
currentSelected = this;
|
||||
FadeInSelectedBorder();
|
||||
|
||||
SongDataHolder.SelectedSongData = selectedSong;
|
||||
SceneManager.LoadScene("Songs_Select");
|
||||
var selectedInfo = FindObjectOfType<selected_songInfo>();
|
||||
if (selectedInfo != null)
|
||||
{
|
||||
selectedInfo.UpdateSelectedSongDisplay();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError("未找到对应的 SongData, songID: " + song_songSerialID);
|
||||
}
|
||||
}
|
||||
|
||||
private void FadeInSelectedBorder()
|
||||
{
|
||||
if (selected_boarder != null)
|
||||
{
|
||||
if (fadeCoroutine != null) StopCoroutine(fadeCoroutine);
|
||||
fadeCoroutine = StartCoroutine(FadeImage(selected_boarder, selected_boarder.color.a, 1f, 0.3f));
|
||||
}
|
||||
if (fade_image != null)
|
||||
{
|
||||
if (blinkCoroutine != null) StopCoroutine(blinkCoroutine);
|
||||
blinkCoroutine = StartCoroutine(BlinkFadeImage());
|
||||
}
|
||||
}
|
||||
|
||||
private void FadeOutSelectedBorder()
|
||||
{
|
||||
if (selected_boarder != null)
|
||||
{
|
||||
if (fadeCoroutine != null) StopCoroutine(fadeCoroutine);
|
||||
fadeCoroutine = StartCoroutine(FadeImage(selected_boarder, selected_boarder.color.a, 0f, 0.3f));
|
||||
}
|
||||
if (fade_image != null)
|
||||
{
|
||||
if (blinkCoroutine != null) StopCoroutine(blinkCoroutine);
|
||||
fadeCoroutine = StartCoroutine(FadeImage(fade_image, fade_image.color.a, 0f, 0.3f));
|
||||
}
|
||||
}
|
||||
|
||||
private IEnumerator FadeImage(Image img, float startAlpha, float endAlpha, float duration)
|
||||
{
|
||||
if (img == null) yield break;
|
||||
float time = 0f;
|
||||
Color color = img.color;
|
||||
while (time < duration)
|
||||
{
|
||||
time += Time.deltaTime;
|
||||
float alpha = Mathf.Lerp(startAlpha, endAlpha, time / duration);
|
||||
color.a = alpha;
|
||||
img.color = color;
|
||||
yield return null;
|
||||
}
|
||||
color.a = endAlpha;
|
||||
img.color = color;
|
||||
}
|
||||
|
||||
private IEnumerator BlinkFadeImage()
|
||||
{
|
||||
if (fade_image == null) yield break;
|
||||
Color color = fade_image.color;
|
||||
while (true)
|
||||
{
|
||||
float time = 0f;
|
||||
while (time < blinkDuration / 2f)
|
||||
{
|
||||
time += Time.deltaTime;
|
||||
float alpha = Mathf.Lerp(minAlpha, maxAlpha, time / (blinkDuration / 2f));
|
||||
color.a = alpha;
|
||||
fade_image.color = color;
|
||||
yield return null;
|
||||
}
|
||||
time = 0f;
|
||||
while (time < blinkDuration / 2f)
|
||||
{
|
||||
time += Time.deltaTime;
|
||||
float alpha = Mathf.Lerp(maxAlpha, minAlpha, time / (blinkDuration / 2f));
|
||||
color.a = alpha;
|
||||
fade_image.color = color;
|
||||
yield return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user