#nullable enable using UnityEngine; using UVC.UI.Commands; using UVC.Studio.Manager; using UVC.Studio.Config; namespace UVC.Studio.Command { /// /// 평면 생성 커맨드 (Undo/Redo 지원) /// public class EditCreatePlaneCommand : IUndoableCommand { public string Description => "평면 생성"; private readonly StageObjectManager _stageObjectManager; // Undo용 상태 저장 private string? _createdStageObjectId; private GameObject? _createdPlane; private Vector3 _position; private Vector3 _scale; public EditCreatePlaneCommand(StageObjectManager stageObjectManager) { _stageObjectManager = stageObjectManager; } public void Execute(object? parameter = null) { // 평면 생성 _createdPlane = GameObject.CreatePrimitive(PrimitiveType.Plane); _createdPlane.name = "Plane"; // 기본 위치 설정 _position = Vector3.zero; _scale = Vector3.one; _createdPlane.transform.position = _position; _createdPlane.transform.localScale = _scale; // Plane용 Equipment 생성 (기본 프리미티브) var planeEquipment = new EquipmentItem { id = "primitive_plane", label = "Plane" }; // StageObjectManager에 등록 var stageObject = _stageObjectManager.Register(planeEquipment, _createdPlane); _createdStageObjectId = stageObject.Id; Debug.Log($"[EditCreatePlaneCommand] 평면 생성됨: {_createdStageObjectId}"); } public void Undo(object? parameter = null) { if (_createdStageObjectId != null) { _stageObjectManager.Unregister(_createdStageObjectId); _createdPlane = null; Debug.Log($"[EditCreatePlaneCommand] Undo: 평면 삭제됨"); } } public void Redo() { // 평면 다시 생성 _createdPlane = GameObject.CreatePrimitive(PrimitiveType.Plane); _createdPlane.name = "Plane"; _createdPlane.transform.position = _position; _createdPlane.transform.localScale = _scale; var planeEquipment = new EquipmentItem { id = "primitive_plane", label = "Plane" }; var stageObject = _stageObjectManager.Register(planeEquipment, _createdPlane); _createdStageObjectId = stageObject.Id; Debug.Log($"[EditCreatePlaneCommand] Redo: 평면 다시 생성됨: {_createdStageObjectId}"); } public bool CanMerge(IUndoableCommand other) => false; public void Merge(IUndoableCommand other) { } } }