Exemplo n.º 1
0
    void Start()
    {
        udp.Initialize();

        //Initialize a publicly visible memory stream, that is writeable, so the buffer is accessible
        memoryStream = new MemoryStream(testData, 0, testData.Length, true, true);
        //MemoryStream.GetBuffer();
        //writer = new BinaryWriter(memoryStream);


        Icosahedra.IO.BinaryWriter.Int32ToBytes ib = new Icosahedra.IO.BinaryWriter.Int32ToBytes();
        ib.value = -13451345;
        byte[] a = System.BitConverter.GetBytes(ib.value);
        Debug.Log(a[0] + " : " + a[1] + " : " + a[2] + " : " + a[3]);
        Debug.Log(ib.byte0 + " : " + ib.byte1 + " : " + ib.byte2 + " : " + ib.byte3);

        Icosahedra.IO.BinaryWriter.FloatToBytes fb = new Icosahedra.IO.BinaryWriter.FloatToBytes();
        fb.value = -12341234234.1234f;
        a        = System.BitConverter.GetBytes(fb.value);
        Debug.Log(a[0] + " : " + a[1] + " : " + a[2] + " : " + a[3]);
        Debug.Log(fb.byte0 + " : " + fb.byte1 + " : " + fb.byte2 + " : " + fb.byte3);

        Icosahedra.IO.BinaryWriter.CharToBytes cb = new Icosahedra.IO.BinaryWriter.CharToBytes();
        cb.value = 'g';
        a        = System.BitConverter.GetBytes(cb.value);
        Debug.Log(a[0] + " : " + a[1]);
        Debug.Log(cb.byte0 + " : " + cb.byte1);


        Icosahedra.IO.BinaryWriter.Write("hello, world", testData, 0);


        //Debug.Log(System.BitConverter.IsLittleEndian);
    }
Exemplo n.º 2
0
    void SerializeBird()
    {
        networkedBird[0] = 1;        //birdState.Value;
        Icosahedra.IO.BinaryWriter.FloatToBytes converter = new Icosahedra.IO.BinaryWriter.FloatToBytes();

        converter.value  = pX.Value;
        networkedBird[1] = converter.byte0;
        networkedBird[2] = converter.byte1;
        networkedBird[3] = converter.byte2;
        networkedBird[4] = converter.byte3;

        converter.value  = pY.Value;
        networkedBird[5] = converter.byte0;
        networkedBird[6] = converter.byte1;
        networkedBird[7] = converter.byte2;
        networkedBird[8] = converter.byte3;

        converter.value   = pZ.Value;
        networkedBird[9]  = converter.byte0;
        networkedBird[10] = converter.byte1;
        networkedBird[11] = converter.byte2;
        networkedBird[12] = converter.byte3;

        converter.value   = rYaw.Value;
        networkedBird[13] = converter.byte0;
        networkedBird[14] = converter.byte1;
        networkedBird[15] = converter.byte2;
        networkedBird[16] = converter.byte3;

        converter.value   = rPitch.Value;
        networkedBird[17] = converter.byte0;
        networkedBird[18] = converter.byte1;
        networkedBird[19] = converter.byte2;
        networkedBird[20] = converter.byte3;

        converter.value   = rRoll.Value;
        networkedBird[21] = converter.byte0;
        networkedBird[22] = converter.byte1;
        networkedBird[23] = converter.byte2;
        networkedBird[24] = converter.byte3;

        converter.value   = vX.Value;
        networkedBird[25] = converter.byte0;
        networkedBird[26] = converter.byte1;
        networkedBird[27] = converter.byte2;
        networkedBird[28] = converter.byte3;

        converter.value   = vY.Value;
        networkedBird[29] = converter.byte0;
        networkedBird[30] = converter.byte1;
        networkedBird[31] = converter.byte2;
        networkedBird[32] = converter.byte3;

        converter.value   = vZ.Value;
        networkedBird[33] = converter.byte0;
        networkedBird[34] = converter.byte1;
        networkedBird[35] = converter.byte2;
        networkedBird[36] = converter.byte3;

        converter.value   = time.Value;
        networkedBird[37] = converter.byte0;
        networkedBird[38] = converter.byte1;
        networkedBird[39] = converter.byte2;
        networkedBird[40] = converter.byte3;

        converter.value   = lightingManager.dayPercent;
        networkedBird[41] = converter.byte0;
        networkedBird[42] = converter.byte1;
        networkedBird[43] = converter.byte2;
        networkedBird[44] = converter.byte3;
    }
Exemplo n.º 3
0
    void DeserializeBird()
    {
        birdState.Value = networkedBird[0];
        Icosahedra.IO.BinaryWriter.FloatToBytes converter = new Icosahedra.IO.BinaryWriter.FloatToBytes();


        converter.byte0 = networkedBird[1];
        converter.byte1 = networkedBird[2];
        converter.byte2 = networkedBird[3];
        converter.byte3 = networkedBird[4];
        pX.Value        = converter.value;

        converter.byte0 = networkedBird[5];
        converter.byte1 = networkedBird[6];
        converter.byte2 = networkedBird[7];
        converter.byte3 = networkedBird[8];
        pY.Value        = converter.value;

        converter.byte0 = networkedBird[9];
        converter.byte1 = networkedBird[10];
        converter.byte2 = networkedBird[11];
        converter.byte3 = networkedBird[12];
        pZ.Value        = converter.value;

        converter.byte0 = networkedBird[13];
        converter.byte1 = networkedBird[14];
        converter.byte2 = networkedBird[15];
        converter.byte3 = networkedBird[16];
        rYaw.Value      = converter.value;

        converter.byte0 = networkedBird[17];
        converter.byte1 = networkedBird[18];
        converter.byte2 = networkedBird[19];
        converter.byte3 = networkedBird[20];
        rPitch.Value    = converter.value;

        converter.byte0 = networkedBird[21];
        converter.byte1 = networkedBird[22];
        converter.byte2 = networkedBird[23];
        converter.byte3 = networkedBird[24];
        rRoll.Value     = converter.value;

        converter.byte0 = networkedBird[25];
        converter.byte1 = networkedBird[26];
        converter.byte2 = networkedBird[27];
        converter.byte3 = networkedBird[28];
        vX.Value        = converter.value;

        converter.byte0 = networkedBird[29];
        converter.byte1 = networkedBird[30];
        converter.byte2 = networkedBird[31];
        converter.byte3 = networkedBird[32];
        vY.Value        = converter.value;

        converter.byte0 = networkedBird[33];
        converter.byte1 = networkedBird[34];
        converter.byte2 = networkedBird[35];
        converter.byte3 = networkedBird[36];
        vZ.Value        = converter.value;

        converter.byte0 = networkedBird[37];
        converter.byte1 = networkedBird[38];
        converter.byte2 = networkedBird[39];
        converter.byte3 = networkedBird[40];
        time.Value      = converter.value;

        converter.byte0 = networkedBird[41];
        converter.byte1 = networkedBird[42];
        converter.byte2 = networkedBird[43];
        converter.byte3 = networkedBird[44];
        lightingManager.SetTime(converter.value);
    }