public static Entity ConvertGameObjectHierarchy(GameObject root, GameObjectConversionSettings settings)
        {
            using (s_ConvertScene.Auto())
            {
                Entity convertedEntity;
                using (var conversionWorld = CreateConversionWorld(settings))
                {
                    var mappingSystem = conversionWorld.GetExistingSystem <GameObjectConversionMappingSystem>();

                    using (s_CreateEntitiesForGameObjects.Auto())
                        mappingSystem.AddGameObjectOrPrefab(root);

                    Convert(conversionWorld);

                    convertedEntity = mappingSystem.GetPrimaryEntity(root);

                    settings.ConversionWorldPreDispose?.Invoke(conversionWorld);

                    s_DestroyConversionWorld.Begin();
                }

                s_DestroyConversionWorld.End();
                return(convertedEntity);
            }
        }
        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);
            }
        }
Example #4
0
        internal static World CreateConversionWorld(GameObjectConversionSettings settings)
        {
            using (s_CreateConversionWorld.Auto())
            {
                var gameObjectWorld = new World($"GameObject -> Entity Conversion '{settings.DebugConversionName}'", WorldFlags.Live | WorldFlags.Conversion | WorldFlags.Staging);
                gameObjectWorld.CreateSystem <GameObjectConversionMappingSystem>(settings);

                var systemTypes   = settings.Systems ?? DefaultWorldInitialization.GetAllSystems(WorldSystemFilterFlags.GameObjectConversion);
                var includeExport = settings.GetType() != typeof(GameObjectConversionSettings);
                AddConversionSystems(gameObjectWorld, systemTypes.Concat(settings.ExtraSystems), includeExport);

                settings.ConversionWorldCreated?.Invoke(gameObjectWorld);

                return(gameObjectWorld);
            }
        }
        public static World ConvertIncrementalInitialize(Scene scene, GameObjectConversionSettings settings)
        {
            using (s_ConvertScene.Auto())
            {
                var gameObjectWorld = CreateConversionWorld(settings);

                using (s_CreateEntitiesForGameObjects.Auto())
                    gameObjectWorld.GetExistingSystem <GameObjectConversionMappingSystem>().CreateEntitiesForGameObjects(scene, gameObjectWorld);

                Convert(gameObjectWorld);

                gameObjectWorld.EntityManager.DestroyEntity(gameObjectWorld.EntityManager.UniversalQuery);

                return(gameObjectWorld);
            }
        }
        public static World ConvertIncrementalInitialize(Scene scene, GameObjectConversionSettings settings)
        {
            using (s_ConvertScene.Auto())
            {
                var conversionWorld = CreateConversionWorld(settings);
                using (var conversion = new Conversion(conversionWorld))
                {
                    using (s_CreateEntitiesForGameObjects.Auto())
                        conversion.MappingSystem.CreateEntitiesForGameObjects(scene);

                    Convert(conversionWorld);

                    conversionWorld.EntityManager.DestroyEntity(conversionWorld.EntityManager.UniversalQuery);
                }

                return(conversionWorld);
            }
        }
        internal static World CreateConversionWorld(GameObjectConversionSettings settings)
        {
            using (s_CreateConversionWorld.Auto())
            {
                var gameObjectWorld = new World("GameObject World");
                gameObjectWorld.CreateSystem <GameObjectConversionMappingSystem>(settings);

                var systemTypes = DefaultWorldInitialization.GetAllSystems(WorldSystemFilterFlags.GameObjectConversion);
                systemTypes.AddRange(settings.ExtraSystems);

                var includeExport = settings.GetType() != typeof(GameObjectConversionSettings);
                AddConversionSystems(gameObjectWorld, systemTypes, includeExport);

                settings.ConversionWorldCreated?.Invoke(gameObjectWorld);

                return(gameObjectWorld);
            }
        }
        public static void ConvertScene(Scene scene, GameObjectConversionSettings settings)
        {
            using (s_ConvertScene.Auto())
            {
                using (var conversionWorld = CreateConversionWorld(settings))
                    using (var conversion = new Conversion(conversionWorld))
                    {
                        using (s_CreateEntitiesForGameObjects.Auto())
                            conversion.MappingSystem.CreateEntitiesForGameObjects(scene);

                        Convert(conversionWorld);

                        settings.ConversionWorldPreDispose?.Invoke(conversionWorld);

                        s_DestroyConversionWorld.Begin();
                    }
                s_DestroyConversionWorld.End();
            }
        }
        public static void ConvertScene(Scene scene, GameObjectConversionSettings settings)
        {
            using (s_ConvertScene.Auto())
            {
                using (var conversionWorld = CreateConversionWorld(settings))
                {
                    using (s_CreateEntitiesForGameObjects.Auto())
                    {
                        var mappingSystem = conversionWorld.GetExistingSystem <GameObjectConversionMappingSystem>();
                        mappingSystem.CreateEntitiesForGameObjects(scene, conversionWorld);
                    }

                    Convert(conversionWorld);

                    settings.ConversionWorldPreDispose?.Invoke(conversionWorld);

                    s_DestroyConversionWorld.Begin();
                }
                s_DestroyConversionWorld.End();
            }
        }
Example #10
0
        internal static World CreateConversionWorld(GameObjectConversionSettings settings, Scene scene = default)
        {
            using (s_CreateConversionWorld.Auto())
            {
                var gameObjectWorld = new World($"GameObject -> Entity Conversion '{settings.DebugConversionName}'", WorldFlags.Live | WorldFlags.Conversion | WorldFlags.Staging);
                var mappingSystem   = new GameObjectConversionMappingSystem(settings);
                gameObjectWorld.AddSystem(mappingSystem);
                if (mappingSystem.IsLiveLink)
                {
                    mappingSystem.PrepareForLiveLink(scene);
                }

                var systemTypes = settings.Systems ?? DefaultWorldInitialization.GetAllSystems(settings.FilterFlags);

                var includeExport = settings.SupportsExporting;
                AddConversionSystems(gameObjectWorld, systemTypes.Concat(settings.ExtraSystems), includeExport, mappingSystem.IsLiveLink);

                settings.ConversionWorldCreated?.Invoke(gameObjectWorld);

                return(gameObjectWorld);
            }
        }
        internal static World CreateConversionWorld(GameObjectConversionSettings settings)
        {
            using (s_CreateConversionWorld.Auto())
            {
                var gameObjectWorld = new World($"GameObject -> Entity Conversion '{settings.DebugConversionName}'");
                gameObjectWorld.CreateSystem <GameObjectConversionMappingSystem>(settings);

                var systemTypes = DefaultWorldInitialization.GetAllSystems(WorldSystemFilterFlags.GameObjectConversion);
                if (settings.ExtraSystems.Length > 0)
                {
                    var systems = new List <Type>(systemTypes.Count + settings.ExtraSystems.Length);
                    systems.AddRange(systemTypes);
                    systems.AddRange(settings.ExtraSystems);
                    systemTypes = systems;
                }

                var includeExport = settings.GetType() != typeof(GameObjectConversionSettings);
                AddConversionSystems(gameObjectWorld, systemTypes, includeExport);

                settings.ConversionWorldCreated?.Invoke(gameObjectWorld);

                return(gameObjectWorld);
            }
        }
        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);
                    }
                }
            }
        }
Example #13
0
 public static World ConvertIncrementalInitialize(Scene scene, GameObjectConversionSettings settings)
 => InitializeIncrementalConversion(scene, settings);