コード例 #1
0
        static void SwapDeleteAndReconvert(ref IncrementalConversionBatch batch)
        {
            var tmp = batch.DeletedInstanceIds;

            batch.DeletedInstanceIds            = batch.ReconvertHierarchyInstanceIds;
            batch.ReconvertHierarchyInstanceIds = tmp;
        }
コード例 #2
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();
        }
        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);
        }
        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);
        }
        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);
        }
コード例 #8
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;
            }
        }