コード例 #1
0
ファイル: SyncVarTest.cs プロジェクト: MirageNet/Mirage
        public void TestSyncIntervalAndClearAllComponents()
        {
            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");

            // ClearAllComponents should clear dirty even if syncInterval not
            // elapsed yet
            player.Identity.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");
        }
コード例 #2
0
ファイル: SyncVarTest.cs プロジェクト: MirageNet/Mirage
        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");
        }