Files
JuegoSim/Assets/_Project/Scripts/Code/CommandLayer/Commands/RotateBlockCommand.cs
T
2026-07-21 08:56:10 +03:00

58 lines
1.6 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class RotateblockCommand : ICommand
{
private string blockId;
private Quaternion newRotation;
private Quaternion previousRotation;
private Environment environment;
private Transform blockTransform;
public RotateblockCommand(string blockId, Quaternion newRotation)
{
this.blockId = blockId;
this.newRotation = newRotation;
this.environment = Environment.getInstance();
}
public RotateblockCommand(CommandDTO commandDTO)
{
this.blockId = commandDTO.Parameters["blockId"].ToString();
this.newRotation = (Quaternion)commandDTO.Parameters["newRotation"];
this.environment = Environment.getInstance();
}
public void execute()
{
blockTransform = environment.getBlock(blockId)?.transform;
if (blockTransform != null)
{
previousRotation = blockTransform.rotation;
blockTransform.rotation = newRotation;
}
else
{
Debug.LogWarning("RotateblockCommand: block with ID " + blockId + " not found.");
}
}
public void undo()
{
blockTransform = environment.getBlock(blockId)?.transform;
if (blockTransform != null)
{
blockTransform.rotation = previousRotation;
}
}
public CommandDTO toDTO()
{
return new CommandDTO.CommandDTOBuilder()
.SetCommandName("RotateCommand")
.AddParameter("blockId", blockId)
.AddParameter("newRotation", newRotation)
.Build();
}
}