Files
ichni_Creator_Studio/Assets/Scripts/Manager/OperationManager.cs
SoulliesOfficial 3995beeb29 修复bug+清理
2026-05-23 09:43:16 -04:00

181 lines
6.3 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using Ichni.RhythmGame;
using Ichni.RhythmGame.Beatmap;
using UnityEngine;
using UnityEngine.InputSystem;
namespace Ichni.Editor
{
public class OperationManager
{
public List<GameElement> currentSelectedElements { get; private set; }
public TempOutlineModule TempOutlineModule = new TempOutlineModule();
public CopyPasteDeleteModule CopyPasteDeleteModule;
public FindingModule FindingModule;
public OperationManager()
{
currentSelectedElements = new List<GameElement>();
CopyPasteDeleteModule = new CopyPasteDeleteModule();
FindingModule = new FindingModule();
}
public void AddSelectElement(GameElement gameElement)
{
currentSelectedElements.Add(gameElement);
gameElement.connectedTab.isSelected = true;
if (gameElement.connectedTab.BgImage != null)
{
gameElement.connectedTab.BgImage.color = new Color(0f, 0f, 0f, 0.8f);
}
}
public void RemoveSelectElement(GameElement gameElement)
{
currentSelectedElements.Remove(gameElement);
gameElement.connectedTab.isSelected = false;
if (gameElement.connectedTab.BgImage != null)
{
gameElement.connectedTab.BgImage.color = new Color(0.5f, 0.5f, 0.5f, 0);
}
}
public void ClearSelectedElements()
{
currentSelectedElements.ForEach(gameElement =>
{
if (gameElement == null || gameElement.connectedTab == null) return;
gameElement.connectedTab.isSelected = false;
if (gameElement.connectedTab.BgImage != null)
{
gameElement.connectedTab.BgImage.color = new Color(0.5f, 0.5f, 0.5f, 0);
}
});
currentSelectedElements.Clear();
}
}
public class TempOutlineModule
{
public List<GameElement> outlinedElements;
public Material outlineMaterial => EditorManager.instance.basePrefabs.outlineShaderMaterial;
public TempOutlineModule()
{
outlinedElements = new List<GameElement>();
}
public void AddOutline(GameElement gameElement)
{
outlinedElements.Add(gameElement);
}
public void RemoveOutline(GameElement gameElement)
{
outlinedElements.Remove(gameElement);
}
public void ClearOutline()
{
outlinedElements.Clear();
}
}
public class FindingModule
{
public GameElement FindGameElementByName(string elementName)
{
foreach (GameElement element in EditorManager.instance.beatmapContainer.gameElementList)
{
if (element.elementName == elementName)
{
return element;
}
}
LogWindow.Log("Element not found: " + elementName, Color.red);
return null;
}
}
public class CopyPasteDeleteModule
{
public GameElement copiedElement;
public List<GameElement> pastedElementList;
public void CopyElement(GameElement gameElement)
{
LogWindow.Log("Copied element: " + gameElement.elementName);
copiedElement = gameElement;
}
public void PasteElement(GameElement parentElement)
{
if (copiedElement == null)
{
LogWindow.Log("No element copied.");
return;
}
LogWindow.Log("Pasted element: " + copiedElement.elementName + " to " + parentElement.elementName);
pastedElementList = new List<GameElement>();
AffiliatedPaste(copiedElement, parentElement);
// 粘贴完成后,对所有新生成的元素执行 AfterInitialize 和 Refresh
// 与 EditorManager.LoadProject 的加载后流程对齐,确保 Manager 注册等关键步骤不遗漏。
foreach (GameElement pasted in pastedElementList)
{
pasted.AfterInitialize();
pasted.Refresh();
}
}
public void DeleteElement(GameElement gameElement)
{
LogWindow.Log("Deleted element: " + gameElement.elementName + " and all its children.");
if (gameElement.parentElement != null)
{
gameElement.parentElement.childElementList.Remove(gameElement); //从父物体的子物体列表中移除避免报null
gameElement.parentElement.connectedTab.childTabList.Remove(gameElement.connectedTab);
gameElement.parentElement.connectedTab.SetStatus();
}
gameElement.Delete();
EditorManager.instance.uiManager.inspector.ClearInspector();
}
/// <summary>
/// 使用递归的方式复制粘贴物体及其所有子物体
/// </summary>
/// <param name="gameElement">将要被粘贴的物体</param>
/// <param name="parent">(将要)被粘贴物体的父物体</param>
/// <returns></returns>
private void AffiliatedPaste(GameElement gameElement, GameElement parent)
{
gameElement.SaveBM();
GameElement pastedElement = (gameElement.matchedBM as GameElement_BM).DuplicateBM(parent);
pastedElementList.Add(pastedElement);
gameElement.submoduleList.ForEach(submodule =>
{
Debug.Log(submodule.GetType() + " is pasted.");
submodule.SaveBM();
try { (submodule.matchedBM as Submodule_BM).DuplicateBM(pastedElement); }
catch { Debug.LogWarning("Submodule paste error: " + submodule.GetType()); }
});
if (gameElement.childElementList != null)
{
foreach (GameElement Element in gameElement.childElementList.Where(x => !pastedElementList.Contains(x)))
{
AffiliatedPaste(Element, pastedElement);
}
}
}
}
}