Exemplo n.º 1
0
        public void TestSettingStruct()
        {
            GameObject gameObject = new GameObject();

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

            // synchronize immediatelly
            player.syncInterval = 0f;

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

            MockPlayer.Guild 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");
        }
Exemplo n.º 2
0
        public void TestSyncIntervalAndClearAllComponents()
        {
            GameObject gameObject = new GameObject();

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

            player.lastSyncTime = Time.time;
            // synchronize immediately
            player.syncInterval = 1f;

            player.guild = new MockPlayer.Guild
            {
                name = "Back street boys"
            };

            Assert.That(player.IsDirty(), Is.False, "Sync interval not met, so not dirty yet");

            // ClearAllComponents should clear dirty even if syncInterval not
            // elapsed yet
            player.netIdentity.ClearAllComponentsDirtyBits();

            // set lastSyncTime far enough back to be ready for syncing
            player.lastSyncTime = Time.time - player.syncInterval;

            // should be dirty now
            Assert.That(player.IsDirty(), Is.False, "Sync interval met, should still not be dirty");
        }
Exemplo n.º 3
0
        public void TestSynchronizingObjects()
        {
            // set up a "server" object
            GameObject      gameObject1 = new GameObject();
            NetworkIdentity identity1   = gameObject1.AddComponent <NetworkIdentity>();
            MockPlayer      player1     = gameObject1.AddComponent <MockPlayer>();

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

            // serialize all the data as we would for the network
            NetworkWriter ownerWriter = new NetworkWriter();
            // not really used in this Test
            NetworkWriter observersWriter = new NetworkWriter();

            identity1.OnSerializeAllSafely(true, ownerWriter, out int ownerWritten, observersWriter, out int observersWritten);

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

            // apply all the data from the server object
            NetworkReader reader = new NetworkReader(ownerWriter.ToArray());

            identity2.OnDeserializeAllSafely(reader, true);

            // check that the syncvars got updated
            Assert.That(player2.guild.name, Is.EqualTo("Back street boys"), "Data should be synchronized");
        }
Exemplo n.º 4
0
        public void TestSyncIntervalAndClearDirtyComponents()
        {
            var gameObject = new GameObject("player", typeof(NetworkIdentity), typeof(MockPlayer));

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

            player.lastSyncTime = Time.time;
            // synchronize immediately
            player.syncInterval = 1f;

            player.guild = new MockPlayer.Guild
            {
                name = "Back street boys"
            };

            Assert.That(player.IsDirty(), Is.False, "Sync interval not met, so not dirty yet");

            // ClearDirtyComponents should do nothing since syncInterval is not
            // elapsed yet
            player.NetIdentity.ClearDirtyComponentsDirtyBits();

            // set lastSyncTime far enough back to be ready for syncing
            player.lastSyncTime = Time.time - player.syncInterval;

            // should be dirty now
            Assert.That(player.IsDirty(), Is.True, "Sync interval met, should be dirty");
        }
Exemplo n.º 5
0
        public void SetNetworkIdentitySyncvar()
        {
            var        gameObject = new GameObject("player", typeof(NetworkIdentity), typeof(MockPlayer));
            MockPlayer player     = gameObject.GetComponent <MockPlayer>();

            player.target = gameObject.GetComponent <NetworkIdentity>();

            Assert.That(player.target, Is.EqualTo(player.GetComponent <NetworkIdentity>()));
        }
Exemplo n.º 6
0
        public void TestSettingGuild()
        {
            GameObject gameObject = new GameObject();

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

            Assert.That(!player.IsDirty());

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

            player.guild = myGuild;

            Assert.That(player.IsDirty());
        }
Exemplo n.º 7
0
        public void TestSyncModeObserversMask()
        {
            GameObject      gameObject1 = new GameObject();
            NetworkIdentity identity    = gameObject1.AddComponent <NetworkIdentity>();
            MockPlayer      player1     = gameObject1.AddComponent <MockPlayer>();

            player1.syncInterval = 0;
            MockPlayer player2 = gameObject1.AddComponent <MockPlayer>();

            player2.syncInterval = 0;
            MockPlayer player3 = gameObject1.AddComponent <MockPlayer>();

            player3.syncInterval = 0;

            // sync mode
            player1.syncMode = SyncMode.Observers;
            player2.syncMode = SyncMode.Owner;
            player3.syncMode = SyncMode.Observers;

            Assert.That(identity.GetSyncModeObserversMask(), Is.EqualTo(0b101));
        }