public IEnumerator IncrementalConversion_WithDuplicateChanges_IncomingChangesAreDeduplicated()
        {
            var subScene = CreateEmptySubScene("TestSubScene", true);

            SceneManager.SetActiveScene(subScene.EditingScene);
            var go   = new GameObject();
            var goId = go.GetInstanceID();

            var w = GetLiveLinkWorld();

            yield return(UpdateEditorAndWorld(w));

            {
                Undo.RegisterCompleteObjectUndo(go, "Test Change");
                Undo.RegisterCompleteObjectUndo(go, "Test Change");
                IncrementalConversionTestSystem.CaptureNext(subScene.SceneGUID);
                yield return(UpdateEditorAndWorld(w));

                CollectionAssert.IsEmpty(IncrementalConversionTestSystem.ChangedComponents);
                CollectionAssert.AreEqual(new[] { go }, IncrementalConversionTestSystem.ChangedGameObjects);
                CollectionAssert.AreEqual(new[] { goId }, IncrementalConversionTestSystem.ChangedGameObjectsInstanceIds);
                CollectionAssert.IsEmpty(IncrementalConversionTestSystem.DeletedGameObjectInstanceIds);

                Undo.RegisterCompleteObjectUndo(go.transform, "Test Component Change");
                Undo.RegisterCompleteObjectUndo(go.transform, "Test Component Change");
                IncrementalConversionTestSystem.CaptureNext(subScene.SceneGUID);
                yield return(UpdateEditorAndWorld(w));

                CollectionAssert.AreEqual(new [] { go.transform }, IncrementalConversionTestSystem.ChangedComponents);
                CollectionAssert.IsEmpty(IncrementalConversionTestSystem.ChangedGameObjects);
                CollectionAssert.IsEmpty(IncrementalConversionTestSystem.ChangedGameObjectsInstanceIds);
                CollectionAssert.IsEmpty(IncrementalConversionTestSystem.DeletedGameObjectInstanceIds);
            }
        }
        public IEnumerator IncrementalConversion_WithCreateThenDelete_IncomingChangesAreEmpty()
        {
            var subScene = CreateEmptySubScene("TestSubScene", true);

            SceneManager.SetActiveScene(subScene.EditingScene);

            var w = GetLiveLinkWorld();

            yield return(UpdateEditorAndWorld(w));

            {
                var go = new GameObject();

                Undo.RegisterCreatedObjectUndo(go, "Test Create");
                Undo.IncrementCurrentGroup();
                Undo.DestroyObjectImmediate(go);
                IncrementalConversionTestSystem.CaptureNext(subScene.SceneGUID);
                yield return(UpdateEditorAndWorld(w));

                CollectionAssert.IsEmpty(IncrementalConversionTestSystem.ChangedComponents);
                CollectionAssert.IsEmpty(IncrementalConversionTestSystem.ChangedGameObjects);
                CollectionAssert.IsEmpty(IncrementalConversionTestSystem.ChangedGameObjectsInstanceIds);
                CollectionAssert.IsEmpty(IncrementalConversionTestSystem.DeletedGameObjectInstanceIds);
            }
        }
        public IEnumerator IncrementalConversion_WithSingleObject_IncomingChangesAreCorrect()
        {
            var subScene = CreateEmptySubScene("TestSubScene", true);

            SceneManager.SetActiveScene(subScene.EditingScene);

            var w = GetLiveLinkWorld();

            yield return(UpdateEditorAndWorld(w));

            {
                var go   = new GameObject("TestGameObject");
                int goId = go.GetInstanceID();

                Undo.RegisterCreatedObjectUndo(go, "Test Create");
                IncrementalConversionTestSystem.CaptureNext(subScene.SceneGUID);
                yield return(UpdateEditorAndWorld(w));

                CollectionAssert.IsEmpty(IncrementalConversionTestSystem.ChangedComponents);
                CollectionAssert.AreEqual(new[] { go }, IncrementalConversionTestSystem.ChangedGameObjects);
                CollectionAssert.AreEqual(new[] { goId }, IncrementalConversionTestSystem.ChangedGameObjectsInstanceIds);
                CollectionAssert.IsEmpty(IncrementalConversionTestSystem.DeletedGameObjectInstanceIds);

                Undo.RegisterCompleteObjectUndo(go, "Test Change GameObject");
                IncrementalConversionTestSystem.CaptureNext(subScene.SceneGUID);
                yield return(UpdateEditorAndWorld(w));

                CollectionAssert.IsEmpty(IncrementalConversionTestSystem.ChangedComponents);
                CollectionAssert.AreEqual(new[] { go }, IncrementalConversionTestSystem.ChangedGameObjects);
                CollectionAssert.AreEqual(new[] { goId }, IncrementalConversionTestSystem.ChangedGameObjectsInstanceIds);
                CollectionAssert.IsEmpty(IncrementalConversionTestSystem.DeletedGameObjectInstanceIds);

                // Changing a component should not mark the game object itself as dirty.
                Undo.RegisterCompleteObjectUndo(go.transform, "Test Change Transform");
                IncrementalConversionTestSystem.CaptureNext(subScene.SceneGUID);
                yield return(UpdateEditorAndWorld(w));

                CollectionAssert.AreEqual(new[] { go.transform }, IncrementalConversionTestSystem.ChangedComponents);
                CollectionAssert.IsEmpty(IncrementalConversionTestSystem.ChangedGameObjects);
                CollectionAssert.IsEmpty(IncrementalConversionTestSystem.ChangedGameObjectsInstanceIds);
                CollectionAssert.IsEmpty(IncrementalConversionTestSystem.DeletedGameObjectInstanceIds);

                Undo.DestroyObjectImmediate(go);
                IncrementalConversionTestSystem.CaptureNext(subScene.SceneGUID);
                yield return(UpdateEditorAndWorld(w));

                CollectionAssert.IsEmpty(IncrementalConversionTestSystem.ChangedComponents);
                CollectionAssert.IsEmpty(IncrementalConversionTestSystem.ChangedGameObjects);
                CollectionAssert.IsEmpty(IncrementalConversionTestSystem.ChangedGameObjectsInstanceIds);
                CollectionAssert.AreEqual(new[] { goId }, IncrementalConversionTestSystem.DeletedGameObjectInstanceIds);
            }
        }
        public IEnumerator IncrementalConversion_WithParentChange_IncomingChangesOnlyContainTransformChange()
        {
            var subScene = CreateEmptySubScene("TestSubScene", true);

            SceneManager.SetActiveScene(subScene.EditingScene);
            var root  = new GameObject("Root");
            var child = new GameObject("Child");

            var w = GetLiveLinkWorld();

            yield return(UpdateEditorAndWorld(w));

            {
                Undo.SetTransformParent(child.transform, root.transform, "Test Transform change");
                IncrementalConversionTestSystem.CaptureNext(subScene.SceneGUID);
                yield return(UpdateEditorAndWorld(w));

                CollectionAssert.AreEqual(new[] { child.transform }, IncrementalConversionTestSystem.ChangedComponents);
                CollectionAssert.IsEmpty(IncrementalConversionTestSystem.ChangedGameObjects);
                CollectionAssert.IsEmpty(IncrementalConversionTestSystem.ChangedGameObjectsInstanceIds);
                CollectionAssert.IsEmpty(IncrementalConversionTestSystem.DeletedGameObjectInstanceIds);
            }
        }
        public IEnumerator IncrementalConversion_WithDeleteThenCreate_IncomingChangesMarkGameObjectChanged()
        {
            var subScene = CreateEmptySubScene("TestSubScene", true);

            SceneManager.SetActiveScene(subScene.EditingScene);
            var go   = new GameObject("Go");
            var goId = go.GetInstanceID();

            var w = GetLiveLinkWorld();

            yield return(UpdateEditorAndWorld(w));

            {
                Undo.DestroyObjectImmediate(go);
                Undo.PerformUndo();
                IncrementalConversionTestSystem.CaptureNext(subScene.SceneGUID);
                yield return(UpdateEditorAndWorld(w));

                CollectionAssert.IsEmpty(IncrementalConversionTestSystem.ChangedComponents);
                CollectionAssert.AreEqual(new[] { go }, IncrementalConversionTestSystem.ChangedGameObjects);
                CollectionAssert.AreEqual(new[] { goId }, IncrementalConversionTestSystem.ChangedGameObjectsInstanceIds);
                CollectionAssert.IsEmpty(IncrementalConversionTestSystem.DeletedGameObjectInstanceIds);
            }
        }
        public IEnumerator IncrementalConversion_WithObjectHierarchy_IncomingChangesContainChildren()
        {
            var subScene = CreateEmptySubScene("TestSubScene", true);

            SceneManager.SetActiveScene(subScene.EditingScene);

            var w = GetLiveLinkWorld();

            yield return(UpdateEditorAndWorld(w));

            {
                var root    = new GameObject("Root");
                int rootId  = root.GetInstanceID();
                var child   = new GameObject("Child");
                int childId = child.GetInstanceID();
                child.transform.SetParent(root.transform);

                Undo.RegisterCreatedObjectUndo(root, "Test Create");
                IncrementalConversionTestSystem.CaptureNext(subScene.SceneGUID);
                yield return(UpdateEditorAndWorld(w));

                CollectionAssert.IsEmpty(IncrementalConversionTestSystem.ChangedComponents);
                CollectionAssert.AreEquivalent(new[] { root, child }, IncrementalConversionTestSystem.ChangedGameObjects);
                CollectionAssert.AreEquivalent(new[] { rootId, childId }, IncrementalConversionTestSystem.ChangedGameObjectsInstanceIds);
                CollectionAssert.IsEmpty(IncrementalConversionTestSystem.DeletedGameObjectInstanceIds);

                Undo.DestroyObjectImmediate(root);
                IncrementalConversionTestSystem.CaptureNext(subScene.SceneGUID);
                yield return(UpdateEditorAndWorld(w));

                CollectionAssert.IsEmpty(IncrementalConversionTestSystem.ChangedComponents);
                CollectionAssert.IsEmpty(IncrementalConversionTestSystem.ChangedGameObjects);
                CollectionAssert.IsEmpty(IncrementalConversionTestSystem.ChangedGameObjectsInstanceIds);
                CollectionAssert.AreEquivalent(new[] { rootId, childId }, IncrementalConversionTestSystem.DeletedGameObjectInstanceIds);
            }
        }