public void ConvertGameObject_WithFilteredBuildSettings_ConversionDoesntRun()
        {
            var scene = SceneManager.GetActiveScene();
            var go    = CreateGameObject("Test Conversion");

            go.transform.localPosition = new Vector3(1, 2, 3);

            var config = BuildConfiguration.CreateInstance((bs) =>
            {
                bs.hideFlags = HideFlags.HideAndDontSave;
                bs.SetComponent(new ConversionSystemFilterSettings("Unity.Transforms.Hybrid"));
            });

            var conversionSettings = new GameObjectConversionSettings
            {
                DestinationWorld   = World,
                BuildConfiguration = config,
                Systems            = TestWorldSetup.GetDefaultInitSystemsFromEntitiesPackage(WorldSystemFilterFlags.GameObjectConversion).ToList()
            };

            GameObjectConversionUtility.ConvertScene(scene, conversionSettings);

            // We still expect to find an Entity, just with nothing on it, because
            // entities are eagerly created for every GameObject even if no components
            // get converted on them.
            EntitiesAssert.ContainsOnly(m_Manager, EntityMatch.Exact());
        }
        public void ConvertGameObject_HasOnlyTransform_ProducesEntityWithPositionAndRotation()
        {
            var scene = SceneManager.GetActiveScene();
            var go    = CreateGameObject("Test Conversion");

            go.transform.localPosition = new Vector3(1, 2, 3);

            using (var blobAssetStore = new BlobAssetStore())
            {
                var settings = GameObjectConversionSettings.FromWorld(World, blobAssetStore);
                GameObjectConversionUtility.ConvertScene(scene, settings);

                EntitiesAssert.ContainsOnly(m_Manager,
                                            EntityMatch.Exact(
                                                new Translation {
                    Value = new float3(1, 2, 3)
                },
                                                new Rotation {
                    Value = quaternion.identity
                },
                                                new LocalToWorld {
                    Value = go.transform.localToWorldMatrix
                }));
            }
        }
        public void ConvertGameObject_WithFilteredBuildSettings_ConversionDoesntRun()
        {
            var scene = SceneManager.GetActiveScene();
            var go    = CreateGameObject("Test Conversion");

            go.transform.localPosition = new Vector3(1, 2, 3);

            var bs = ScriptableObject.CreateInstance <BuildSettings>();

            bs.hideFlags = HideFlags.HideAndDontSave;

            bs.SetComponent(new ConversionSystemFilterSettings("Unity.Transforms.Hybrid"));

            var settings = new GameObjectConversionSettings
            {
                DestinationWorld = World,
                BuildSettings    = bs
            };

            GameObjectConversionUtility.ConvertScene(scene, settings);

            // We still expect to find an Entity, just with nothing on it, because
            // entities are eagerly created for every GameObject even if no components
            // get converted on them.
            EntitiesAssert.ContainsOnly(m_Manager, EntityMatch.Exact());
        }
        static void CheckAgainstFullConversion(World destinationWorld)
        {
            var dstEntityManager = destinationWorld.EntityManager;

            using (var fullConversionWorld = new World("FullConversion"))
            {
                using (var blobAssetStore = new BlobAssetStore())
                {
                    var conversionSettings = GameObjectConversionSettings.FromWorld(fullConversionWorld, blobAssetStore);
                    conversionSettings.ConversionFlags = ConversionFlags;

                    GameObjectConversionUtility.ConvertScene(SceneManager.GetActiveScene(), conversionSettings);

                    const EntityManagerDifferOptions options =
                        EntityManagerDifferOptions.IncludeForwardChangeSet |
                        EntityManagerDifferOptions.ValidateUniqueEntityGuid;

                    using (var blobAssetCache = new BlobAssetCache(Allocator.TempJob))
                    {
                        EntityDiffer.PrecomputeBlobAssetCache(fullConversionWorld.EntityManager, EntityManagerDiffer.EntityGuidQueryDesc, blobAssetCache);
                        using (var changes = EntityDiffer.GetChanges(
                                   dstEntityManager,
                                   fullConversionWorld.EntityManager,
                                   options,
                                   EntityManagerDiffer.EntityGuidQueryDesc,
                                   blobAssetCache,
                                   Allocator.TempJob
                                   ))
                        {
                            Assert.IsFalse(changes.AnyChanges, "Full conversion and incremental conversion do not match!");
                        }
                    }
                }
            }
        }
 public static void ConvertSceneAndApplyDiff(Scene scene, World previousStateShadowWorld, World dstEntityWorld)
 {
     using (var cleanConvertedEntityWorld = new World("Clean Entity Conversion World"))
     {
         GameObjectConversionUtility.ConvertScene(scene, cleanConvertedEntityWorld, true);
         WorldDiffer.DiffAndApply(cleanConvertedEntityWorld, previousStateShadowWorld, dstEntityWorld);
     }
 }
        public void ConversionIgnoresMissingMonoBehaviour()
        {
            TestTools.LogAssert.Expect(LogType.Warning, new Regex("missing"));
            var scene = EditorSceneManager.OpenScene("Packages/com.unity.entities/Unity.Entities.Hybrid.Tests/MissingMonoBehaviour.unity");
            var world = new World("Temp");

            GameObjectConversionUtility.ConvertScene(scene, world);
            world.Dispose();
        }
Пример #7
0
        public void ConvertGameObject_HasOnlyTransform_ProducesEntityWithPositionAndRotation([Values] bool useDiffing)
        {
            // Prepare scene
            var scene = EditorSceneManager.NewScene(NewSceneSetup.EmptyScene);

            SceneManager.SetActiveScene(scene);

            var go = new GameObject("Test Conversion");

            go.transform.localPosition = new Vector3(1, 2, 3);

            // Convert
            if (useDiffing)
            {
                var shadowWorld = new World("Shadow");
                GameObjectConversionUtility.ConvertSceneAndApplyDiff(scene, shadowWorld, m_Manager.World);
                shadowWorld.Dispose();
            }
            else
            {
                GameObjectConversionUtility.ConvertScene(scene, m_Manager.World);
            }

            // Check
            var entities = m_Manager.GetAllEntities();

            Assert.AreEqual(1, entities.Length);
            var entity = entities[0];

            Assert.AreEqual(useDiffing ? 3 : 2, m_Manager.GetComponentCount(entity));
            Assert.IsTrue(m_Manager.HasComponent <Position>(entity));
            Assert.IsTrue(m_Manager.HasComponent <Rotation>(entity));
            if (useDiffing)
            {
                Assert.IsTrue(m_Manager.HasComponent <EntityGuid>(entity));
            }

            Assert.AreEqual(new float3(1, 2, 3), m_Manager.GetComponentData <Position>(entity).Value);
            Assert.AreEqual(quaternion.identity, m_Manager.GetComponentData <Rotation>(entity).Value);

            // Unload
            EditorSceneManager.UnloadSceneAsync(scene);
        }
Пример #8
0
        public override BuildStepResult RunBuildStep(BuildContext context)
        {
            var manifest    = context.BuildManifest;
            var settings    = GetRequiredComponent <DotsRuntimeBuildProfile>(context);
            var buildScenes = GetRequiredComponent <SceneList>(context);

            var exportedSceneGuids = new HashSet <Guid>();

            var originalActiveScene = SceneManager.GetActiveScene();

            void ExportSceneToFile(Scene scene, Guid guid)
            {
                var outputFile = settings.DataDirectory.GetFile(guid.ToString("N"));

                using (var exportWorld = new World("Export World"))
                {
                    var exportDriver = new TinyExportDriver(context, settings.DataDirectory);
                    exportDriver.DestinationWorld = exportWorld;
                    exportDriver.SceneGUID        = new Hash128(guid.ToString("N"));

                    SceneManager.SetActiveScene(scene);

                    GameObjectConversionUtility.ConvertScene(scene, exportDriver);
                    context.GetOrCreateValue <WorldExportTypeTracker>()?.AddTypesFromWorld(exportWorld);

#if EXPORT_TINY_SHADER
                    RenderSettingsConversion.ConvertRenderSettings(exportWorld.EntityManager);
#endif

                    WorldExport.WriteWorldToFile(exportWorld, outputFile);
                    exportDriver.Write(manifest);
                }

                manifest.Add(guid, scene.path, outputFile.ToSingleEnumerable());
            }

            foreach (var rootScenePath in buildScenes.GetScenePathsForBuild())
            {
                using (var loadedSceneScope = new LoadedSceneScope(rootScenePath))
                {
                    var thisSceneGuid = new Guid(AssetDatabase.AssetPathToGUID(rootScenePath));
                    if (exportedSceneGuids.Contains(thisSceneGuid))
                    {
                        continue;
                    }

                    ExportSceneToFile(loadedSceneScope.ProjectScene, thisSceneGuid);
                    exportedSceneGuids.Add(thisSceneGuid);

                    var thisSceneSubScenes = loadedSceneScope.ProjectScene.GetRootGameObjects()
                                             .Select(go => go.GetComponent <SubScene>())
                                             .Where(g => g != null && g);

                    foreach (var subScene in thisSceneSubScenes)
                    {
                        var guid = new Guid(subScene.SceneGUID.ToString());
                        if (exportedSceneGuids.Contains(guid))
                        {
                            continue;
                        }

                        var isLoaded = subScene.IsLoaded;
                        if (!isLoaded)
                        {
                            SubSceneInspectorUtility.EditScene(subScene);
                        }

                        var scene     = subScene.EditingScene;
                        var sceneGuid = subScene.SceneGUID;

                        ExportSceneToFile(scene, guid);

                        if (!isLoaded)
                        {
                            SubSceneInspectorUtility.CloseSceneWithoutSaving(subScene);
                        }
                    }
                }
            }

            SceneManager.SetActiveScene(originalActiveScene);

            return(Success());
        }
        void ApplyLiveLink(SubScene scene)
        {
            //Debug.Log("ApplyLiveLink: " + scene.SceneName);

            var streamingSystem = World.GetExistingManager <SubSceneStreamingSystem>();

            var isFirstTime = scene.LiveLinkShadowWorld == null;

            if (scene.LiveLinkShadowWorld == null)
            {
                scene.LiveLinkShadowWorld = new World("LiveLink");
            }


            using (var cleanConvertedEntityWorld = new World("Clean Entity Conversion World"))
            {
                // Unload scene
                //@TODO: We optimally shouldn't be unloading the scene here. We should simply prime the shadow world with the scene that we originally loaded into the player (Including Entity GUIDs)
                //       This way we can continue the live link, compared to exactly what we loaded into the player.
                if (isFirstTime)
                {
                    foreach (var s in scene._SceneEntities)
                    {
                        streamingSystem.UnloadSceneImmediate(s);
                        EntityManager.DestroyEntity(s);
                    }

                    var sceneEntity = EntityManager.CreateEntity();
                    EntityManager.SetName(sceneEntity, "Scene (LiveLink): " + scene.SceneName);
                    EntityManager.AddComponentObject(sceneEntity, scene);
                    EntityManager.AddComponentData(sceneEntity, new SubSceneStreamingSystem.StreamingState {
                        Status = SubSceneStreamingSystem.StreamingStatus.Loaded
                    });
                    EntityManager.AddComponentData(sceneEntity, new SubSceneStreamingSystem.IgnoreTag( ));

                    scene._SceneEntities = new List <Entity>();
                    scene._SceneEntities.Add(sceneEntity);
                }

                // Convert scene
                GameObjectConversionUtility.ConvertScene(scene.LoadedScene, scene.SceneGUID, cleanConvertedEntityWorld, GameObjectConversionUtility.ConversionFlags.AddEntityGUID | GameObjectConversionUtility.ConversionFlags.AssignName);

                var convertedEntityManager = cleanConvertedEntityWorld.GetOrCreateManager <EntityManager>();

                var liveLinkSceneEntity = scene._SceneEntities[0];

                /// We want to let the live linked scene be able to reference the already existing Scene Entity (Specifically SceneTag should point to the scene Entity after live link completes)
                // Add Scene tag to all entities using the convertedSceneEntity that will map to the already existing scene entity.
                convertedEntityManager.AddSharedComponentData(convertedEntityManager.UniversalGroup, new SceneTag {
                    SceneEntity = liveLinkSceneEntity
                });

                WorldDiffer.DiffAndApply(cleanConvertedEntityWorld, scene.LiveLinkShadowWorld, World);

                convertedEntityManager.Debug.CheckInternalConsistency();
                scene.LiveLinkShadowWorld.GetOrCreateManager <EntityManager>().Debug.CheckInternalConsistency();

                var group = EntityManager.CreateComponentGroup(typeof(SceneTag), ComponentType.Exclude <EditorRenderData>());
                group.SetFilter(new SceneTag {
                    SceneEntity = liveLinkSceneEntity
                });

                EntityManager.AddSharedComponentData(group, new EditorRenderData()
                {
                    SceneCullingMask = m_LiveLinkEditGameViewMask, PickableObject = scene.gameObject
                });

                group.Dispose();

                scene.LiveLinkDirtyID = GetSceneDirtyID(scene.LoadedScene);
                EditorUpdateUtility.EditModeQueuePlayerLoopUpdate();
            }
        }
Пример #10
0
    void LoadEntities()
    {
        //get the scene
        Scene entityScene = SceneManager.GetSceneByBuildIndex(1);

        //does that load into this world?
        //load into other scene test
        if (entityScene.IsValid())
        {
            //move wanted objects to entities scene
            SceneManager.MoveGameObjectToScene(objectsToEntities, entityScene);

            //get the bounds off all the objects being moved
            List <Bounds> boundsList = new List <Bounds>();
            for (int i = 0; i < objectsToEntities.transform.childCount; i++)
            {
                boundsList.Add(objectsToEntities.transform.GetChild(i).GetComponent <Collider>().bounds);
            }

            //remove the entities from the parent
            objectsToEntities.transform.DetachChildren();

            //move base object back to scene
            SceneManager.MoveGameObjectToScene(objectsToEntities, SceneManager.GetSceneByBuildIndex(0));

            //convert everything in the entities scene to entities
            GameObjectConversionUtility.ConvertScene(entityScene, World.Active);

            //unload the entities scene now
            StartLoadScene(1, true);

            //attach the components we want to the bodies (if this is a body)
            if (!loadedBody)
            {
                loadedBody = true;

                AttachBodyComp(boundsList, 0);
                Debug.Log("first body");

                //load the second body now
                while (secondBody.transform.childCount > 0)
                {
                    secondBody.transform.GetChild(0).parent = objectsToEntities.transform;
                }

                //async load the scene
                StartLoadScene(1, false);
            }
            //static scene objects
            else if (!loadedSecondBody)
            {
                loadedSecondBody = true;

                AttachBodyComp(boundsList, 1);
                Debug.Log("second body");

                //load the scene now
                //deparent stairs
                while (stairs.transform.childCount > 0)
                {
                    //Debug.Log(x);
                    stairs.transform.GetChild(0).parent = objectsToEntities.transform;
                }

                //async load the scene
                StartLoadScene(1, false);
            }

            //SCENE IS LOADED LAST TO ENSURE THAT ALL MASS POINTS HAVE CORRECT IDS
            //load scene now
            else
            {
                AttachStaticComp(boundsList);
                Debug.Log("statics");
            }
        }
    }