Beispiel #1
0
        public void TestSettingStruct()
        {
            var gameObject = new GameObject("player", typeof(NetworkIdentity), typeof(MockPlayer));

            MockPlayer player = gameObject.GetComponent <MockPlayer>();

            // synchronize immediatelly
            player.syncInterval = 0f;

            Assert.That(player.IsDirty(), Is.False, "First time object should not be dirty");

            var myGuild = new MockPlayer.Guild
            {
                name = "Back street boys"
            };

            player.guild = myGuild;

            Assert.That(player.IsDirty(), "Setting struct should mark object as dirty");
            player.ClearAllDirtyBits();
            Assert.That(player.IsDirty(), Is.False, "ClearAllDirtyBits() should clear dirty flag");

            // clearing the guild should set dirty bit too
            player.guild = default;
            Assert.That(player.IsDirty(), "Clearing struct should mark object as dirty");
        }
Beispiel #2
0
        public void TestSynchronizingObjects()
        {
            // set up a "server" object
            var             gameObject1 = new GameObject("player", typeof(NetworkIdentity), typeof(MockPlayer));
            NetworkIdentity identity1   = gameObject1.GetComponent <NetworkIdentity>();
            MockPlayer      player1     = gameObject1.GetComponent <MockPlayer>();
            var             myGuild     = new MockPlayer.Guild
            {
                name = "Back street boys"
            };

            player1.guild = myGuild;

            // serialize all the data as we would for the network
            identity1.OnSerializeAll(true, ownerWriter, observersWriter);

            // set up a "client" object
            var             gameObject2 = new GameObject();
            NetworkIdentity identity2   = gameObject2.AddComponent <NetworkIdentity>();
            MockPlayer      player2     = gameObject2.AddComponent <MockPlayer>();

            // apply all the data from the server object
            reader.Reset(ownerWriter.ToArray());
            identity2.OnDeserializeAll(reader, true);

            // check that the syncvars got updated
            Assert.That(player2.guild.name, Is.EqualTo("Back street boys"), "Data should be synchronized");
        }
Beispiel #3
0
        public void TestSettingStruct()
        {
            var player = CreateBehaviour <MockPlayer>();

            // synchronize immediatelly
            player.syncInterval = 0f;

            Assert.That(player.IsDirty(), Is.False, "First time object should not be dirty");

            var myGuild = new MockPlayer.Guild
            {
                name = "Back street boys"
            };

            player.guild = myGuild;

            Assert.That(player.IsDirty(), "Setting struct should mark object as dirty");
            player.ClearAllDirtyBits();
            Assert.That(player.IsDirty(), Is.False, "ClearAllDirtyBits() should clear dirty flag");

            // clearing the guild should set dirty bit too
            player.guild = default;
            Assert.That(player.IsDirty(), "Clearing struct should mark object as dirty");
        }
Beispiel #4
0
        public void TestSynchronizingObjects()
        {
            // set up a "server" object
            var player1 = CreateBehaviour <MockPlayer>();
            var myGuild = new MockPlayer.Guild
            {
                name = "Back street boys"
            };

            player1.guild = myGuild;

            // serialize all the data as we would for the network
            player1.Identity.OnSerializeAll(true, ownerWriter, observersWriter);

            // set up a "client" object
            var player2 = CreateBehaviour <MockPlayer>();

            // apply all the data from the server object
            reader.Reset(ownerWriter.ToArray());
            player2.Identity.OnDeserializeAll(reader, true);

            // check that the syncvars got updated
            Assert.That(player2.guild.name, Is.EqualTo("Back street boys"), "Data should be synchronized");
        }