I'm using the Command Pattern to track movement for "replays" later. When I do this, the actions replay correctly, but slower. I have tried both coroutines and Update()
and the problem persists.
I first have an Invoker PlayerControl
that holds a list of ICommand
's.
//Properties
private List<ICommand> oldCommands = new List<ICommand>();
private int updateIterationTracker = 0;
For every invoked command, I add the command to the list.
//If Input moves up, invoke the move up command
if (dirVector.y > 0)
{
oldCommands.Add(dirUp); //Add the command to the list of commands
dirUp.Execute();
}
At some point a "replay" is triggered and I iterate through the commands in oldCommands
.
This functionality works. Just as move input does, triggering the command to move executes.
private void IterateUpdateOnReplay(){
if(iteration < oldCommands.Count){
transform.position = replayStartPosition;
}
oldCommands[iteration].Execute();
iteration++;
}
I have done this in a coroutine as well.
The playback may execute the movements in the correct order and the movements may occur, but the time it takes to execute the entire sequence is longer than the time it took at the initial recording. Playback is longer.
Questions:
1) Is the initial capture
oldCommands.Add(dirUp); //Add the command to the list of commands
adding too many commands to play back at the correct pace, slowed down by execution times?
2) Is there potentially another issue causing this delay that I am unaware of?
Aucun commentaire:
Enregistrer un commentaire