基础内容11 - SAVE LOAD EXPORT
This commit is contained in:
@@ -14,73 +14,84 @@ namespace Ichni
|
||||
public static EditorManager instance;
|
||||
|
||||
public SongModule songModule;
|
||||
|
||||
public ProjectManager projectManager;
|
||||
public EditorSettings editorSettings;
|
||||
|
||||
public ProjectInformation projectInformation;
|
||||
public SongInformation songInformation;
|
||||
public BeatmapContainer beatmapContainer;
|
||||
public CommandScripts commandScripts;
|
||||
|
||||
public NoteBase.NoteJudgeType currentJudgeType;
|
||||
public BasePrefabsCollection basePrefabs;
|
||||
|
||||
public List<GameElement> elementList = new List<GameElement>();
|
||||
|
||||
public List<BaseElement_BM> elementList_BM = new List<BaseElement_BM>();
|
||||
public List<Submodule_BM> submoduleList_BM = new List<Submodule_BM>();
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
instance = this;
|
||||
projectManager = new ProjectManager();
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
|
||||
//CreateNew();
|
||||
projectManager.loadManager.Load("TestProject");
|
||||
AudioSource.PlayClipAtPoint(songInformation.song, Vector3.zero);
|
||||
|
||||
//currentJudgeType = NoteBase.NoteJudgeType.Perfect;
|
||||
|
||||
var f0 = ElementFolder.GenerateElement("Folder", Guid.NewGuid(), new List<string>(), true, null);
|
||||
var dis0 = Displacement.GenerateElement("Displacement-0",Guid.NewGuid(), new List<string>(),true, f0,
|
||||
new FlexibleFloat(),
|
||||
new FlexibleFloat(new List<AnimatedFloat>(){new (0,2,0,10, AnimationCurveType.Linear)}),
|
||||
new FlexibleFloat());
|
||||
var t0 = Track.GenerateElement("Track", Guid.NewGuid(), new List<string>(), true, f0);
|
||||
t0.trackPathSubmodule = new TrackPathSubmodule(t0, Track.TrackSpaceType.Linear,
|
||||
Track.TrackSamplingType.TimeDistributed, false);
|
||||
t0.trackTimeSubmodule = new TrackTimeSubmoduleMovable(t0, 0, 2, 1, AnimationCurveType.OutQuad);
|
||||
var pp0 = TrackPercentPoint.GenerateElement("TrackPercentPoint-0", Guid.NewGuid(), new List<string>(), true, t0,
|
||||
new FlexibleFloat(new List<AnimatedFloat>() { new(0, 2, 0, 1, AnimationCurveType.OutQuad) }));
|
||||
var tr0 = Trail.GenerateElement("Trail-0", Guid.NewGuid(), new List<string>(), true, pp0, 5);
|
||||
// t0.trackRendererSubmodule = new TrackRendererSubmoduleAutoOrient(t0);
|
||||
var p0 = PathNode.GenerateElement("PathNode-0", Guid.NewGuid(), new List<string>(), true, t0);
|
||||
p0.transformSubmodule = new TransformSubmodule(p0, new Vector3(-5, 5, 10), Vector3.forward, Vector3.one);
|
||||
p0.colorSubmodule = new ColorSubmodule(p0, Color.white);
|
||||
var p1 = PathNode.GenerateElement("PathNode-1", Guid.NewGuid(), new List<string>(), true, t0);
|
||||
p1.transformSubmodule = new TransformSubmodule(p1, new Vector3(5, -5, 10), Vector3.forward, Vector3.one);
|
||||
p1.colorSubmodule = new ColorSubmodule(p1, Color.red);
|
||||
var n0 = Tap.GenerateElement("Note-0", Guid.NewGuid(), new List<string>(), true, t0, 1f);
|
||||
var n0v = BasicNoteVisual.GenerateElement("Note-0-V", Guid.NewGuid(), new List<string>(), true, n0,
|
||||
"basic", "BasicNoteTap3D");
|
||||
|
||||
elementList.ForEach(e =>
|
||||
beatmapContainer.gameElementList.ForEach(gameElement =>
|
||||
{
|
||||
e.AfterInitialize();
|
||||
e.Refresh();
|
||||
if (gameElement is IHaveTransformSubmodule transformedElement)
|
||||
{
|
||||
transformedElement.SetTransformObserver();
|
||||
}
|
||||
|
||||
gameElement.AfterInitialize();
|
||||
gameElement.Refresh();
|
||||
});
|
||||
|
||||
elementList.ForEach(e =>
|
||||
{
|
||||
e.SaveBM();
|
||||
e.submoduleList.RemoveAll(s=>s == null);
|
||||
e.submoduleList.ForEach(s => s.SaveBM());
|
||||
});
|
||||
|
||||
//Save
|
||||
elementList.ForEach(x => elementList_BM.Add(x.matchedBM));
|
||||
elementList.ForEach(x => submoduleList_BM.AddRange(x.submoduleList.ConvertAll(s => s.matchedBM as Submodule_BM)));
|
||||
ES3.Save<List<Submodule_BM>>("submoduleList", submoduleList_BM);
|
||||
ES3.Save<List<BaseElement_BM>>("elementList", elementList_BM);
|
||||
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
songModule.songTime += Time.deltaTime;
|
||||
}
|
||||
|
||||
private void CreateNew()
|
||||
{
|
||||
projectManager.GenerateProject("TestProject");
|
||||
|
||||
var f0 = ElementFolder.GenerateElement("Folder", Guid.NewGuid(), new List<string>(), true, null);
|
||||
var dis0 = Displacement.GenerateElement("Displacement-0",Guid.NewGuid(), new List<string>(),true, f0,
|
||||
new FlexibleFloat(),
|
||||
new FlexibleFloat(new List<AnimatedFloat>(){new (0,2,0,10, AnimationCurveType.Linear)}),
|
||||
new FlexibleFloat());
|
||||
var t0 = Track.GenerateElement("Track", Guid.NewGuid(), new List<string>(), true, f0);
|
||||
t0.trackPathSubmodule = new TrackPathSubmodule(t0, Track.TrackSpaceType.Linear, Track.TrackSamplingType.TimeDistributed, false);
|
||||
t0.submoduleList.Add(t0.trackPathSubmodule);
|
||||
t0.trackTimeSubmodule = new TrackTimeSubmoduleMovable(t0, 0, 2, 1, AnimationCurveType.OutQuad);
|
||||
t0.submoduleList.Add(t0.trackTimeSubmodule);
|
||||
var pp0 = TrackPercentPoint.GenerateElement("TrackPercentPoint-0", Guid.NewGuid(), new List<string>(), true, t0,
|
||||
new FlexibleFloat(new List<AnimatedFloat>() { new(0, 2, 0, 1, AnimationCurveType.OutQuad) }));
|
||||
var tr0 = Trail.GenerateElement("Trail-0", Guid.NewGuid(), new List<string>(), true, pp0, 5);
|
||||
// t0.trackRendererSubmodule = new TrackRendererSubmoduleAutoOrient(t0);
|
||||
var p0 = PathNode.GenerateElement("PathNode-0", Guid.NewGuid(), new List<string>(), true, t0);
|
||||
p0.transformSubmodule = new TransformSubmodule(p0, new Vector3(-5, 5, 10), Vector3.zero, Vector3.one);
|
||||
p0.colorSubmodule = new ColorSubmodule(p0, Color.white);
|
||||
var p1 = PathNode.GenerateElement("PathNode-1", Guid.NewGuid(), new List<string>(), true, t0);
|
||||
p1.transformSubmodule = new TransformSubmodule(p1, new Vector3(5, -5, 10), Vector3.zero, Vector3.one);
|
||||
p1.colorSubmodule = new ColorSubmodule(p1, Color.red);
|
||||
var n0 = Tap.GenerateElement("Note-0", Guid.NewGuid(), new List<string>(), true, t0, 1f);
|
||||
var n0v = BasicNoteVisual.GenerateElement("Note-0-V", Guid.NewGuid(), new List<string>(), true, n0,
|
||||
"basic", "BasicNoteTap3D");
|
||||
|
||||
beatmapContainer.gameElementList.ForEach(e =>
|
||||
{
|
||||
e.AfterInitialize();
|
||||
e.Refresh();
|
||||
});
|
||||
|
||||
projectManager.saveManager.Save();
|
||||
projectManager.exportManager.Export();
|
||||
}
|
||||
}
|
||||
|
||||
public class SongModule
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Base/Manager/ProjectManager.cs.meta
Normal file
11
Assets/Scripts/Base/Manager/ProjectManager.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: eaac9d0bf222646fc89d03493f9fca69
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user