Which data structure to hold Array of Array (Unity Javascript) in Unity C#?

I have an array of array of message that I need to send to the server, Unfortunately, I need to code the server module on C#. So what I’m asking is which data structure should correspond to this data structure

My code is more or less as such:

//Javascript part on the game engine
var actionMsg1 : Array = new Array();
var actionMsg2 : Array = new Array();
var actionMsg3 : Array = new Array();

actionMsg1.Push("object A");
actionMsg1.Push("Move");
actionMsg1.Push("tile [2,2]");

actionMsg1.Push("object A");
actionMsg1.Push("shoot");
actionMsg1.Push("object B");

var arrMovementMsg : Array = new Array();
arrMovementMsg.Push(actionMsg1);
arrMovementMsg.Push(actionMsg1);

msgPacker.PackMessage(arrMovementMsg);

Now msgPacker’s clas is the class written in C#, so I’m confused how I’m gonna make the method signature for it? I definitely can’t make

public PackMessage(Array arrMovementMsg)

on the script, since C# doesn’t have Array class. So which data type should I use to correspond to the data type array in javascript? Do I have any other choice than reworking on the game engine’s message system so that It process an array of string? (

2 Answers

2

Google msdn csharp List

You could write

List<List<string>> lstMovementMsg = new List<List<string>>();
List<string> actionMsg = new List<string>();
actionMessage.Add("object A");
actionMessage.Add("shoot");
actionMessage.Add("object B");
lstMovementMsg.Add(actionMessage);

But if I were you I’d use another approach to pack messages and send them over the network. You should checkout the Network View from Unity and the RPC functioanlity that you can use.