public static void ConvertAndInjectOriginal(GameObject root)
        {
            using (var gameObjectWorld = new GameObjectConversionSettings(World.Active, GameObjectConversionUtility.ConversionFlags.AssignName).CreateConversionWorld())
            {
                GameObjectEntity.AddToEntityManager(gameObjectWorld.EntityManager, root);

                GameObjectConversionUtility.Convert(gameObjectWorld);

                var entity = GameObjectConversionUtility.GameObjectToConvertedEntity(gameObjectWorld, root);
                InjectOriginalComponents(World.Active.EntityManager, entity, root.transform);
            }
        }
        public static void ConvertHierarchy(GameObject root)
        {
            using (var gameObjectWorld = new GameObjectConversionSettings(World.Active, GameObjectConversionUtility.ConversionFlags.AssignName).CreateConversionWorld())
            {
                AddRecurse(gameObjectWorld.EntityManager, root.transform);

                GameObjectConversionUtility.Convert(gameObjectWorld);

                InjectOriginalComponents(gameObjectWorld, World.Active.EntityManager, root.transform);

                Destroy(root);
            }
        }
Esempio n. 3
0
        public static void ConvertHierarchy(GameObject root)
        {
            var gameObjectWorld = GameObjectConversionUtility.CreateConversionWorld(World.Active, default(Hash128), 0);

            AddRecurse(gameObjectWorld.EntityManager, root.transform);

            GameObjectConversionUtility.Convert(gameObjectWorld, World.Active);

            InjectOriginalComponents(gameObjectWorld, World.Active.EntityManager, root.transform);

            GameObject.Destroy(root);

            gameObjectWorld.Dispose();
        }
Esempio n. 4
0
        public static void ConvertAndInjectOriginal(GameObject root)
        {
            var gameObjectWorld = GameObjectConversionUtility.CreateConversionWorld(World.Active, default(Hash128), 0);

            GameObjectEntity.AddToEntityManager(gameObjectWorld.EntityManager, root);

            GameObjectConversionUtility.Convert(gameObjectWorld, World.Active);

            var entity = GameObjectConversionUtility.GameObjectToConvertedEntity(gameObjectWorld, root);

            InjectOriginalComponents(World.Active.EntityManager, entity, root.transform);

            gameObjectWorld.Dispose();
        }
        void Convert()
        {
            var toBeDetached    = new HashSet <Transform>();
            var conversionRoots = new HashSet <GameObject>();

            try
            {
                var toBeInjected = new List <Transform>();

                foreach (var convertToWorld in m_ToBeConverted)
                {
                    var toBeConverted = convertToWorld.Value;

                    var settings = new GameObjectConversionSettings(
                        convertToWorld.Key,
                        GameObjectConversionUtility.ConversionFlags.AssignName);
                    settings.FilterFlags = WorldSystemFilterFlags.HybridGameObjectConversion;

                    settings.BlobAssetStore = BlobAssetStore;

                    using (var gameObjectWorld = settings.CreateConversionWorld())
                    {
                        toBeConverted.RemoveAll(convert =>
                        {
                            if (convert == null)
                            {
                                return(true);
                            }

                            if (convert.GetComponent <StopConvertToEntity>() != null)
                            {
                                LogWarning(
                                    $"{nameof(ConvertToEntity)} will be ignored because of a {nameof(StopConvertToEntity)} on the same GameObject",
                                    convert.gameObject);
                                return(true);
                            }

                            var parent = convert.transform.parent;
                            var remove = parent != null && parent.GetComponentInParent <ConvertToEntity>() != null;
                            if (remove && parent.GetComponentInParent <StopConvertToEntity>() != null)
                            {
                                LogWarning(
                                    $"{nameof(ConvertToEntity)} will be ignored because of a {nameof(StopConvertToEntity)} higher in the hierarchy",
                                    convert.gameObject);
                            }

                            return(remove);
                        });

                        foreach (var convert in toBeConverted)
                        {
                            AddRecurse(gameObjectWorld.EntityManager, convert.transform, toBeDetached, toBeInjected);
                        }

                        foreach (var convert in toBeConverted)
                        {
                            conversionRoots.Add(convert.gameObject);
                            toBeDetached.Remove(convert.transform);
                        }

                        GameObjectConversionUtility.Convert(gameObjectWorld);

                        var mappingSystem = gameObjectWorld.GetExistingSystem <GameObjectConversionMappingSystem>();
                        foreach (var convert in toBeInjected)
                        {
                            InjectOriginalComponents(mappingSystem, convert);
                        }
                    }

                    toBeInjected.Clear();
                }
            }
            finally
            {
                m_ToBeConverted.Clear();

                foreach (var transform in toBeDetached)
                {
                    transform.parent = null;
                }

                foreach (var go in conversionRoots)
                {
                    if (!IsConvertAndInject(go))
                    {
                        UnityObject.DestroyImmediate(go);
                    }
                }
            }
        }