I have an object called Unit
. Unit
has 2 member functions
void MoveTo(int x, int y)
void Attack(Unit enemyUnit)
Now, I would like to implement some sort of system to be able to track and recreate the functions of the Unit
on a different machine. So if a Unit makes following actions
1. MoveTo xy
2. Attack z
3. MoveTo ab
I would ideally like to store these function calls (together with their arguments) into some
List<(Action,Arguments)> executedActions
serialize the executedActions
into JSON and then on the other side I would deserialize.
However I've read that it is NOT good idea to serialize functions, delegates and actions, but rather that some sort of system of Dictionary<string, Action>
would be ideal, with string
being the actionName
being the key (example). So I would have to have a List<ActionName, Arguments>
and than on the reciever side I would use dict[ActionName]
to get the Action
.
Since I have a lot of different functions this seems a bit cumbersome (because they all have different parameters) and redundant. I would have to have several dictionaries because of different arguments problem.
Is there some sort of simpler way ? Or is the dictionary way the proper way ?