public void ArraySchemaTypesTest()
    {
        var state = new SchemaTest.ArraySchemaTypes.ArraySchemaTypes();

        byte[] bytes = { 128, 1, 129, 2, 130, 3, 131, 4, 255, 1, 128, 0, 5, 128, 1, 6, 255, 2, 128, 0, 0, 128, 1, 10, 128, 2, 20, 128, 3, 205, 192, 13, 255, 3, 128, 0, 163, 111, 110, 101, 128, 1, 163, 116, 119, 111, 128, 2, 165, 116, 104, 114, 101, 101, 255, 4, 128, 0, 232, 3, 0, 0, 128, 1, 192, 13, 0, 0, 128, 2, 72, 244, 255, 255, 255, 5, 128, 100, 129, 208, 156, 255, 6, 128, 100, 129, 208, 156 };

        state.arrayOfSchemas.OnAdd += (value, key) => Debug.Log("onAdd, arrayOfSchemas => " + key);
        state.arrayOfNumbers.OnAdd += (value, key) => Debug.Log("onAdd, arrayOfNumbers => " + key);
        state.arrayOfStrings.OnAdd += (value, key) => Debug.Log("onAdd, arrayOfStrings => " + key);
        state.arrayOfInt32.OnAdd   += (value, key) => Debug.Log("onAdd, arrayOfInt32 => " + key);

        var refs = new Colyseus.Schema.ReferenceTracker();

        state.Decode(bytes, null, refs);

        Debug.Log("Decoded 1st time!");

        Assert.AreEqual(2, state.arrayOfSchemas.Count);
        Assert.AreEqual(100, state.arrayOfSchemas[0].x);
        Assert.AreEqual(-100, state.arrayOfSchemas[0].y);
        Assert.AreEqual(100, state.arrayOfSchemas[1].x);
        Assert.AreEqual(-100, state.arrayOfSchemas[1].y);

        Assert.AreEqual(4, state.arrayOfNumbers.Count);
        Assert.AreEqual(0, state.arrayOfNumbers[0]);
        Assert.AreEqual(10, state.arrayOfNumbers[1]);
        Assert.AreEqual(20, state.arrayOfNumbers[2]);
        Assert.AreEqual(3520, state.arrayOfNumbers[3]);

        Assert.AreEqual(3, state.arrayOfStrings.Count);
        Assert.AreEqual("one", state.arrayOfStrings[0]);
        Assert.AreEqual("two", state.arrayOfStrings[1]);
        Assert.AreEqual("three", state.arrayOfStrings[2]);

        Assert.AreEqual(3, state.arrayOfInt32.Count);
        Assert.AreEqual(1000, state.arrayOfInt32[0]);
        Assert.AreEqual(3520, state.arrayOfInt32[1]);
        Assert.AreEqual(-3000, state.arrayOfInt32[2]);

        state.arrayOfSchemas.OnRemove += (value, key) => Debug.Log("onRemove, arrayOfSchemas => " + key);
        state.arrayOfNumbers.OnRemove += (value, key) => Debug.Log("onRemove, arrayOfNumbers => " + key);
        state.arrayOfStrings.OnRemove += (value, key) => Debug.Log("onRemove, arrayOfStrings => " + key);
        state.arrayOfInt32.OnRemove   += (value, key) => Debug.Log("onRemove, arrayOfInt32 => " + key);

        byte[] popBytes = { 255, 1, 64, 1, 255, 2, 64, 3, 64, 2, 64, 1, 255, 4, 64, 2, 64, 1, 255, 3, 64, 2, 64, 1 };
        state.Decode(popBytes, null, refs);
        Debug.Log("Decoded 2nd time!");

        Assert.AreEqual(1, state.arrayOfSchemas.Count);
        Assert.AreEqual(1, state.arrayOfNumbers.Count);
        Assert.AreEqual(1, state.arrayOfStrings.Count);
        Assert.AreEqual(1, state.arrayOfInt32.Count);
        Debug.Log("FINISHED");
    }
    public void ArraySchemaTypesTest()
    {
        var state = new SchemaTest.ArraySchemaTypes.ArraySchemaTypes();

        byte[] bytes = { 0, 2, 2, 0, 0, 100, 1, 208, 156, 193, 1, 0, 100, 1, 208, 156, 193, 1, 4, 4, 0, 0, 1, 10, 2, 20, 3, 205, 192, 13, 2, 3, 3, 0, 163, 111, 110, 101, 1, 163, 116, 119, 111, 2, 165, 116, 104, 114, 101, 101, 3, 3, 3, 0, 232, 3, 0, 0, 1, 192, 13, 0, 0, 2, 72, 244, 255, 255 };

        state.arrayOfSchemas.OnAdd += (value, key) => Debug.Log("onAdd, arrayOfSchemas => " + key);
        state.arrayOfNumbers.OnAdd += (value, key) => Debug.Log("onAdd, arrayOfNumbers => " + key);
        state.arrayOfStrings.OnAdd += (value, key) => Debug.Log("onAdd, arrayOfStrings => " + key);
        state.arrayOfInt32.OnAdd   += (value, key) => Debug.Log("onAdd, arrayOfInt32 => " + key);
        state.Decode(bytes);

        Assert.AreEqual(state.arrayOfSchemas.Count, 2);
        Assert.AreEqual(state.arrayOfSchemas[0].x, 100);
        Assert.AreEqual(state.arrayOfSchemas[0].y, -100);
        Assert.AreEqual(state.arrayOfSchemas[1].x, 100);
        Assert.AreEqual(state.arrayOfSchemas[1].y, -100);

        Assert.AreEqual(state.arrayOfNumbers.Count, 4);
        Assert.AreEqual(state.arrayOfNumbers[0], 0);
        Assert.AreEqual(state.arrayOfNumbers[1], 10);
        Assert.AreEqual(state.arrayOfNumbers[2], 20);
        Assert.AreEqual(state.arrayOfNumbers[3], 3520);

        Assert.AreEqual(state.arrayOfStrings.Count, 3);
        Assert.AreEqual(state.arrayOfStrings[0], "one");
        Assert.AreEqual(state.arrayOfStrings[1], "two");
        Assert.AreEqual(state.arrayOfStrings[2], "three");

        Assert.AreEqual(state.arrayOfInt32.Count, 3);
        Assert.AreEqual(state.arrayOfInt32[0], 1000);
        Assert.AreEqual(state.arrayOfInt32[1], 3520);
        Assert.AreEqual(state.arrayOfInt32[2], -3000);

        state.arrayOfSchemas.OnRemove += (value, key) => Debug.Log("onRemove, arrayOfSchemas => " + key);
        state.arrayOfNumbers.OnRemove += (value, key) => Debug.Log("onRemove, arrayOfNumbers => " + key);
        state.arrayOfStrings.OnRemove += (value, key) => Debug.Log("onRemove, arrayOfStrings => " + key);
        state.arrayOfInt32.OnRemove   += (value, key) => Debug.Log("onRemove, arrayOfInt32 => " + key);

        byte[] popBytes = { 0, 1, 0, 1, 1, 0, 3, 1, 0, 2, 1, 0 };
        state.Decode(popBytes);

        Assert.AreEqual(state.arrayOfSchemas.Count, 1);
        Assert.AreEqual(state.arrayOfNumbers.Count, 1);
        Assert.AreEqual(state.arrayOfStrings.Count, 1);
        Assert.AreEqual(state.arrayOfInt32.Count, 1);
        Debug.Log("FINISHED");
    }
예제 #3
0
    public void ArraySchemaTypesTest()
    {
        var state = new SchemaTest.ArraySchemaTypes.ArraySchemaTypes();

        byte[] bytes = { 0, 2, 2, 0, 0, 100, 1, 208, 156, 193, 1, 0, 100, 1, 208, 156, 193, 1, 4, 4, 0, 0, 1, 10, 2, 20, 3, 30 };
        state.Decode(bytes);

        Assert.AreEqual(state.arrayOfSchemas.Count, 2);
        Assert.AreEqual(state.arrayOfSchemas[0].x, 100);
        Assert.AreEqual(state.arrayOfSchemas[0].y, -100);
        Assert.AreEqual(state.arrayOfSchemas[1].x, 100);
        Assert.AreEqual(state.arrayOfSchemas[1].y, -100);

        Assert.AreEqual(state.arrayOfNumbers.Count, 4);
        Assert.AreEqual(state.arrayOfNumbers[0], 0);
        Assert.AreEqual(state.arrayOfNumbers[1], 10);
        Assert.AreEqual(state.arrayOfNumbers[2], 20);
        Assert.AreEqual(state.arrayOfNumbers[3], 30);
    }