add revert as well as undo

upm
Anton Franzluebbers 2023-08-23 14:56:42 -04:00
parent 4ba96b70a5
commit 593afca4d1
2 changed files with 24 additions and 2 deletions

View File

@ -21,7 +21,7 @@ namespace VelNet
/// <summary> /// <summary>
/// Reset to the last UndoState. This only takes ownership if the IPackState component is also a NetworkComponent /// Reset to the last UndoState and remove the state from history. This only takes ownership if the IPackState component is also a NetworkComponent
/// </summary> /// </summary>
public void Undo() public void Undo()
{ {
@ -43,6 +43,28 @@ namespace VelNet
} }
} }
/// <summary>
/// Reset to the last UndoState. This only takes ownership if the IPackState component is also a NetworkComponent
/// </summary>
public void Revert()
{
byte[][] lastStates = undoBuffer.LastOrDefault();
if (lastStates != null)
{
for (int i = 0; i < objects.Count; i++)
{
objects[i].networkObject.TakeOwnership();
objects[i].UnpackState(lastStates[i]);
}
if (debugLog) Debug.Log($"Revert {objects.Count} objects");
}
else
{
if (debugLog) Debug.Log($"No more undo to undo");
}
}
public void SaveUndoState() public void SaveUndoState()
{ {
byte[][] states = new byte[objects.Count][]; byte[][] states = new byte[objects.Count][];

View File

@ -1,7 +1,7 @@
{ {
"name": "edu.uga.engr.vel.velnet", "name": "edu.uga.engr.vel.velnet",
"displayName": "VelNet", "displayName": "VelNet",
"version": "1.2.2", "version": "1.2.3",
"unity": "2019.1", "unity": "2019.1",
"description": "A custom networking library for Unity.", "description": "A custom networking library for Unity.",
"keywords": [ "keywords": [