Note Prefab功能
This commit is contained in:
@@ -31,6 +31,7 @@ namespace Ichni
|
||||
public LoadManager loadManager;
|
||||
public ExportManager exportManager;
|
||||
public BeatmapClipManager beatmapClipManager;
|
||||
public NotePrefabManager notePrefabManager;
|
||||
public AutoSaveManager autoSaveManager;
|
||||
|
||||
public ProjectManager()
|
||||
@@ -39,6 +40,7 @@ namespace Ichni
|
||||
loadManager = new LoadManager();
|
||||
exportManager = new ExportManager();
|
||||
beatmapClipManager = new BeatmapClipManager();
|
||||
notePrefabManager = new NotePrefabManager();
|
||||
autoSaveManager = new AutoSaveManager();
|
||||
}
|
||||
|
||||
@@ -245,27 +247,12 @@ namespace Ichni
|
||||
|
||||
private void _LoadClip(GameElement target, 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);
|
||||
|
||||
//对于第一个元素,需要特殊处理,将它放入目标物体的子物体列表中
|
||||
GameElement_BM first = clip[0] as GameElement_BM;
|
||||
List<BaseElement_BM> firstAttaches = GetAllAttachedBaseElements(first, clip);
|
||||
List<BaseElement_BM> firstAttaches = GameElement_BM.GetAllAttachedBaseElements(first, clip);
|
||||
first.elementGuid = Guid.NewGuid();
|
||||
GameElement_BM.identifier.TryAdd(first.elementGuid, first);
|
||||
firstAttaches.ForEach(e => { e.attachedElementGuid = first.elementGuid; });
|
||||
@@ -281,7 +268,7 @@ namespace Ichni
|
||||
var element = clip[index];
|
||||
if (element is GameElement_BM gameElement)
|
||||
{
|
||||
List<BaseElement_BM> attachedElements = GetAllAttachedBaseElements(gameElement, clip);
|
||||
List<BaseElement_BM> attachedElements = GameElement_BM.GetAllAttachedBaseElements(gameElement, clip);
|
||||
gameElement.elementGuid = Guid.NewGuid();
|
||||
GameElement_BM.identifier.TryAdd(gameElement.elementGuid, gameElement);
|
||||
attachedElements.ForEach(e => { e.attachedElementGuid = gameElement.elementGuid; });
|
||||
@@ -297,6 +284,68 @@ namespace Ichni
|
||||
}
|
||||
}
|
||||
|
||||
public class NotePrefabManager
|
||||
{
|
||||
private string notePrefabPath => Application.streamingAssetsPath + "/NotePrefabs";
|
||||
private string GetNotePrefabPath(string notePrefabName) => notePrefabPath + "/" + notePrefabName + ".json";
|
||||
|
||||
public void SaveNotePrefab(NoteBase note, string noteName)
|
||||
{
|
||||
List<BaseElement_BM> clip = new List<BaseElement_BM>();
|
||||
|
||||
note.GetAllGameElementsFromThis().ForEach(e =>
|
||||
{
|
||||
e.SaveBM();
|
||||
clip.Add(e.matchedBM);
|
||||
e.submoduleList.ForEach(s =>
|
||||
{
|
||||
s.SaveBM();
|
||||
clip.Add(s.matchedBM);
|
||||
});
|
||||
});
|
||||
|
||||
ES3.Save("Note", clip, GetNotePrefabPath(noteName), ProjectManager.SaveSettings);
|
||||
}
|
||||
|
||||
public void LoadNotePrefab(NoteBase target, string noteName)
|
||||
{
|
||||
List<BaseElement_BM> clip = ES3.Load<List<BaseElement_BM>>("Note", GetNotePrefabPath(noteName), ProjectManager.SaveSettings);
|
||||
|
||||
if (clip == null || clip.Count == 0)
|
||||
{
|
||||
LogWindow.Log("Note prefab not found", Color.red);
|
||||
return;
|
||||
}
|
||||
|
||||
target.SaveBM();
|
||||
GameElement_BM.identifier.TryAdd(target.elementGuid, target.matchedBM as GameElement_BM);
|
||||
(target.matchedBM as GameElement_BM).matchedElement = target;
|
||||
|
||||
GameElement_BM first = clip[0] as GameElement_BM;
|
||||
List<BaseElement_BM> firstAttaches = GameElement_BM.GetAllAttachedBaseElements(first, clip);
|
||||
first.elementGuid = target.elementGuid;
|
||||
GameElement_BM.identifier.TryAdd(first.elementGuid, first);
|
||||
firstAttaches.ForEach(e => { e.attachedElementGuid = first.elementGuid; });
|
||||
|
||||
for (var index = 1; index < clip.Count; index++)
|
||||
{
|
||||
var element = clip[index];
|
||||
if (element is GameElement_BM gameElement)
|
||||
{
|
||||
List<BaseElement_BM> attachedElements = GameElement_BM.GetAllAttachedBaseElements(gameElement, clip);
|
||||
gameElement.elementGuid = Guid.NewGuid();
|
||||
GameElement_BM.identifier.TryAdd(gameElement.elementGuid, gameElement);
|
||||
attachedElements.ForEach(e => { e.attachedElementGuid = gameElement.elementGuid; });
|
||||
}
|
||||
}
|
||||
|
||||
for (var index = 1; index < clip.Count; index++)
|
||||
{
|
||||
clip[index].ExecuteBM();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class AutoSaveManager
|
||||
{
|
||||
private string autoSavePath => Application.streamingAssetsPath + "/AutoSave/" +
|
||||
|
||||
Reference in New Issue
Block a user