Files
ichni_Creator_Studio/Assets/Scripts/Manager/OperationManager.cs

146 lines
5.0 KiB
C#
Raw Normal View History

2025-02-19 09:15:51 -05:00
using System.Collections;
using System.Collections.Generic;
2025-02-19 19:01:21 -05:00
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-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-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-04-02 18:18:25 -04:00
public void AddSelectElement(GameElement gameElement)
2025-02-19 19:01:21 -05:00
{
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)
{
gameElement.connectedTab.BgImage.color = new Color(0.5f, 0.5f, 0.5f, 0.2f);
}
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)
{
currentSelectedElements.Remove(gameElement);
2025-04-13 14:04:17 +08:00
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()
{
currentSelectedElements.ForEach(gameElement =>
{
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();
}
}
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-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;
public List<GameElement> pastedElementList;
2025-02-19 19:01:21 -05:00
public void CopyElement(GameElement gameElement)
{
LogWindow.Log("Copied element: " + gameElement.elementName);
copiedElement = gameElement;
}
2025-02-19 19:01:21 -05:00
public void PasteElement(GameElement parentElement)
{
if (copiedElement == null)
{
LogWindow.Log("No element copied.");
return;
}
2025-02-19 19:01:21 -05:00
LogWindow.Log("Pasted element: " + copiedElement.elementName + " to " + parentElement.elementName);
pastedElementList = new List<GameElement>();
2025-02-19 19:01:21 -05:00
AffiliatedPaste(copiedElement, parentElement);
}
2025-02-19 19:06:26 -05:00
public void DeleteElement(GameElement gameElement)
{
LogWindow.Log("Deleted element: " + gameElement.elementName + " and all its children.");
2025-02-19 19:06:26 -05:00
if (gameElement.parentElement != null)
{
2025-02-20 19:36:49 -05:00
gameElement.parentElement.childElementList.Remove(gameElement); //从父物体的子物体列表中移除避免报null
gameElement.parentElement.connectedTab.childTabList.Remove(gameElement.connectedTab);
2025-04-13 14:04:17 +08:00
gameElement.parentElement.connectedTab.SetStatus();
2025-02-19 19:06:26 -05:00
}
gameElement.Delete();
}
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
{
gameElement.SaveBM();
GameElement pastedElement = (gameElement.matchedBM as GameElement_BM).DuplicateBM(parent);
pastedElementList.Add(pastedElement);
2025-02-19 19:01:21 -05:00
gameElement.submoduleList.ForEach(submodule =>
{
Debug.Log(submodule.GetType() + " is pasted.");
2025-02-19 19:01:21 -05:00
submodule.SaveBM();
2025-05-03 14:25:04 +08:00
try { (submodule.matchedBM as Submodule_BM).DuplicateBM(pastedElement); }
catch { Debug.LogWarning("Submodule paste error: " + submodule.GetType()); }
2025-02-19 19:01:21 -05:00
});
2025-02-19 19:01:21 -05:00
if (gameElement.childElementList != null)
{
for (int i = 0; i < gameElement.childElementList.Count; i++)
{
AffiliatedPaste(gameElement.childElementList[i], pastedElement);
}
}
}
2025-02-19 09:15:51 -05:00
}
2025-02-19 19:01:21 -05:00
}