original ver 25/06/01
This commit is contained in:
@@ -0,0 +1,144 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
[Serializable]
|
||||
public class ChartFileEntry
|
||||
{
|
||||
public int difficulty; // 该谱面对应的难度
|
||||
public TextAsset chartFile; // 谱面文件
|
||||
}
|
||||
|
||||
[CreateAssetMenu(fileName = "NewSongData", menuName = "EaseOut/SongData")]
|
||||
public class SongData : ScriptableObject
|
||||
{
|
||||
public string usernameID = "user_TestUser@FloatGaming";
|
||||
public string songName;
|
||||
public int songID;
|
||||
public int songLength_second;
|
||||
public string artistName;
|
||||
public string painter;
|
||||
public string level_creator;
|
||||
public string belongsTo_whichDLC;
|
||||
|
||||
public int bpm;
|
||||
public float songDuration;
|
||||
|
||||
public int game_enterTimes;
|
||||
public int time_totalPlayingTime;
|
||||
public DateTime uploadData;
|
||||
|
||||
public Sprite illustration;
|
||||
public Sprite backgroudPIC;
|
||||
public Sprite fullscreen_songPicture;
|
||||
public AudioClip audioFile;
|
||||
public AudioClip audio_previewAudio;
|
||||
|
||||
// 支持不同难度的数据
|
||||
public Dictionary<int, int> difficultyNumberMap = new Dictionary<int, int>(); // 各个难度的难度数值
|
||||
public Dictionary<int, int> personalRecordMap = new Dictionary<int, int>(); // 各个难度的最高分
|
||||
public Dictionary<int, TextAsset> chartFileMap = new Dictionary<int, TextAsset>(); // 各个难度下的谱面文件
|
||||
|
||||
// 用于在 Inspector 选择谱面文件
|
||||
public List<ChartFileEntry> chartFiles = new List<ChartFileEntry>();
|
||||
|
||||
// 个人最高记录(所有难度中的最高分)
|
||||
public int personalRecord;
|
||||
|
||||
// 当前游玩的难度
|
||||
public int difficultyID;
|
||||
public float current_levelProgress;
|
||||
public bool _if_level_is_EASE;
|
||||
public int max_comboRecord;
|
||||
|
||||
// 构造函数:从 JSON 数据创建 SongData
|
||||
public SongData(SongDataSerializable jsonData)
|
||||
{
|
||||
usernameID = jsonData.usernameID;
|
||||
songName = jsonData.songName;
|
||||
songID = jsonData.songID;
|
||||
songLength_second = jsonData.songLength_second;
|
||||
artistName = jsonData.artistName;
|
||||
painter = jsonData.painter;
|
||||
level_creator = jsonData.level_creator;
|
||||
belongsTo_whichDLC = jsonData.belongsTo_whichDLC;
|
||||
|
||||
bpm = jsonData.bpm;
|
||||
songDuration = jsonData.songDuration;
|
||||
|
||||
game_enterTimes = jsonData.game_enterTimes;
|
||||
time_totalPlayingTime = jsonData.time_totalPlayingTime;
|
||||
uploadData = DateTime.Parse(jsonData.uploadData);
|
||||
|
||||
difficultyID = jsonData.difficultyID;
|
||||
current_levelProgress = jsonData.current_levelProgress;
|
||||
_if_level_is_EASE = jsonData._if_level_is_EASE;
|
||||
max_comboRecord = jsonData.max_comboRecord;
|
||||
|
||||
difficultyNumberMap = jsonData.difficultyNumberMap;
|
||||
personalRecordMap = jsonData.personalRecordMap;
|
||||
personalRecord = jsonData.personalRecord; // 赋值最高成绩
|
||||
|
||||
// 确保 JSON 里的谱面文件映射到可用的 List
|
||||
foreach (var kvp in jsonData.chartFileMap)
|
||||
{
|
||||
chartFiles.Add(new ChartFileEntry { difficulty = kvp.Key, chartFile = Resources.Load<TextAsset>("Charts/" + kvp.Value) });
|
||||
}
|
||||
SyncChartFileMap();
|
||||
}
|
||||
|
||||
// 获取所有难度中最高的成绩
|
||||
public int CalculateHighestPersonalRecord()
|
||||
{
|
||||
int highest = 0;
|
||||
foreach (var score in personalRecordMap.Values)
|
||||
{
|
||||
if (score > highest)
|
||||
{
|
||||
highest = score;
|
||||
}
|
||||
}
|
||||
personalRecord = highest;
|
||||
return highest;
|
||||
}
|
||||
|
||||
// 更新指定难度的最高成绩
|
||||
public void UpdatePersonalRecord(int difficulty, int newScore)
|
||||
{
|
||||
if (!personalRecordMap.ContainsKey(difficulty) || newScore > personalRecordMap[difficulty])
|
||||
{
|
||||
personalRecordMap[difficulty] = newScore;
|
||||
}
|
||||
CalculateHighestPersonalRecord();
|
||||
}
|
||||
|
||||
// 获取特定难度的最高分
|
||||
public int GetPersonalRecord(int difficulty)
|
||||
{
|
||||
return personalRecordMap.ContainsKey(difficulty) ? personalRecordMap[difficulty] : 0;
|
||||
}
|
||||
|
||||
// 获取指定难度的谱面文件
|
||||
public TextAsset GetChartFile(int difficulty)
|
||||
{
|
||||
foreach (var entry in chartFiles)
|
||||
{
|
||||
if (entry.difficulty == difficulty)
|
||||
return entry.chartFile;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// 同步 Dictionary 和 List 确保数据一致
|
||||
public void SyncChartFileMap()
|
||||
{
|
||||
chartFileMap.Clear();
|
||||
foreach (var entry in chartFiles)
|
||||
{
|
||||
if (entry.chartFile != null)
|
||||
{
|
||||
chartFileMap[entry.difficulty] = entry.chartFile;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user