@@ -285,7 +285,8 @@ namespace Ichni
|
||||
e.submoduleList.ForEach(s =>
|
||||
{
|
||||
s.SaveBM();
|
||||
clip.Add(s.matchedBM);
|
||||
if (s.matchedBM != null)
|
||||
clip.Add(s.matchedBM);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -295,41 +296,84 @@ namespace Ichni
|
||||
|
||||
private void _LoadClip(GameElement target, string clipName)
|
||||
{
|
||||
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 = GameElement_BM.GetAllAttachedBaseElements(first, clip);
|
||||
first.elementGuid = Guid.NewGuid();
|
||||
GameElement_BM.identifier.TryAdd(first.elementGuid, first);
|
||||
firstAttaches.ForEach(e => { e.attachedElementGuid = first.elementGuid; });
|
||||
|
||||
//将目标物体(临时)存入读存档的Dictionary中
|
||||
target.SaveBM();
|
||||
GameElement_BM.identifier.TryAdd(target.elementGuid, target.matchedBM as GameElement_BM);
|
||||
(target.matchedBM as GameElement_BM).matchedElement = target;
|
||||
first.attachedElementGuid = target.elementGuid;
|
||||
|
||||
for (var index = 1; index < clip.Count; index++)
|
||||
try
|
||||
{
|
||||
var element = clip[index];
|
||||
if (element is GameElement_BM gameElement)
|
||||
string filePath = Application.streamingAssetsPath + "/Clips/" + clipName + ".json";
|
||||
List<BaseElement_BM> clip = ES3.Load<List<BaseElement_BM>>("Clip", filePath, ProjectManager.SaveSettings);
|
||||
|
||||
if (clip == null || clip.Count == 0)
|
||||
{
|
||||
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; });
|
||||
Debug.LogError("Clip is empty or null");
|
||||
return;
|
||||
}
|
||||
|
||||
// 验证第一个元素
|
||||
if (!(clip[0] is GameElement_BM first))
|
||||
{
|
||||
Debug.LogError("First element is not a GameElement_BM");
|
||||
return;
|
||||
}
|
||||
|
||||
// 处理目标对象 - 添加清理机制
|
||||
target.SaveBM();
|
||||
bool targetAdded = GameElement_BM.identifier.TryAdd(target.elementGuid, target.matchedBM as GameElement_BM);
|
||||
if (!targetAdded)
|
||||
{
|
||||
Debug.LogWarning("Target element already exists in identifier dictionary");
|
||||
}
|
||||
|
||||
// 处理第一个元素及其附加元素
|
||||
ProcessGameElement(first, clip, target.elementGuid);
|
||||
|
||||
// 处理后续元素
|
||||
for (var index = 1; index < clip.Count; index++)
|
||||
{
|
||||
if (clip[index] is GameElement_BM gameElement)
|
||||
{
|
||||
ProcessGameElement(gameElement, clip, null);
|
||||
}
|
||||
else
|
||||
{
|
||||
// 非GameElement_BM直接执行
|
||||
clip[index].ExecuteBM();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
first.ExecuteBM();
|
||||
|
||||
for (var index = 1; index < clip.Count; index++)
|
||||
catch (Exception ex)
|
||||
{
|
||||
clip[index].ExecuteBM();
|
||||
Debug.LogError($"Failed to load clip: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
private void ProcessGameElement(GameElement_BM gameElement, List<BaseElement_BM> clip, Guid? attachToGuid)
|
||||
{
|
||||
List<BaseElement_BM> attachedElements = GameElement_BM.GetAllAttachedBaseElements(gameElement, clip);
|
||||
|
||||
// 生成新GUID并验证
|
||||
gameElement.elementGuid = Guid.NewGuid();
|
||||
bool elementAdded = GameElement_BM.identifier.TryAdd(gameElement.elementGuid, gameElement);
|
||||
if (!elementAdded)
|
||||
{
|
||||
Debug.LogError($"Failed to add element with GUID: {gameElement.elementGuid}");
|
||||
return;
|
||||
}
|
||||
|
||||
// 更新附加元素
|
||||
attachedElements.ForEach(e =>
|
||||
{
|
||||
e.attachedElementGuid = gameElement.elementGuid;
|
||||
});
|
||||
|
||||
// 如果需要附加到其他元素
|
||||
if (attachToGuid.HasValue)
|
||||
{
|
||||
gameElement.attachedElementGuid = attachToGuid.Value;
|
||||
}
|
||||
|
||||
gameElement.ExecuteBM();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public class BeatmapMergeManager
|
||||
|
||||
Reference in New Issue
Block a user