コード例 #1
0
        public void IncrementalConversionPerformance_CreateGameObjects([Values(1000)] int n)
        {
            InitializeIncrementalConversion();
            var reconvert = new NativeArray <int>(n, Allocator.TempJob);
            var args      = new IncrementalConversionBatch
            {
                ReconvertHierarchyInstanceIds = reconvert,
            };

            args.EnsureFullyInitialized();
            var objs = new List <GameObject>();

            Measure.Method(() =>
            {
                GameObjectConversionUtility.ConvertIncremental(ConversionWorld, ConversionFlags, ref args);
            }).SetUp(() =>
            {
                foreach (var go in objs)
                {
                    Object.DestroyImmediate(go);
                }
                SwapDeleteAndReconvert(ref args);
                GameObjectConversionUtility.ConvertIncremental(ConversionWorld, ConversionFlags, ref args);
                for (int i = 0; i < n; i++)
                {
                    var obj = _Objects.CreateGameObject();
                    objs.Add(obj);
                    reconvert[i] = obj.GetInstanceID();
                }

                SwapDeleteAndReconvert(ref args);
            }).MeasurementCount(30).Run();
            args.Dispose();
        }
コード例 #2
0
        public void Convert(Scene scene, Hash128 sceneHash, GameObjectConversionUtility.ConversionFlags flags)
        {
            using (m_Convert.Auto())
            {
                // Try incremental conversion
                if (!_RequestCleanConversion)
                {
                    // Debug.Log("Incremental convert");
                    try
                    {
                        GameObjectConversionUtility.ConvertIncremental(GameObjectWorld, _ChangedGameObjects, flags);
                        _ChangedGameObjects.Clear();
                    }
                    catch (Exception e)
                    {
                        _RequestCleanConversion = true;
                        Debug.LogWarning("Incremental conversion failed. Performing full conversion instead\n" + e.ToString());
                    }
                }

                // If anything failed, fall back to clean conversion
                if (_RequestCleanConversion)
                {
                    // Debug.Log("Clean convert");
                    ConvertedWorld.EntityManager.DestroyEntity(ConvertedWorld.EntityManager.UniversalQuery);
                    GameObjectWorld = GameObjectConversionUtility.ConvertIncrementalInitialize(scene, new GameObjectConversionSettings(ConvertedWorld, sceneHash, flags));
                }

                _ChangedGameObjects.Clear();
                _RequestCleanConversion = false;
            }
        }
        public void IncrementalConversion_ChangeOneObject_OnlyChangesThatObject()
        {
            var root  = _Objects.CreateGameObject("Root");
            var child = _Objects.CreateGameObject("Child");

            child.transform.SetParent(root.transform);

            InitializeIncrementalConversion();

            {
                var args = new IncrementalConversionBatch
                {
                    ChangedInstanceIds = new NativeArray <int>(new[] { root.GetInstanceID() }, Allocator.TempJob),
                };
                args.EnsureFullyInitialized();
                GameObjectConversionUtility.ConvertIncremental(ConversionWorld, ConversionFlags, ref args);
                args.Dispose();
            }
            CollectionAssert.AreEquivalent(InterceptConvertedGameObjects.GameObjectsConverted, new [] { root });

            {
                var args = new IncrementalConversionBatch
                {
                    ChangedInstanceIds = new NativeArray <int>(new[] { child.GetInstanceID() }, Allocator.TempJob)
                };
                args.EnsureFullyInitialized();
                GameObjectConversionUtility.ConvertIncremental(ConversionWorld, ConversionFlags, ref args);
                args.Dispose();
            }
            CollectionAssert.AreEquivalent(InterceptConvertedGameObjects.GameObjectsConverted, new [] { child });
        }
        public void IncrementalConversion_WhenChangingTransformWithoutDependency_DoesNotCauseReconversion()
        {
            var root  = _Objects.CreateGameObject("Root");
            var child = _Objects.CreateGameObject("Child");
            var a     = child.AddComponent <DependsOnTransformTestAuthoring>();

            a.Dependency            = root.transform;
            a.SkipDependency        = true;
            root.transform.position = new Vector3(0, 0, 0);
            child.transform.SetParent(root.transform);
            InitializeIncrementalConversion();

            // change the parent's position
            root.transform.position = new Vector3(0, 1, 2);
            var args = new IncrementalConversionBatch
            {
                ChangedComponents = new List <Component> {
                    root.transform
                }
            };

            args.EnsureFullyInitialized();
            GameObjectConversionUtility.ConvertIncremental(ConversionWorld, ConversionFlags, ref args);
            args.Dispose();

            // because there is no dependency on the transform of the child, we do not reconvert it and have invalid
            // data
            var t = DestinationWorld.EntityManager.CreateEntityQuery(typeof(DependsOnTransformTestAuthoring.Component))
                    .GetSingleton <DependsOnTransformTestAuthoring.Component>();

            Assert.AreNotEqual(t.LocalToWorld, child.transform.localToWorldMatrix);
        }
コード例 #5
0
        public void IncrementalConversionLinkedGroup()
        {
            var conversionFlags = GameObjectConversionUtility.ConversionFlags.GameViewLiveLink | GameObjectConversionUtility.ConversionFlags.AssignName;
            // Parent (LinkedEntityGroup) (2 additional entities)
            // - Child (2 additional entities)
            // All reference parent game object

            var parent = CreateGameObject().AddComponent <EntityRefTestDataAuthoring>();
            var child  = CreateGameObject().AddComponent <EntityRefTestDataAuthoring>();

            child.transform.parent = parent.transform;

            child.name = "child";
            child.AdditionalEntityCount    = 2;
            child.DeclareLinkedEntityGroup = false;
            child.Value = parent.gameObject;

            parent.name = "parent";
            parent.AdditionalEntityCount    = 2;
            parent.DeclareLinkedEntityGroup = true;
            parent.Value = parent.gameObject;

            using (var conversionWorld = GameObjectConversionUtility.ConvertIncrementalInitialize(SceneManager.GetActiveScene(), new GameObjectConversionSettings(World, conversionFlags)))
            {
                Entities.ForEach((ref EntityRefTestData data) =>
                                 StringAssert.StartsWith("parent", m_Manager.GetName(data.Value)));

                var entity = EmptySystem.GetSingletonEntity <LinkedEntityGroup>();

                // Parent (LinkedEntityGroup) (2 additional entities)
                // - Child (1 additional entities)
                // All reference child game object
                child.Value = child.gameObject;
                child.AdditionalEntityCount = 1;
                parent.Value = child.gameObject;
                GameObjectConversionUtility.ConvertIncremental(conversionWorld, new[] { child.gameObject }, conversionFlags);

                EntitiesAssert.ContainsOnly(m_Manager,
                                            EntityMatch.Exact <EntityRefTestData>(entity, k_CommonComponents,
                                                                                  EntityMatch.Component((LinkedEntityGroup[] group) => group.Length == 5)),
                                            EntityMatch.Exact <EntityRefTestData>(k_ChildComponents),
                                            EntityMatch.Exact <EntityRefTestData>(),
                                            EntityMatch.Exact <EntityRefTestData>(),
                                            EntityMatch.Exact <EntityRefTestData>());

                // We expect there to still only be one linked entity group and it should be the same entity as before
                // since it is attached to the primary entity which is not getting destroyed.
                Assert.AreEqual(entity, EmptySystem.GetSingletonEntity <LinkedEntityGroup>());

                Entities.ForEach((ref EntityRefTestData data) =>
                                 StringAssert.StartsWith("child", m_Manager.GetName(data.Value)));

                foreach (var e in m_Manager.GetBuffer <LinkedEntityGroup>(entity).AsNativeArray())
                {
                    Assert.IsTrue(m_Manager.Exists(e.Value));
                }
            }
        }
コード例 #6
0
        void Convert(Scene scene, Hash128 sceneGUID, GameObjectConversionUtility.ConversionFlags flags, BuildConfiguration config)
        {
            using (m_ConvertMarker.Auto())
            {
                // Try incremental conversion
                if (!_RequestCleanConversion)
                {
                    // Debug.Log("Incremental convert");
                    try
                    {
                        GameObjectConversionUtility.ConvertIncremental(_GameObjectWorld, _ChangedGameObjects, flags);
                        _ChangedGameObjects.Clear();
                    }
                    #pragma warning disable 168
                    catch (Exception e)
                    {
                        _RequestCleanConversion = true;

                        // Debug.Log("Incremental conversion failed. Performing full conversion instead\n" + e.ToString());
                    }
                    #pragma warning restore 168
                }

                // If anything failed, fall back to clean conversion
                if (_RequestCleanConversion)
                {
                    // Debug.Log("Clean convert");
                    _ConvertedWorld.EntityManager.DestroyEntity(_ConvertedWorld.EntityManager.UniversalQuery);
                    var conversionSettings = new GameObjectConversionSettings(_ConvertedWorld, flags);
                    conversionSettings.BuildConfiguration  = config;
                    conversionSettings.SceneGUID           = sceneGUID;
                    conversionSettings.DebugConversionName = _SceneName;
                    conversionSettings.BlobAssetStore      = m_BlobAssetStore;
                    conversionSettings.FilterFlags         = WorldSystemFilterFlags.HybridGameObjectConversion;

                    if (_GameObjectWorld != null && _GameObjectWorld.IsCreated)
                    {
                        _GameObjectWorld.Dispose();
                        _GameObjectWorld = null;
                    }
                    _GameObjectWorld = GameObjectConversionUtility.ConvertIncrementalInitialize(scene, conversionSettings);
                    m_AssetDependencies.Clear();
                    AddAssetDependencies(_GameObjectWorld.GetExistingSystem <GameObjectConversionMappingSystem>().Dependencies, ref m_AssetDependencies);
                }

                _ChangedGameObjects.Clear();
                _RequestCleanConversion = false;
            }
        }
        public void IncrementalConversion_ConvertedEntitiesAccessor_ReturnsAllEntities()
        {
            var root = _Objects.CreateGameObject("Root");

            InitializeIncrementalConversion();

            {
                var args = new IncrementalConversionBatch
                {
                    ChangedInstanceIds = new NativeArray <int>(new[] { root.GetInstanceID() }, Allocator.TempJob),
                };
                args.EnsureFullyInitialized();
                GameObjectConversionUtility.ConvertIncremental(ConversionWorld, ConversionFlags, ref args);
                args.Dispose();
            }
            CollectionAssert.AreEquivalent(InterceptConvertedGameObjects.GameObjectsConverted, new [] { root });
        }
        public void IncrementalConversion_WhenAddingNewGameObjectToSubScene_MatchesFullConversion()
        {
            InitializeIncrementalConversion();
            var go   = _Objects.CreateGameObject("Hello");
            var args = new IncrementalConversionBatch
            {
                ReconvertHierarchyInstanceIds = new NativeArray <int>(new[] { go.GetInstanceID() }, Allocator.TempJob),
                ChangedComponents             = new List <Component> {
                    go.transform
                }
            };

            args.EnsureFullyInitialized();
            GameObjectConversionUtility.ConvertIncremental(ConversionWorld, ConversionFlags, ref args);
            args.Dispose();
            CheckAgainstFullConversion(DestinationWorld);
        }
コード例 #9
0
        public void Convert(Scene scene, Hash128 sceneGUID, GameObjectConversionUtility.ConversionFlags flags, BuildSettings buildSettings)
        {
            using (m_ConvertMarker.Auto())
            {
                // Try incremental conversion
                if (!_RequestCleanConversion)
                {
                    // Debug.Log("Incremental convert");
                    try
                    {
                        GameObjectConversionUtility.ConvertIncremental(_GameObjectWorld, _ChangedGameObjects, flags);
                        _ChangedGameObjects.Clear();
                    }
                    catch (Exception e)
                    {
                        _RequestCleanConversion = true;
                        Debug.LogWarning("Incremental conversion failed. Performing full conversion instead\n" + e.ToString());
                    }
                }

                // If anything failed, fall back to clean conversion
                if (_RequestCleanConversion)
                {
                    // Debug.Log("Clean convert");
                    _ConvertedWorld.EntityManager.DestroyEntity(_ConvertedWorld.EntityManager.UniversalQuery);
                    var conversionSettings = new GameObjectConversionSettings(_ConvertedWorld, flags);
                    conversionSettings.BuildSettings       = buildSettings;
                    conversionSettings.SceneGUID           = sceneGUID;
                    conversionSettings.DebugConversionName = _SceneName;
                    conversionSettings.blobAssetStore      = m_BlobAssetStore;

                    if (_GameObjectWorld != null && _GameObjectWorld.IsCreated)
                    {
                        _GameObjectWorld.Dispose();
                        _GameObjectWorld = null;
                    }
                    _GameObjectWorld = GameObjectConversionUtility.ConvertIncrementalInitialize(scene, conversionSettings);
                }

                _ChangedGameObjects.Clear();
                _RequestCleanConversion = false;
            }
        }
        public void IncrementalConversion_NoChanges_DoesNotCauseReconversion()
        {
            for (int i = 0; i < 10; i++)
            {
                _Objects.CreateGameObject("Hello" + i);
            }
            InitializeIncrementalConversion();

            var args = new IncrementalConversionBatch();

            args.EnsureFullyInitialized();

            // this is necessary: if nothing is updated, the interception system never updates and we never clear the
            // list.
            InterceptConvertedGameObjects.GameObjectsConverted.Clear();
            GameObjectConversionUtility.ConvertIncremental(ConversionWorld, ConversionFlags, ref args);
            args.Dispose();

            Assert.IsEmpty(InterceptConvertedGameObjects.GameObjectsConverted);
        }
コード例 #11
0
        void Convert(GameObjectConversionUtility.ConversionFlags flags)
        {
            using (LiveLinkConvertMarker.Auto())
            {
                var mode = LiveConversionSettings.Mode;
#if UNITY_2020_2_OR_NEWER
                if (mode == LiveConversionSettings.ConversionMode.AlwaysCleanConvert)
                {
                    _RequestCleanConversion = true;
                }
                _IncrementalConversionDebug.LastConversionFlags = flags;
#endif

                // Try incremental conversion
                if (!_RequestCleanConversion)
                {
                    try
                    {
                        using (IncrementalConversionMarker.Auto())
                        {
#if UNITY_2020_2_OR_NEWER
                            _IncrementalConversionDebug.NeedsUpdate = true;
                            var batch = new IncrementalConversionBatch();
                            _IncrementalConversionChangeTracker.FillBatch(ref batch);
                            GameObjectConversionUtility.ConvertIncremental(_GameObjectWorld, flags, ref batch);
#else
                            GameObjectConversionUtility.ConvertIncremental(_GameObjectWorld, m_ChangedGameObjects, _IncrementalConversionChangeTracker.ChangedAssets, flags);
#endif
                            AddMissingData(_ConvertedWorld, _MissingSceneQuery, _MissingRenderDataQuery);
                        }
                    }
#if UNITY_2020_2_OR_NEWER
                    catch (Exception e)
                    {
                        _RequestCleanConversion = true;
                        if (LiveConversionSettings.TreatIncrementalConversionFailureAsError)
                        {
                            throw;
                        }
                        if (mode != LiveConversionSettings.ConversionMode.AlwaysCleanConvert)
                        {
                            Debug.Log("Incremental conversion failed. Performing full conversion instead\n" + e);
                        }
                    }
#else
                    catch (Exception)

                    {
                        _RequestCleanConversion = true;
                    }
#endif
                }

                // If anything failed, fall back to clean conversion
                if (_RequestCleanConversion)
                {
#if UNITY_2020_2_OR_NEWER
                    _IncrementalConversionDebug.NeedsUpdate = false;
#endif
                    using (CleanConversionMarker.Auto())
                    {
                        if (_GameObjectWorld != null && _GameObjectWorld.IsCreated)
                        {
                            _GameObjectWorld.Dispose();
                            _GameObjectWorld = null;
                        }

                        var settings = PrepareConversion(_ConvertedWorld, flags, _buildConfigurationGUID, _buildConfiguration);
                        _GameObjectWorld = GameObjectConversionUtility.InitializeIncrementalConversion(_Scene, settings);
                        _MappingSystem   = _GameObjectWorld.GetExistingSystem <GameObjectConversionMappingSystem>();
                        AddMissingData(_ConvertedWorld, _MissingSceneQuery, _MissingRenderDataQuery);
                    }
                }

                _IncrementalConversionChangeTracker.Clear();
                _RequestCleanConversion = false;
            }
        }