From a99d5c8d9387eb4ded9fc6e1c165455fb659300d Mon Sep 17 00:00:00 2001 From: Anton Franzluebbers Date: Wed, 23 Aug 2023 14:56:42 -0400 Subject: [PATCH] add revert as well as undo --- .../VelNetUnity/Runtime/Util/UndoGroup.cs | 24 ++++++++++++++++++- .../Packages/VelNetUnity/package.json | 2 +- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/TestVelGameServer/Packages/VelNetUnity/Runtime/Util/UndoGroup.cs b/TestVelGameServer/Packages/VelNetUnity/Runtime/Util/UndoGroup.cs index 23e76d7..b3100b7 100644 --- a/TestVelGameServer/Packages/VelNetUnity/Runtime/Util/UndoGroup.cs +++ b/TestVelGameServer/Packages/VelNetUnity/Runtime/Util/UndoGroup.cs @@ -21,7 +21,7 @@ namespace VelNet /// - /// 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 /// public void Undo() { @@ -43,6 +43,28 @@ namespace VelNet } } + /// + /// Reset to the last UndoState. This only takes ownership if the IPackState component is also a NetworkComponent + /// + 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() { byte[][] states = new byte[objects.Count][]; diff --git a/TestVelGameServer/Packages/VelNetUnity/package.json b/TestVelGameServer/Packages/VelNetUnity/package.json index ad1b159..8fd0fb7 100644 --- a/TestVelGameServer/Packages/VelNetUnity/package.json +++ b/TestVelGameServer/Packages/VelNetUnity/package.json @@ -1,7 +1,7 @@ { "name": "edu.uga.engr.vel.velnet", "displayName": "VelNet", - "version": "1.2.2", + "version": "1.2.3", "unity": "2019.1", "description": "A custom networking library for Unity.", "keywords": [