50 lines
1.7 KiB
C#
50 lines
1.7 KiB
C#
using UnityEngine;
|
|
using TMPro;
|
|
using UnityEngine.UI;
|
|
using UnityEngine.SceneManagement;
|
|
|
|
public class SongButton : MonoBehaviour
|
|
{
|
|
public TextMeshProUGUI songNameText; // 歌曲名称文本
|
|
public TextMeshProUGUI highestScoreText; // 个人最高分文本
|
|
public TextMeshProUGUI difficultyIDText; // 难度ID文本
|
|
public TextMeshProUGUI songIDText;
|
|
public Image buttonImage; // 按钮的 Image 组件,用于设置背景图像
|
|
public int song_songSerialID; // 按钮对应的歌曲ID
|
|
|
|
// 设置按钮的数据
|
|
|
|
public void Start()
|
|
{
|
|
|
|
}
|
|
public void SetButtonData(string songName, int highestScore, int difficultyID, Sprite songSprite, int songID)
|
|
{
|
|
Debug.Log("SetButtonData 被调用, songID 参数: " + songID);
|
|
songNameText.text = songName;
|
|
highestScoreText.text = "PR: " + highestScore.ToString();
|
|
difficultyIDText.text = "" + difficultyID.ToString();
|
|
buttonImage.sprite = songSprite;
|
|
song_songSerialID = songID;
|
|
songIDText.text = "Song ID: " + song_songSerialID.ToString();
|
|
}
|
|
|
|
|
|
// 按钮点击事件:根据 song_songSerialID 查找对应的 SongData,并传递到下个场景
|
|
public void OnSongButtonClick()
|
|
{
|
|
Debug.Log("点击按钮的 song_songSerialID: " + song_songSerialID);
|
|
SongData selectedSong = SongDataLibrary.Instance.GetSongDataByID(song_songSerialID);
|
|
if (selectedSong != null)
|
|
{
|
|
SongDataHolder.SelectedSongData = selectedSong;
|
|
SceneManager.LoadScene("Songs_Select");
|
|
}
|
|
else
|
|
{
|
|
Debug.LogError("未找到对应的 SongData, songID: " + song_songSerialID);
|
|
}
|
|
}
|
|
|
|
}
|