2025-02-19 09:15:51 -05:00
|
|
|
|
using System.Collections;
|
2026-07-10 14:05:45 +08:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using Ichni.Editor.Commands;
|
|
|
|
|
|
using Ichni.RhythmGame;
|
|
|
|
|
|
using Ichni.RhythmGame.Beatmap;
|
2025-02-19 09:15:51 -05:00
|
|
|
|
using UnityEngine;
|
2025-04-16 08:33:34 -04:00
|
|
|
|
using UnityEngine.InputSystem;
|
2025-02-19 09:15:51 -05:00
|
|
|
|
|
2025-02-19 19:01:21 -05:00
|
|
|
|
namespace Ichni.Editor
|
2025-02-19 09:15:51 -05:00
|
|
|
|
{
|
2025-02-19 19:01:21 -05:00
|
|
|
|
public class OperationManager
|
2025-02-19 09:15:51 -05:00
|
|
|
|
{
|
2025-04-02 18:18:25 -04:00
|
|
|
|
public List<GameElement> currentSelectedElements { get; private set; }
|
2025-10-01 20:41:06 +08:00
|
|
|
|
public TempOutlineModule TempOutlineModule = new TempOutlineModule();
|
2025-02-19 19:06:26 -05:00
|
|
|
|
public CopyPasteDeleteModule CopyPasteDeleteModule;
|
2025-04-13 14:04:17 +08:00
|
|
|
|
|
2025-04-02 18:18:25 -04:00
|
|
|
|
public FindingModule FindingModule;
|
2025-03-30 11:18:37 +08:00
|
|
|
|
|
2025-02-19 19:01:21 -05:00
|
|
|
|
public OperationManager()
|
|
|
|
|
|
{
|
2025-04-02 18:18:25 -04:00
|
|
|
|
currentSelectedElements = new List<GameElement>();
|
2025-02-19 19:06:26 -05:00
|
|
|
|
CopyPasteDeleteModule = new CopyPasteDeleteModule();
|
2025-04-02 18:18:25 -04:00
|
|
|
|
FindingModule = new FindingModule();
|
2025-02-19 19:01:21 -05:00
|
|
|
|
}
|
2025-03-30 11:18:37 +08:00
|
|
|
|
|
2025-04-02 18:18:25 -04:00
|
|
|
|
public void AddSelectElement(GameElement gameElement)
|
2025-02-19 19:01:21 -05:00
|
|
|
|
{
|
2026-07-09 23:25:02 +08:00
|
|
|
|
if (gameElement == null || gameElement.connectedTab == null) return;
|
|
|
|
|
|
if (currentSelectedElements.Contains(gameElement)) return;
|
|
|
|
|
|
|
2025-04-02 18:18:25 -04:00
|
|
|
|
currentSelectedElements.Add(gameElement);
|
2025-04-13 14:04:17 +08:00
|
|
|
|
|
2025-04-02 18:18:25 -04:00
|
|
|
|
gameElement.connectedTab.isSelected = true;
|
2025-04-09 17:54:29 -04:00
|
|
|
|
if (gameElement.connectedTab.BgImage != null)
|
|
|
|
|
|
{
|
2025-05-11 14:12:47 +08:00
|
|
|
|
gameElement.connectedTab.BgImage.color = new Color(0f, 0f, 0f, 0.8f);
|
2025-04-09 17:54:29 -04:00
|
|
|
|
}
|
2025-04-02 18:18:25 -04:00
|
|
|
|
}
|
2025-04-13 14:04:17 +08:00
|
|
|
|
|
2025-04-02 18:18:25 -04:00
|
|
|
|
public void RemoveSelectElement(GameElement gameElement)
|
|
|
|
|
|
{
|
2026-07-09 23:25:02 +08:00
|
|
|
|
if (gameElement == null) return;
|
|
|
|
|
|
|
2025-04-02 18:18:25 -04:00
|
|
|
|
currentSelectedElements.Remove(gameElement);
|
2025-04-13 14:04:17 +08:00
|
|
|
|
|
2026-07-09 23:25:02 +08:00
|
|
|
|
if (gameElement.connectedTab == null) return;
|
|
|
|
|
|
|
2025-04-02 18:18:25 -04:00
|
|
|
|
gameElement.connectedTab.isSelected = false;
|
2025-04-09 17:54:29 -04:00
|
|
|
|
if (gameElement.connectedTab.BgImage != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
gameElement.connectedTab.BgImage.color = new Color(0.5f, 0.5f, 0.5f, 0);
|
|
|
|
|
|
}
|
2025-04-02 18:18:25 -04:00
|
|
|
|
}
|
2025-04-13 14:04:17 +08:00
|
|
|
|
|
2025-04-02 18:18:25 -04:00
|
|
|
|
public void ClearSelectedElements()
|
|
|
|
|
|
{
|
2026-07-09 23:25:02 +08:00
|
|
|
|
currentSelectedElements.RemoveAll(gameElement => gameElement == null);
|
2025-04-02 18:18:25 -04:00
|
|
|
|
currentSelectedElements.ForEach(gameElement =>
|
2025-02-20 15:25:42 +08:00
|
|
|
|
{
|
2026-05-02 22:10:19 +08:00
|
|
|
|
if (gameElement == null || gameElement.connectedTab == null) return;
|
2025-04-02 18:18:25 -04:00
|
|
|
|
gameElement.connectedTab.isSelected = false;
|
2025-04-09 17:54:29 -04:00
|
|
|
|
if (gameElement.connectedTab.BgImage != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
gameElement.connectedTab.BgImage.color = new Color(0.5f, 0.5f, 0.5f, 0);
|
|
|
|
|
|
}
|
2025-04-02 18:18:25 -04:00
|
|
|
|
});
|
2025-04-13 14:04:17 +08:00
|
|
|
|
|
2025-04-02 18:18:25 -04:00
|
|
|
|
currentSelectedElements.Clear();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-10-01 20:41:06 +08:00
|
|
|
|
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);
|
|
|
|
|
|
}
|
2025-04-02 18:18:25 -04:00
|
|
|
|
|
2025-10-01 20:41:06 +08:00
|
|
|
|
public void RemoveOutline(GameElement gameElement)
|
|
|
|
|
|
{
|
|
|
|
|
|
outlinedElements.Remove(gameElement);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void ClearOutline()
|
|
|
|
|
|
{
|
|
|
|
|
|
outlinedElements.Clear();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-04-02 18:18:25 -04:00
|
|
|
|
public class FindingModule
|
|
|
|
|
|
{
|
|
|
|
|
|
public GameElement FindGameElementByName(string elementName)
|
|
|
|
|
|
{
|
|
|
|
|
|
foreach (GameElement element in EditorManager.instance.beatmapContainer.gameElementList)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (element.elementName == elementName)
|
2025-03-20 19:30:42 -04:00
|
|
|
|
{
|
2025-04-02 18:18:25 -04:00
|
|
|
|
return element;
|
2025-03-20 19:30:42 -04:00
|
|
|
|
}
|
2025-02-20 15:25:42 +08:00
|
|
|
|
}
|
2025-04-13 14:04:17 +08:00
|
|
|
|
|
2025-04-02 18:18:25 -04:00
|
|
|
|
LogWindow.Log("Element not found: " + elementName, Color.red);
|
|
|
|
|
|
return null;
|
2025-02-19 19:01:21 -05:00
|
|
|
|
}
|
2025-02-19 09:15:51 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-02-19 19:06:26 -05:00
|
|
|
|
public class CopyPasteDeleteModule
|
2025-02-19 09:15:51 -05:00
|
|
|
|
{
|
2025-02-19 19:01:21 -05:00
|
|
|
|
public GameElement copiedElement;
|
2025-02-21 01:03:01 -05:00
|
|
|
|
public List<GameElement> pastedElementList;
|
|
|
|
|
|
|
2025-02-19 19:01:21 -05:00
|
|
|
|
public void CopyElement(GameElement gameElement)
|
|
|
|
|
|
{
|
2026-07-09 23:25:02 +08:00
|
|
|
|
if (gameElement == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
LogWindow.Log("No element selected to copy.", Color.red);
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-02-19 19:01:21 -05:00
|
|
|
|
LogWindow.Log("Copied element: " + gameElement.elementName);
|
|
|
|
|
|
copiedElement = gameElement;
|
|
|
|
|
|
}
|
2025-03-30 11:18:37 +08:00
|
|
|
|
|
2026-07-10 14:05:45 +08:00
|
|
|
|
public void PasteElement(GameElement parentElement)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (parentElement == null)
|
2026-07-09 23:25:02 +08:00
|
|
|
|
{
|
|
|
|
|
|
LogWindow.Log("No parent element selected to paste.", Color.red);
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-02-19 19:01:21 -05:00
|
|
|
|
if (copiedElement == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
LogWindow.Log("No element copied.");
|
2026-07-10 14:05:45 +08:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
CommandManager.ExecuteCommand(new PasteElementCommand(this, copiedElement, parentElement));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public GameElement PasteElementRaw(GameElement sourceElement, GameElement parentElement)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (sourceElement == null || parentElement == null) return null;
|
|
|
|
|
|
|
|
|
|
|
|
LogWindow.Log("Pasted element: " + sourceElement.elementName + " to " + parentElement.elementName);
|
|
|
|
|
|
pastedElementList = new List<GameElement>();
|
|
|
|
|
|
AffiliatedPaste(sourceElement, parentElement);
|
|
|
|
|
|
|
|
|
|
|
|
// 粘贴完成后,对所有新生成的元素执行 AfterInitialize 和 Refresh,
|
|
|
|
|
|
// 与 EditorManager.LoadProject 的加载后流程对齐,确保 Manager 注册等关键步骤不遗漏。
|
2026-05-23 09:43:16 -04:00
|
|
|
|
foreach (GameElement pasted in pastedElementList)
|
|
|
|
|
|
{
|
2026-07-09 23:25:02 +08:00
|
|
|
|
if (pasted == null) continue;
|
2026-07-10 14:05:45 +08:00
|
|
|
|
pasted.AfterInitialize();
|
|
|
|
|
|
pasted.Refresh();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return pastedElementList.FirstOrDefault();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void DeleteElement(GameElement gameElement)
|
2025-02-19 19:06:26 -05:00
|
|
|
|
{
|
2026-07-09 23:25:02 +08:00
|
|
|
|
if (gameElement == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
LogWindow.Log("No element selected to delete.", Color.red);
|
2026-07-10 14:05:45 +08:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
CommandManager.ExecuteCommand(new DeleteElementCommand(gameElement));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void DeleteElementRaw(GameElement gameElement, bool writeLog = true)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (gameElement == null) return;
|
|
|
|
|
|
|
|
|
|
|
|
var deletedElements = gameElement.GetAllGameElementsFromThis();
|
|
|
|
|
|
var deletedGuids = deletedElements.Select(element => element.elementGuid).ToList();
|
|
|
|
|
|
var deletedTabs = deletedElements
|
|
|
|
|
|
.Select(element => element.connectedTab)
|
|
|
|
|
|
.Where(tab => tab != null)
|
|
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
|
|
|
|
if (writeLog)
|
|
|
|
|
|
LogWindow.Log("Deleted element: " + gameElement.elementName + " and all its children.");
|
|
|
|
|
|
|
|
|
|
|
|
if (gameElement.parentElement != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
gameElement.parentElement.childElementList.Remove(gameElement); //从父物体的子物体列表中移除,避免报null
|
|
|
|
|
|
if (gameElement.parentElement.connectedTab != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
gameElement.parentElement.connectedTab.childTabList.Remove(gameElement.connectedTab);
|
|
|
|
|
|
gameElement.parentElement.connectedTab.SetStatus();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
EditorManager.instance.operationManager.RemoveSelectElement(gameElement);
|
|
|
|
|
|
gameElement.Delete();
|
|
|
|
|
|
deletedGuids.ForEach(guid => GameElement_BM.identifier.Remove(guid));
|
|
|
|
|
|
deletedTabs.ForEach(tab => EditorManager.instance.uiManager.hierarchy.tabList.Remove(tab));
|
|
|
|
|
|
EditorManager.instance.uiManager.inspector.ClearInspector();
|
|
|
|
|
|
}
|
2025-03-30 11:18:37 +08:00
|
|
|
|
|
2025-02-20 19:36:49 -05:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 使用递归的方式复制粘贴物体及其所有子物体
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="gameElement">将要被粘贴的物体</param>
|
|
|
|
|
|
/// <param name="parent">(将要)被粘贴物体的父物体</param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
private void AffiliatedPaste(GameElement gameElement, GameElement parent)
|
2025-02-19 19:01:21 -05:00
|
|
|
|
{
|
2026-07-09 23:25:02 +08:00
|
|
|
|
if (gameElement == null || parent == null) return;
|
|
|
|
|
|
|
2025-02-19 19:01:21 -05:00
|
|
|
|
gameElement.SaveBM();
|
2026-07-09 23:25:02 +08:00
|
|
|
|
if (gameElement.matchedBM is not GameElement_BM gameElementBM)
|
|
|
|
|
|
{
|
|
|
|
|
|
LogWindow.Log("Paste failed: " + gameElement.elementName + " did not create a valid BM.", Color.red);
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2025-02-19 19:01:21 -05:00
|
|
|
|
|
2026-07-09 23:25:02 +08:00
|
|
|
|
GameElement pastedElement = gameElementBM.DuplicateBM(parent);
|
|
|
|
|
|
if (pastedElement == null)
|
2025-02-19 19:01:21 -05:00
|
|
|
|
{
|
2026-07-09 23:25:02 +08:00
|
|
|
|
LogWindow.Log("Paste failed: " + gameElement.elementName + " could not be duplicated.", Color.red);
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pastedElementList.Add(pastedElement);
|
|
|
|
|
|
|
|
|
|
|
|
gameElement.submoduleList.ForEach(submodule =>
|
|
|
|
|
|
{
|
|
|
|
|
|
if (submodule == null) return;
|
|
|
|
|
|
Debug.Log(submodule.GetType() + " is pasted.");
|
|
|
|
|
|
submodule.SaveBM();
|
|
|
|
|
|
if (submodule.matchedBM is not Submodule_BM submoduleBM) return;
|
|
|
|
|
|
|
|
|
|
|
|
SubmoduleBase existingSubmodule = pastedElement.submoduleList
|
|
|
|
|
|
.FirstOrDefault(pastedSubmodule => pastedSubmodule != null && pastedSubmodule.GetType() == submodule.GetType());
|
|
|
|
|
|
existingSubmodule?.Delete();
|
|
|
|
|
|
|
|
|
|
|
|
try { submoduleBM.DuplicateBM(pastedElement); }
|
|
|
|
|
|
catch { Debug.LogWarning("Submodule paste error: " + submodule.GetType()); }
|
|
|
|
|
|
});
|
2025-03-30 11:18:37 +08:00
|
|
|
|
|
2025-02-19 19:01:21 -05:00
|
|
|
|
if (gameElement.childElementList != null)
|
|
|
|
|
|
{
|
2025-05-04 14:09:02 +08:00
|
|
|
|
foreach (GameElement Element in gameElement.childElementList.Where(x => !pastedElementList.Contains(x)))
|
2025-02-19 19:01:21 -05:00
|
|
|
|
{
|
2025-05-04 14:09:02 +08:00
|
|
|
|
AffiliatedPaste(Element, pastedElement);
|
2025-02-19 19:01:21 -05:00
|
|
|
|
}
|
2025-05-04 14:09:02 +08:00
|
|
|
|
|
2025-02-19 19:01:21 -05:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-02-19 09:15:51 -05:00
|
|
|
|
}
|
2026-07-09 23:25:02 +08:00
|
|
|
|
}
|