Files
ichni_Creator_Studio/Assets/Scripts/Manager/OperationManager.cs
TRAfoer 30fab16eed sth
做了点功能
bug在冰花那张谱里
2025-03-30 11:18:37 +08:00

102 lines
3.6 KiB
C#
Raw 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 Ichni.RhythmGame;
using Ichni.RhythmGame.Beatmap;
using UnityEngine;
namespace Ichni.Editor
{
public class OperationManager
{
public GameElement currentSelectedElement { get; private set; }
public CopyPasteDeleteModule CopyPasteDeleteModule;
public OperationManager()
{
CopyPasteDeleteModule = new CopyPasteDeleteModule();
}
public void SelectElement(GameElement gameElement)
{
if (currentSelectedElement != null)
{
currentSelectedElement.connectedTab.isSelected = false;
if (currentSelectedElement.connectedTab.BgImage != null)
{
currentSelectedElement.connectedTab.BgImage.color = new Color(0.5f, 0.5f, 0.5f, 0);
}
}
currentSelectedElement = gameElement;
currentSelectedElement.connectedTab.isSelected = true;
currentSelectedElement.connectedTab.BgImage.color = new Color(0.5f, 0.5f, 0.5f, 0.2f);
}
}
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);
}
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.Delete();
}
/// <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();
(submodule.matchedBM as Submodule_BM).DuplicateBM(pastedElement);
});
if (gameElement.childElementList != null)
{
for (int i = 0; i < gameElement.childElementList.Count; i++)
{
AffiliatedPaste(gameElement.childElementList[i], pastedElement);
}
}
}
}
}