Esempio n. 1
0
    public static byte[] Serialize(this Vector3 v)
    {
        byte[] mem = new byte[4 * 3],
        xBin = BitConverterFloat.HostToNetworkOrder(v.x),
        yBin = BitConverterFloat.HostToNetworkOrder(v.y),
        zBin = BitConverterFloat.HostToNetworkOrder(v.z);

        xBin.CopyTo(mem, 0);
        yBin.CopyTo(mem, 4);
        zBin.CopyTo(mem, 8);

        return(mem);
    }
Esempio n. 2
0
    public static HitInfo Deserialize(byte[] bin)
    {
        HitInfo data = new HitInfo();

        data.team = (Team)BitConverter.ToChar(bin, 0);
        data.teammateHealthDelta = BitConverterFloat.NetworkToHostOrder(bin, 1);
        data.enemyHealthDelta    = BitConverterFloat.NetworkToHostOrder(bin, 5);
        data.teammateKnockback   = BitConverterFloat.NetworkToHostOrder(bin, 9);
        data.enemyKnockback      = BitConverterFloat.NetworkToHostOrder(bin, 13);
        data.senderId            = IPAddress.NetworkToHostOrder(BitConverter.ToInt32(bin, 17));
        data.direction           = Vector3.zero;
        data.direction.Deserialize(bin.Skip(21).ToArray());

        return(data);
    }
Esempio n. 3
0
    public byte[] Serialize()
    {
        byte[] mem = new byte[4 * 8 + 1],
        teamBin = BitConverter.GetBytes((byte)team),
        teammateHealthDeltaBin = BitConverterFloat.HostToNetworkOrder(teammateHealthDelta),
        enemyHealthDeltaBin    = BitConverterFloat.HostToNetworkOrder(enemyHealthDelta),
        teammateKnockbackBin   = BitConverterFloat.HostToNetworkOrder(teammateKnockback),
        enemyKnockbackBin      = BitConverterFloat.HostToNetworkOrder(enemyKnockback),
        senderIdBin            = BitConverter.GetBytes(IPAddress.HostToNetworkOrder(senderId)),
        directionBin           = direction.Serialize();

        teamBin.CopyTo(mem, 0);
        teammateHealthDeltaBin.CopyTo(mem, 1);
        enemyHealthDeltaBin.CopyTo(mem, 5);
        teammateKnockbackBin.CopyTo(mem, 9);
        enemyKnockbackBin.CopyTo(mem, 13);
        senderIdBin.CopyTo(mem, 17);
        directionBin.CopyTo(mem, 21);

        return(mem);
    }
Esempio n. 4
0
 public static void Deserialize(this Vector3 v, byte[] bin)
 {
     v.x = BitConverterFloat.NetworkToHostOrder(bin, 0);
     v.y = BitConverterFloat.NetworkToHostOrder(bin, 4);
     v.z = BitConverterFloat.NetworkToHostOrder(bin, 8);
 }