Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class EntityAction {
- public int actorID;
- public enum actionType { Movement, Skill }
- public int actorAction;
- public List<int> arguments;
- public static void Register() {
- MonoBehaviour.print("Registering EntityAction Serialization: " + PhotonPeer.RegisterType(typeof(EntityAction), (byte)'E', EntityAction.SerializeEntityAction, EntityAction.DeserializeEntityAction));
- }
- public EntityAction() {
- arguments = new List<int>();
- }
- private static short SerializeEntityAction(StreamBuffer outStream, object customobject)
- {
- BinaryFormatter format = new BinaryFormatter();
- MemoryStream argBytes = new MemoryStream();
- EntityAction o = (EntityAction)customobject;
- format.Serialize(argBytes, o.arguments);
- byte[] bytes = new byte[argBytes.Length + sizeof(int)*4];
- int objectSize = (int)argBytes.Length + sizeof(int)*3;
- int index = 0;
- Protocol.Serialize(objectSize, bytes, ref index);
- Protocol.Serialize(o.actorID, bytes, ref index);
- Protocol.Serialize(o.actorAction, bytes, ref index);
- Protocol.Serialize((int)argBytes.Length, bytes, ref index);
- argBytes.ToArray().CopyTo(bytes, index);
- index += (int)argBytes.Length;
- outStream.Write(bytes, 0, (int)bytes.Length);
- return (short)index;
- }
- private static object DeserializeEntityAction(StreamBuffer inStream, short length)
- {
- BinaryFormatter format = new BinaryFormatter();
- MemoryStream argBytes = new MemoryStream();
- EntityAction o = new EntityAction();
- int index = 0;
- int argBytesLength;
- int objSize;
- byte[] objBuf = new byte[sizeof(int)]; // Create a buffer to read in a single int.
- inStream.Read(objBuf, 0, sizeof(int)); // Read in one int worth of bytes
- Protocol.Deserialize(out objSize, objBuf, ref index); // Deserialize that int as the size of the whole remaining object
- byte[] mem = new byte[objSize]; // Read in that object
- inStream.Read(mem, 0, objSize); //
- index = 0;
- Protocol.Deserialize(out o.actorID, mem, ref index);
- Protocol.Deserialize(out o.actorAction, mem, ref index);
- Protocol.Deserialize(out argBytesLength, mem, ref index);
- byte[] argArray = new byte[argBytesLength]; // Create a buffer the size of the list
- Array.Copy(mem, index, argArray, 0, argBytesLength); // Copy the memory representing the list into that buffer
- argBytes.Write(argArray, 0, argBytesLength); // Write that buffer into the memory stream to be deserialized
- argBytes.Position = 0;
- if(argBytes.Length == 0) o.arguments = new List<int>();
- else o.arguments = format.Deserialize(argBytes) as List<int>;
- return o;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement