删除文件 Assets/scripts/gamePlay_gameplay/BeatmapManager.cs
This commit is contained in:
@@ -1,131 +0,0 @@
|
||||
using System.IO;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
|
||||
public class BeatmapManager : MonoBehaviour
|
||||
|
||||
{
|
||||
public Beatmap beatmap; // 当前谱面数据
|
||||
|
||||
// 音符生成器引用
|
||||
public NoteSpawner noteSpawner;
|
||||
|
||||
|
||||
|
||||
// 保存谱面数据到 JSON 文件
|
||||
//public void SaveBeatmap(string fileName)
|
||||
//{
|
||||
// string json = JsonUtility.ToJson(beatmap, true); // 格式化 JSON 输出
|
||||
// File.WriteAllText(Application.dataPath + "/" + fileName, json);
|
||||
// Debug.Log("谱面已保存:" + Application.dataPath + "/" + fileName);
|
||||
//}
|
||||
|
||||
// 从 JSON 文件加载谱面数据
|
||||
public void LoadBeatmap(string fileName)
|
||||
{
|
||||
string path = Application.streamingAssetsPath + "/" + fileName;
|
||||
if (File.Exists(path))
|
||||
{
|
||||
string json = File.ReadAllText(path);
|
||||
beatmap = JsonUtility.FromJson<Beatmap>(json);
|
||||
Debug.Log("谱面已加载:" + json);
|
||||
|
||||
// 在加载后立即调用音符生成
|
||||
noteSpawner.LoadBeatmap(beatmap);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError("文件不存在:" + path);
|
||||
}
|
||||
}
|
||||
public void LoadBeatmap(Beatmap loadedBeatmap)
|
||||
{
|
||||
beatmap = loadedBeatmap;
|
||||
Debug.Log("谱面已加载:" + beatmap.title);
|
||||
|
||||
// 在加载后立即调用音符生成
|
||||
noteSpawner.LoadBeatmap(beatmap);
|
||||
}
|
||||
|
||||
//public void LoadBeatmapFromFile(string fileName)
|
||||
//{
|
||||
// string path = Application.persistentDataPath + "/" + fileName;
|
||||
// if (File.Exists(path))
|
||||
// {
|
||||
// string json = File.ReadAllText(path);
|
||||
// Beatmap beatmap = JsonUtility.FromJson<Beatmap>(json);
|
||||
// beatmapManager.LoadBeatmap(beatmap); // 使用 LoadBeatmap 方法传递 Beatmap 对象
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// Debug.LogError("文件不存在:" + path);
|
||||
// }
|
||||
//}
|
||||
|
||||
// 创建一个示例谱面并保存
|
||||
//public void CreateSampleBeatmap()
|
||||
//{
|
||||
// beatmap = new Beatmap
|
||||
// {
|
||||
// title = "Moonlight Sonata",
|
||||
// composer = "Ludwig van Beethoven",
|
||||
// illustrator = "John Doe",
|
||||
// charter = "Jane Smith",
|
||||
// beatmapId = "ML-001",
|
||||
// duration = 120.5f,
|
||||
// bpm = 128f,
|
||||
// difficulty = 5,
|
||||
// difficultyName = "Hard",
|
||||
// createdDate = System.DateTime.Now.ToString("yyyy-MM-dd"),
|
||||
// musicFile = "moonlight_sonata.mp3",
|
||||
// backgroundFile = "moonlight_art.png",
|
||||
|
||||
// tracks = new TrackData[]
|
||||
// {
|
||||
// new TrackData { color = "red" },
|
||||
// new TrackData { color = "green" },
|
||||
// new TrackData { color = "yellow" },
|
||||
// new TrackData { color = "purple" },
|
||||
// new TrackData { color = "blue" }
|
||||
// },
|
||||
|
||||
// notes = new NoteData[]
|
||||
// {
|
||||
// new NoteData { trackIndex = 0, time = 1.0f, color = "red", type = "tap", length = 0.0f },
|
||||
// new NoteData { trackIndex = 4, time = 2.0f, color = "blue", type = "tap", length = 0.0f },
|
||||
// new NoteData { trackIndex = 1, time = 3.5f, color = "green", type = "tap", length = 0.0f },
|
||||
// new NoteData { trackIndex = 2, time = 3.5f, color = "yellow", type = "tap", length = 0.0f },
|
||||
// new NoteData { trackIndex = 2, time = 3.5f, color = "yellow", type = "tap", length = 0.0f },
|
||||
// new NoteData { trackIndex = 3, time = 3.5f, color = "purple", type = "tap", length = 0.0f },
|
||||
// }
|
||||
// };
|
||||
|
||||
// SaveBeatmap("test_beatmap.json");
|
||||
//}
|
||||
|
||||
// 读取并加载当前谱面到音符生成器
|
||||
public void LoadBeatmapFromFile()
|
||||
{
|
||||
string path = Application.streamingAssetsPath + "/Emilia_demo.json";
|
||||
if (File.Exists(path))
|
||||
{
|
||||
string json = File.ReadAllText(path);
|
||||
beatmap = JsonUtility.FromJson<Beatmap>(json);
|
||||
noteSpawner.LoadBeatmap(beatmap);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError("谱面文件未找到!");
|
||||
}
|
||||
}
|
||||
|
||||
// 在 Start() 方法中初始化
|
||||
void Start()
|
||||
{
|
||||
// 这里可以选择在启动时创建一个示例谱面并加载
|
||||
//CreateSampleBeatmap(); // 创建并保存一个示例谱面
|
||||
LoadBeatmap("Emilia_demo.json"); // 加载并实例化音符
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user