131 lines
4.5 KiB
C#
131 lines
4.5 KiB
C#
using System;
|
||
using System.Collections.Generic;
|
||
using UnityEngine;
|
||
|
||
[Serializable]
|
||
public class SongDataSerializable
|
||
{
|
||
// --- 动态变动数据 (需要存储) ---
|
||
public int game_enterTimes;
|
||
public float time_totalPlayingTime;
|
||
public float current_levelProgress;
|
||
public bool _if_level_is_EASE;
|
||
public int max_comboRecord;
|
||
public int personalRecord;
|
||
public string dataHash; // 防篡改校验和
|
||
// public List<int> enemyList = new List<int>(); // Deprecated and removed
|
||
|
||
// --- 字典映射表 (JsonUtility 不支持 Dictionary,需转为 List 存储) ---
|
||
[System.Serializable]
|
||
public struct IntIntEntry
|
||
{
|
||
public int key;
|
||
public int value;
|
||
}
|
||
|
||
public List<IntIntEntry> difficultyNumberList = new List<IntIntEntry>();
|
||
public List<IntIntEntry> personalRecordList = new List<IntIntEntry>();
|
||
public List<IntIntEntry> idolRecordList = new List<IntIntEntry>();
|
||
public List<IntIntEntry> chartScoreList = new List<IntIntEntry>();
|
||
|
||
[System.Serializable]
|
||
public struct IntFloatEntry
|
||
{
|
||
public int key;
|
||
public float value;
|
||
}
|
||
public List<IntFloatEntry> levelProgressList = new List<IntFloatEntry>();
|
||
|
||
public SongDataSerializable() { }
|
||
|
||
public SongDataSerializable(SongData source)
|
||
{
|
||
if (source == null) return;
|
||
|
||
// 提取动态数据
|
||
this.game_enterTimes = source.game_enterTimes;
|
||
this.time_totalPlayingTime = source.time_totalPlayingTime;
|
||
this.current_levelProgress = source.current_levelProgress;
|
||
this._if_level_is_EASE = source._if_level_is_EASE;
|
||
this.max_comboRecord = source.max_comboRecord;
|
||
this.personalRecord = source.personalRecord;
|
||
// this.enemyList = new List<int>(source.enemyList); // Deprecated and removed
|
||
|
||
// 将字典转换为 List
|
||
this.difficultyNumberList = DictToList(source.difficultyNumberMap);
|
||
this.personalRecordList = DictToList(source.personalRecordMap);
|
||
this.idolRecordList = DictToList(source.idolRecordMap);
|
||
this.chartScoreList = DictToList(source.chartScoreMap);
|
||
this.levelProgressList = DictToListFloat(source.levelProgressMap);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 将序列化的动态数据应用回 SongData SO。
|
||
/// </summary>
|
||
public void ApplyTo(SongData target)
|
||
{
|
||
if (target == null) return;
|
||
|
||
target.game_enterTimes = this.game_enterTimes;
|
||
target.time_totalPlayingTime = this.time_totalPlayingTime;
|
||
target.current_levelProgress = this.current_levelProgress;
|
||
target._if_level_is_EASE = this._if_level_is_EASE;
|
||
target.max_comboRecord = this.max_comboRecord;
|
||
target.personalRecord = this.personalRecord;
|
||
// target.enemyList = new List<int>(this.enemyList); // Deprecated and removed
|
||
|
||
// 将 List 还原回字典
|
||
ListToDict(this.difficultyNumberList, target.difficultyNumberMap);
|
||
ListToDict(this.personalRecordList, target.personalRecordMap);
|
||
ListToDict(this.idolRecordList, target.idolRecordMap);
|
||
ListToDict(this.chartScoreList, target.chartScoreMap);
|
||
ListToDictFloat(this.levelProgressList, target.levelProgressMap);
|
||
}
|
||
|
||
private List<IntIntEntry> DictToList(Dictionary<int, int> dict)
|
||
{
|
||
List<IntIntEntry> list = new List<IntIntEntry>();
|
||
if (dict != null)
|
||
{
|
||
foreach (var kvp in dict)
|
||
{
|
||
list.Add(new IntIntEntry { key = kvp.Key, value = kvp.Value });
|
||
}
|
||
}
|
||
return list;
|
||
}
|
||
|
||
private void ListToDict(List<IntIntEntry> list, Dictionary<int, int> dict)
|
||
{
|
||
if (list == null || dict == null) return;
|
||
dict.Clear();
|
||
foreach (var entry in list)
|
||
{
|
||
dict[entry.key] = entry.value;
|
||
}
|
||
}
|
||
|
||
private List<IntFloatEntry> DictToListFloat(Dictionary<int, float> dict)
|
||
{
|
||
List<IntFloatEntry> list = new List<IntFloatEntry>();
|
||
if (dict != null)
|
||
{
|
||
foreach (var kvp in dict)
|
||
{
|
||
list.Add(new IntFloatEntry { key = kvp.Key, value = kvp.Value });
|
||
}
|
||
}
|
||
return list;
|
||
}
|
||
|
||
private void ListToDictFloat(List<IntFloatEntry> list, Dictionary<int, float> dict)
|
||
{
|
||
if (list == null || dict == null) return;
|
||
dict.Clear();
|
||
foreach (var entry in list)
|
||
{
|
||
dict[entry.key] = entry.value;
|
||
}
|
||
}
|
||
}
|