Clip保存与读取
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using Ichni.Editor;
|
||||
using Ichni.RhythmGame;
|
||||
using Ichni.RhythmGame.Beatmap;
|
||||
@@ -28,18 +29,21 @@ namespace Ichni
|
||||
public SaveManager saveManager;
|
||||
public LoadManager loadManager;
|
||||
public ExportManager exportManager;
|
||||
public BeatmapClipManager beatmapClipManager;
|
||||
|
||||
public ProjectManager()
|
||||
{
|
||||
saveManager = new SaveManager();
|
||||
loadManager = new LoadManager();
|
||||
exportManager = new ExportManager();
|
||||
beatmapClipManager = new BeatmapClipManager();
|
||||
}
|
||||
|
||||
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.projectInformation = new ProjectInformation(projectName, "Soullies", "2.0",
|
||||
DateTime.Now.ToString(CultureInfo.CurrentCulture), DateTime.Now.ToString(CultureInfo.CurrentCulture),
|
||||
new List<string>());
|
||||
EditorManager.instance.songInformation = new SongInformation("TestSong", 120, 0);
|
||||
EditorManager.instance.beatmapContainer = new BeatmapContainer();
|
||||
EditorManager.instance.commandScripts = new CommandScripts(new List<string>());
|
||||
@@ -156,6 +160,7 @@ namespace Ichni
|
||||
{
|
||||
yield return new WaitForEndOfFrame();
|
||||
}
|
||||
|
||||
LoadBeatMap();
|
||||
LogWindow.Log("Load Complete", Color.green);
|
||||
}
|
||||
@@ -184,4 +189,101 @@ namespace Ichni
|
||||
ProjectManager.SaveSettings).ExecuteBM();
|
||||
}
|
||||
}
|
||||
|
||||
public class BeatmapClipManager
|
||||
{
|
||||
public void Save(string clipName)
|
||||
{
|
||||
LogWindow.Log("Start Saving Clip...");
|
||||
|
||||
GameElement selectedElement = EditorManager.instance.operationManager.currentSelectedElement;
|
||||
|
||||
if (selectedElement is not ElementFolder folder)
|
||||
{
|
||||
LogWindow.Log("Please select a folder to save the beatmap clip.", Color.red);
|
||||
return;
|
||||
}
|
||||
|
||||
SaveClip(folder, clipName);
|
||||
|
||||
LogWindow.Log("Save Clip Complete", Color.green);
|
||||
}
|
||||
|
||||
public void Load(string clipName)
|
||||
{
|
||||
LogWindow.Log("Start Loading Clip...");
|
||||
|
||||
if(!ES3.FileExists(Application.streamingAssetsPath + "/Clips/" + clipName + ".json"))
|
||||
{
|
||||
LogWindow.Log("Clip not found", Color.red);
|
||||
return;
|
||||
}
|
||||
|
||||
LoadClip(clipName);
|
||||
|
||||
LogWindow.Log("Load Clip Complete", Color.green);
|
||||
}
|
||||
|
||||
public void SaveClip(ElementFolder folder, string clipName)
|
||||
{
|
||||
List<BaseElement_BM> clip = new List<BaseElement_BM>();
|
||||
|
||||
folder.SaveBM();
|
||||
folder.matchedBM.attachedElementGuid = Guid.Empty;
|
||||
clip.Add(folder.matchedBM);
|
||||
folder.submoduleList.ForEach(s =>
|
||||
{
|
||||
s.SaveBM();
|
||||
clip.Add(s.matchedBM);
|
||||
});
|
||||
|
||||
folder.GetAllGameElementsFromThis(false).ForEach(e =>
|
||||
{
|
||||
e.SaveBM();
|
||||
clip.Add(e.matchedBM);
|
||||
e.submoduleList.ForEach(s =>
|
||||
{
|
||||
s.SaveBM();
|
||||
clip.Add(s.matchedBM);
|
||||
});
|
||||
});
|
||||
|
||||
string filePath = Application.streamingAssetsPath + "/Clips/" + clipName + ".json";
|
||||
ES3.Save("Clip", clip, filePath, ProjectManager.SaveSettings);
|
||||
}
|
||||
|
||||
public void LoadClip(string clipName)
|
||||
{
|
||||
List<BaseElement_BM> GetAllAttachedBaseElements(GameElement_BM gameElement, List<BaseElement_BM> clip)
|
||||
{
|
||||
Guid elementGuid = gameElement.elementGuid;
|
||||
List<BaseElement_BM> result = new List<BaseElement_BM>();
|
||||
foreach (BaseElement_BM element in clip)
|
||||
{
|
||||
if (element.attachedElementGuid == elementGuid)
|
||||
{
|
||||
result.Add(element);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
string filePath = Application.streamingAssetsPath + "/Clips/" + clipName + ".json";
|
||||
List<BaseElement_BM> clip = ES3.Load<List<BaseElement_BM>>("Clip", filePath, ProjectManager.SaveSettings);
|
||||
|
||||
foreach (BaseElement_BM element in clip)
|
||||
{
|
||||
if (element is GameElement_BM gameElement)
|
||||
{
|
||||
List<BaseElement_BM> attachedElements = GetAllAttachedBaseElements(gameElement, clip);
|
||||
gameElement.elementGuid = Guid.NewGuid();
|
||||
GameElement_BM.identifier.TryAdd(gameElement.elementGuid, gameElement);
|
||||
attachedElements.ForEach(e => { e.attachedElementGuid = gameElement.elementGuid; });
|
||||
}
|
||||
}
|
||||
|
||||
clip.ForEach(e => e.ExecuteBM());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user