基础内容11 - SAVE LOAD EXPORT
This commit is contained in:
173
Assets/Scripts/Base/Manager/ProjectManager.cs
Normal file
173
Assets/Scripts/Base/Manager/ProjectManager.cs
Normal file
@@ -0,0 +1,173 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Ichni.RhythmGame;
|
||||
using Ichni.RhythmGame.Beatmap;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Ichni
|
||||
{
|
||||
public class ProjectManager
|
||||
{
|
||||
public static readonly ES3Settings SaveSettings = new ES3Settings
|
||||
{
|
||||
compressionType = ES3.CompressionType.None,
|
||||
encryptionType = ES3.EncryptionType.None,
|
||||
format = ES3.Format.JSON,
|
||||
};
|
||||
|
||||
public static readonly ES3Settings ExportSettings = new ES3Settings
|
||||
{
|
||||
compressionType = ES3.CompressionType.Gzip,
|
||||
encryptionType = ES3.EncryptionType.AES,
|
||||
encryptionPassword = "Soullies515",
|
||||
format = ES3.Format.JSON,
|
||||
};
|
||||
|
||||
public SaveManager saveManager;
|
||||
public LoadManager loadManager;
|
||||
public ExportManager exportManager;
|
||||
|
||||
public ProjectManager()
|
||||
{
|
||||
saveManager = new SaveManager();
|
||||
loadManager = new LoadManager();
|
||||
exportManager = new ExportManager();
|
||||
}
|
||||
|
||||
public void GenerateProject(string projectName)
|
||||
{
|
||||
EditorManager.instance.projectInformation = new ProjectInformation(projectName, "Soullies",
|
||||
"2.0", "2025-02-08", "2025-02-08", new List<string>());
|
||||
EditorManager.instance.songInformation = new SongInformation("TestSong", 120, 0);
|
||||
EditorManager.instance.beatmapContainer = new BeatmapContainer();
|
||||
EditorManager.instance.commandScripts = new CommandScripts(new List<string>());
|
||||
|
||||
//Create project folder
|
||||
if (!System.IO.Directory.Exists(EditorManager.instance.projectInformation.projectPath))
|
||||
{
|
||||
System.IO.Directory.CreateDirectory(EditorManager.instance.projectInformation.projectPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class ExportManager
|
||||
{
|
||||
public void Export()
|
||||
{
|
||||
string exportPath = Application.streamingAssetsPath + "/Export/" +
|
||||
EditorManager.instance.projectInformation.projectName;
|
||||
string projectInfoPath = exportPath + "/ProjectInfo.bytes";
|
||||
string songInfoPath = exportPath + "/SongInfo.bytes";
|
||||
string beatmapPath = exportPath + "/BeatMap.bytes";
|
||||
string commandScriptsPath = exportPath + "/CommandScripts.bytes";
|
||||
|
||||
ExportProjectInfo(projectInfoPath);
|
||||
ExportSongInfo(songInfoPath);
|
||||
ExportBeatMap(beatmapPath);
|
||||
ExportCommandScripts(commandScriptsPath);
|
||||
}
|
||||
|
||||
private void ExportProjectInfo(string exportPath)
|
||||
{
|
||||
EditorManager.instance.projectInformation.SaveBM();
|
||||
ES3.Save("ProjectInformation", EditorManager.instance.projectInformation.matchedBM as ProjectInformation_BM,
|
||||
exportPath, ProjectManager.ExportSettings);
|
||||
}
|
||||
|
||||
private void ExportSongInfo(string exportPath)
|
||||
{
|
||||
EditorManager.instance.songInformation.SaveBM();
|
||||
ES3.Save("SongInformation", EditorManager.instance.songInformation.matchedBM as SongInformation_BM,
|
||||
exportPath, ProjectManager.ExportSettings);
|
||||
}
|
||||
|
||||
private void ExportBeatMap(string exportPath)
|
||||
{
|
||||
EditorManager.instance.beatmapContainer.SaveBM();
|
||||
ES3.Save("BeatMap", EditorManager.instance.beatmapContainer.matchedBM as BeatmapContainer_BM,
|
||||
exportPath, ProjectManager.ExportSettings);
|
||||
}
|
||||
|
||||
private void ExportCommandScripts(string exportPath)
|
||||
{
|
||||
EditorManager.instance.commandScripts.SaveBM();
|
||||
ES3.Save("CommandScripts", EditorManager.instance.commandScripts.matchedBM as CommandScripts_BM,
|
||||
exportPath, ProjectManager.ExportSettings);
|
||||
}
|
||||
}
|
||||
|
||||
public class SaveManager
|
||||
{
|
||||
public void Save()
|
||||
{
|
||||
SaveProjectInfo();
|
||||
SaveSongInfo();
|
||||
SaveBeatMap();
|
||||
SaveCommandScripts();
|
||||
}
|
||||
|
||||
private void SaveProjectInfo()
|
||||
{
|
||||
EditorManager.instance.projectInformation.SaveBM();
|
||||
ES3.Save("ProjectInformation", EditorManager.instance.projectInformation.matchedBM as ProjectInformation_BM,
|
||||
EditorManager.instance.projectInformation.peojectInfoPath, ProjectManager.SaveSettings);
|
||||
}
|
||||
|
||||
private void SaveSongInfo()
|
||||
{
|
||||
EditorManager.instance.songInformation.SaveBM();
|
||||
ES3.Save("SongInformation", EditorManager.instance.songInformation.matchedBM as SongInformation_BM,
|
||||
EditorManager.instance.projectInformation.songInfoPath, ProjectManager.SaveSettings);
|
||||
}
|
||||
|
||||
private void SaveBeatMap()
|
||||
{
|
||||
EditorManager.instance.beatmapContainer.SaveBM();
|
||||
ES3.Save("BeatMap", EditorManager.instance.beatmapContainer.matchedBM as BeatmapContainer_BM,
|
||||
EditorManager.instance.projectInformation.beatmapPath, ProjectManager.SaveSettings);
|
||||
}
|
||||
|
||||
private void SaveCommandScripts()
|
||||
{
|
||||
EditorManager.instance.commandScripts.SaveBM();
|
||||
ES3.Save("CommandScripts", EditorManager.instance.commandScripts.matchedBM as CommandScripts_BM,
|
||||
EditorManager.instance.projectInformation.CommandScriptsPath, ProjectManager.SaveSettings);
|
||||
}
|
||||
}
|
||||
|
||||
public class LoadManager
|
||||
{
|
||||
public void Load(string projectName)
|
||||
{
|
||||
LoadProjectInfo(projectName);
|
||||
LoadSongInfo();
|
||||
LoadBeatMap();
|
||||
LoadCommandScripts();
|
||||
}
|
||||
|
||||
private void LoadProjectInfo(string projectName)
|
||||
{
|
||||
string projectInfoPath = Application.streamingAssetsPath + "/Projects/" + projectName + "/ProjectInfo.json";
|
||||
ES3.Load<ProjectInformation_BM>("ProjectInformation", projectInfoPath, ProjectManager.SaveSettings).ExecuteBM();
|
||||
}
|
||||
|
||||
private void LoadSongInfo()
|
||||
{
|
||||
ES3.Load<SongInformation_BM>("SongInformation", EditorManager.instance.projectInformation.songInfoPath,
|
||||
ProjectManager.SaveSettings).ExecuteBM();
|
||||
}
|
||||
|
||||
private void LoadBeatMap()
|
||||
{
|
||||
ES3.Load<BeatmapContainer_BM>("BeatMap", EditorManager.instance.projectInformation.beatmapPath,
|
||||
ProjectManager.SaveSettings).ExecuteBM();
|
||||
}
|
||||
|
||||
private void LoadCommandScripts()
|
||||
{
|
||||
ES3.Load<CommandScripts_BM>("CommandScripts", EditorManager.instance.projectInformation.CommandScriptsPath,
|
||||
ProjectManager.SaveSettings).ExecuteBM();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user