Esempio n. 1
0
        public override BuildResult Run(BuildContext context)
        {
            var profile      = context.GetComponentOrDefault <DotsRuntimeBuildProfile>();
            var rootAssembly = context.GetComponentOrDefault <DotsRuntimeRootAssembly>();
            var targetName   = rootAssembly.MakeBeeTargetName(context.BuildConfigurationName);
            var workingDir   = DotsRuntimeRootAssembly.BeeRootDirectory;
            var outputDir    = new DirectoryInfo(BuildStepGenerateBeeFiles.GetFinalOutputDirectory(context, targetName));

            var result = BeeTools.Run(targetName, workingDir, context.BuildProgress);

            WorldExport.GetOrCreateLogDirectoryFrom(targetName).GetFile("BuildLog.txt").WriteAllText(result.Output);
            workingDir.GetFile("runbuild" + ShellScriptExtension()).UpdateAllText(result.Command);

            if (result.Failed)
            {
                return(context.Failure(result.Error));
            }

            if (!string.IsNullOrEmpty(rootAssembly.ProjectName))
            {
                var outputTargetFile = outputDir.GetFile(rootAssembly.ProjectName + profile.Target.ExecutableExtension);
                context.SetBuildArtifact(new DotsRuntimeBuildArtifact {
                    OutputTargetFile = outputTargetFile
                });
            }

            return(context.Success());
        }
Esempio n. 2
0
        public override BuildResult Run(BuildContext context)
        {
            var manifest           = context.BuildManifest;
            var buildConfiguration = BuildContextInternals.GetBuildConfiguration(context);
            var profile            = context.GetComponentOrDefault <DotsRuntimeBuildProfile>();
            var rootAssembly       = context.GetComponentOrDefault <DotsRuntimeRootAssembly>();
            var targetName         = rootAssembly.MakeBeeTargetName(context.BuildConfigurationName);
            var scenes             = context.GetComponentOrDefault <SceneList>();
            var firstScene         = scenes.GetScenePathsForBuild().FirstOrDefault();

            s_AssemblyCache.BaseAssemblies = rootAssembly.RootAssembly.asset;
            s_AssemblyCache.PlatformName   = profile.Target.UnityPlatformName;

            // Record any log errors/exceptions to be able to stop the build if any
            ExportConfigurationLogHandler logHandler = new ExportConfigurationLogHandler();

            logHandler.Hook();

            using (var tmpWorld = new World(ConfigurationScene.Guid.ToString()))
            {
                var dataDirInfo =
                    WorldExport.GetOrCreateDataDirectoryFrom(rootAssembly.StagingDirectory.Combine(targetName));
                var logDirectory = WorldExport.GetOrCreateLogDirectoryFrom(targetName);
                var subScenePath = WorldExport
                                   .GetOrCreateSubSceneDirectoryFrom(rootAssembly.StagingDirectory.Combine(targetName)).ToString();
                var outputDir = BuildStepGenerateBeeFiles.GetFinalOutputDirectory(context, targetName);

                var hasFilter = context.TryGetComponent <ConversionSystemFilterSettings>(out var conversionFilter);

                // Run configuration systems
                ConfigurationSystemGroup configSystemGroup = tmpWorld.GetOrCreateSystem <ConfigurationSystemGroup>();
                var systems = TypeCache.GetTypesDerivedFrom(typeof(ConfigurationSystemBase));
                foreach (var type in systems)
                {
                    if (hasFilter && !conversionFilter.ShouldRunConversionSystem(type))
                    {
                        continue;
                    }

                    ConfigurationSystemBase baseSys = (ConfigurationSystemBase)tmpWorld.GetOrCreateSystem(type);
                    baseSys.BuildContext     = context;
                    baseSys.AssemblyCache    = s_AssemblyCache;
                    baseSys.LogDirectoryPath = logDirectory.FullName;
                    configSystemGroup.AddSystemToUpdateList(baseSys);
                }

                configSystemGroup.SortSystems();
                configSystemGroup.Update();

                // Export configuration scene
                var writeEntitySceneSettings = new WriteEntitySceneSettings()
                {
                    Codec              = Codec.LZ4,
                    IsDotsRuntime      = true,
                    OutputPath         = subScenePath,
                    BuildAssemblyCache = s_AssemblyCache
                };
                var(decompressedSize, compressedSize) = EditorEntityScenes.WriteEntitySceneSection(
                    tmpWorld.EntityManager, ConfigurationScene.Guid, "0", null, writeEntitySceneSettings,
                    out var objectRefCount, out var objRefs, default);
Esempio n. 3
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());
        }
Esempio n. 4
0
        public override BuildStepResult RunBuildStep(BuildContext context)
        {
#if TINY_SCENE_DEP
            var manifest   = context.BuildManifest;
            var profile    = GetRequiredComponent <DotsRuntimeBuildProfile>(context);
            var scenes     = GetRequiredComponent <SceneList>(context);
            var firstScene = scenes.GetScenePathsForBuild().FirstOrDefault();

            using (var loadedSceneScope = new LoadedSceneScope(firstScene))
            {
                var projScene = loadedSceneScope.ProjectScene;

                var configGameObject = projScene.GetRootGameObjects()
                                       .FirstOrDefault((go => go && go.name == "Configuration"));

                using (var tmpWorld = new World(ConfigurationScene.Guid.ToString("N")))
                {
                    //var configEntity = CopyEntity(context.WorldManager.GetConfigEntity(), context.World, tmpWorld);
                    var em = tmpWorld.EntityManager;

                    Entity configEntity;
                    if (configGameObject != null)
                    {
                        var exportDriver = new TinyExportDriver(context, profile.DataDirectory);
                        exportDriver.DestinationWorld = tmpWorld;
                        exportDriver.SceneGUID        = new GUID(ConfigurationScene.Guid.ToString());

                        configEntity =
                            GameObjectConversionUtility.ConvertGameObjectHierarchy(configGameObject, exportDriver);
                        exportDriver.Write(manifest);
                    }
                    else
                    {
                        UnityEngine.Debug.LogWarning(
                            $"Couldn't find GameObject in scene named 'Configuration' for DOTS RT/Tiny Config -- generating default");

                        configEntity = em.CreateEntity();
                        em.AddComponentData(configEntity, DisplayInfo.Default);
                    }

                    em.AddComponentData(configEntity, new ConfigurationTag());

#if EXPORT_TINY_SHADER
                    if (profile.TypeCache.HasType(typeof(Unity.Tiny.Rendering.PrecompiledShaders)))
                    {
                        TinyShader.Export(em, profile);
                    }
#endif

                    var subScenes = projScene.GetRootGameObjects()
                                    .Select(go => go.GetComponent <SubScene>())
                                    .Where(g => g != null && g);

                    var startupScenes = em.AddBuffer <StartupScenes>(configEntity);

                    // Add this root scene to StartupScenes
                    var projSceneGuid = new GUID(AssetDatabase.AssetPathToGUID(projScene.path));
#if false
                    startupScenes.Add(new StartupScenes()
                    {
                        SceneReference = new Unity.Tiny.Scenes.SceneReference()
                        {
                            SceneGuid = new System.Guid(projSceneGuid.ToString())
                        }
                    });
#endif
                    // Add all our subscenes with AutoLoadScene to StartupScenes
                    // (technically not necessary?)
                    var subSceneGuids = subScenes
                                        .Where(s => s != null && s.SceneAsset != null && s.AutoLoadScene)
                                        .Select(s => new System.Guid(s.SceneGUID.ToString()));
                    foreach (var guid in subSceneGuids)
                    {
                        startupScenes.Add(new StartupScenes()
                        {
                            SceneReference = new Unity.Tiny.Scenes.SceneReference()
                            {
                                SceneGuid = guid
                            }
                        });
                    }

                    // Export configuration scene
                    var outputFile = profile.DataDirectory.GetFile(tmpWorld.Name);
                    context.GetOrCreateValue <WorldExportTypeTracker>()?.AddTypesFromWorld(tmpWorld);
                    WorldExport.WriteWorldToFile(tmpWorld, outputFile);

                    // Update manifest
                    manifest.Add(ConfigurationScene.Guid, ConfigurationScene.Path, outputFile.ToSingleEnumerable());

                    // Dump debug file
                    var debugFile =
                        new NPath(this.GetOutputBuildDirectory(context)).Combine("Logs/SceneExportLog.txt");
                    var debugAssets = manifest.Assets.OrderBy(x => x.Value)
                                      .Select(x => $"{x.Key.ToString("N")} = {x.Value}").ToList();

                    var debugLines = new List <string>();

                    debugLines.Add("::Exported Assets::");
                    debugLines.AddRange(debugAssets);
                    debugLines.Add("\n");

                    // Write out a separate list of types that we see in the dest world
                    // as well as all types
                    for (int group = 0; group < 2; ++group)
                    {
                        IEnumerable <TypeManager.TypeInfo> typesToWrite;
                        if (group == 0)
                        {
                            var typeTracker = context.GetOrCreateValue <WorldExportTypeTracker>();
                            if (typeTracker == null)
                            {
                                continue;
                            }
                            typesToWrite = typeTracker.TypesInUse.Select(t =>
                                                                         TypeManager.GetTypeInfo(TypeManager.GetTypeIndex(t)));
                            debugLines.Add($"::Exported Types (by stable hash)::");
                        }
                        else
                        {
                            typesToWrite = TypeManager.AllTypes;
                            debugLines.Add($"::All Types in TypeManager (by stable hash)::");
                        }

                        var debugTypeHashes = typesToWrite.OrderBy(ti => ti.StableTypeHash)
                                              .Where(ti => ti.Type != null).Select(ti =>
                                                                                   $"0x{ti.StableTypeHash:x16} - {ti.StableTypeHash,22} - {ti.Type.FullName}");

                        debugLines.AddRange(debugTypeHashes);
                        debugLines.Add("\n");
                    }

                    debugFile.MakeAbsolute().WriteAllLines(debugLines.ToArray());
                }
            }
#endif
            return(Success());
        }
Esempio n. 5
0
        public override BuildResult Run(BuildContext context)
        {
            var manifest               = context.BuildManifest;
            var rootAssembly           = context.GetComponentOrDefault <DotsRuntimeRootAssembly>();
            var buildScenes            = context.GetComponentOrDefault <SceneList>();
            var targetName             = rootAssembly.MakeBeeTargetName(context.BuildConfigurationName);
            var scenePaths             = buildScenes.GetScenePathsForBuild();
            var buildConfigurationGuid = context.BuildConfigurationAssetGUID;
            var dataDirectory          = WorldExport.GetOrCreateDataDirectoryFrom(rootAssembly.StagingDirectory.Combine(targetName));
            var logsDirectory          = WorldExport.GetOrCreateLogDirectoryFrom(targetName);

            var sceneGuids = scenePaths.SelectMany(scenePath =>
            {
                var guids = EditorEntityScenes.GetSubScenes(AssetDatabaseCompatibility.PathToGUID(scenePath)).ToList();
                guids.Add(AssetDatabaseCompatibility.PathToGUID(scenePath));
                return(guids);
            }).Distinct().ToList();

            //Save all unsaved scenes of the project first
            foreach (var guid in sceneGuids)
            {
                string scenePath = AssetDatabase.GUIDToAssetPath(guid.ToString());
                var    scene     = SceneManager.GetSceneByPath(scenePath);
                EditorSceneManager.SaveScene(scene);
            }

            var requiresRefresh       = false;
            var sceneBuildConfigGuids = new NativeArray <GUID>(sceneGuids.Count, Allocator.TempJob);

            for (int i = 0; i != sceneBuildConfigGuids.Length; i++)
            {
                sceneBuildConfigGuids[i] = SceneWithBuildConfigurationGUIDs.EnsureExistsFor(sceneGuids[i], new Hash128(buildConfigurationGuid), false, out var thisRequiresRefresh);
                requiresRefresh         |= thisRequiresRefresh;
            }
            if (requiresRefresh)
            {
                AssetDatabase.Refresh();
            }

            var artifactHashes = new NativeArray <UnityEngine.Hash128>(sceneGuids.Count, Allocator.TempJob);

            AssetDatabaseCompatibility.ProduceArtifactsRefreshIfNecessary(sceneBuildConfigGuids, typeof(SubSceneImporter), artifactHashes);

            bool succeeded = true;

            for (int i = 0; i != sceneBuildConfigGuids.Length; i++)
            {
                var sceneGuid    = sceneGuids[i];
                var artifactHash = artifactHashes[i];

                AssetDatabaseCompatibility.GetArtifactPaths(artifactHash, out var artifactPaths);

                List <FileInfo> exportedFiles     = new List <FileInfo>();
                bool            foundEntityHeader = false;
                foreach (var artifactPath in artifactPaths)
                {
                    var ext = Path.GetExtension(artifactPath).ToLower().Replace(".", "");
                    if (ext == EntityScenesPaths.GetExtension(EntityScenesPaths.PathType.EntitiesHeader))
                    {
                        foundEntityHeader = true;
                        var destinationFile = dataDirectory.FullName + Path.DirectorySeparatorChar + EntityScenesPaths.RelativePathFolderFor(sceneGuid, EntityScenesPaths.PathType.EntitiesHeader, -1);
                        new NPath(artifactPath).MakeAbsolute().Copy(new NPath(destinationFile).MakeAbsolute().EnsureParentDirectoryExists());
                        exportedFiles.Add(new FileInfo(destinationFile));
                    }
                    else if (ext == EntityScenesPaths.GetExtension(EntityScenesPaths.PathType.EntitiesBinary))
                    {
                        var destinationFile = dataDirectory.FullName + Path.DirectorySeparatorChar + EntityScenesPaths.RelativePathFolderFor(sceneGuid, EntityScenesPaths.PathType.EntitiesBinary, EntityScenesPaths.GetSectionIndexFromPath(artifactPath));
                        new NPath(artifactPath).MakeAbsolute().Copy(new NPath(destinationFile).MakeAbsolute().EnsureParentDirectoryExists());
                        exportedFiles.Add(new FileInfo(destinationFile));
                    }
                    else if (ext == EntityScenesPaths.GetExtension(EntityScenesPaths.PathType.EntitiesConversionLog))
                    {
                        var destinationFile = logsDirectory.FullName + Path.DirectorySeparatorChar + $"{sceneGuid}.{EntityScenesPaths.GetExtension(EntityScenesPaths.PathType.EntitiesConversionLog)}";
                        new NPath(artifactPath).MakeAbsolute().Copy(new NPath(destinationFile).MakeAbsolute().EnsureParentDirectoryExists());
                        var result = PrintConversionLogToUnityConsole(artifactPath);
                        if (result.HasError || result.HasException)
                        {
                            UnityEngine.Debug.LogError("Failed to export scene: " + Path.GetFileName(AssetDatabase.GUIDToAssetPath(sceneGuid.ToString())));
                            succeeded = false;
                        }
                    }
                    else if (new Hash128(ext).IsValid) //Asset files are exported as {artifactHash}.{assetguid}
                    {
                        var destinationFile = dataDirectory.FullName + Path.DirectorySeparatorChar + ext;
                        new NPath(artifactPath).MakeAbsolute().Copy(new NPath(destinationFile).MakeAbsolute().EnsureParentDirectoryExists());
                        exportedFiles.Add(new FileInfo(destinationFile));
                    }
                }

                if (!foundEntityHeader)
                {
                    Debug.LogError($"Failed to build EntityScene for '{AssetDatabaseCompatibility.GuidToPath(sceneGuid)}'.");
                    succeeded = false;
                }

                //UpdateManifest
                manifest.Add(new Guid(sceneGuid.ToString()), AssetDatabase.GUIDToAssetPath(sceneGuid.ToString()), exportedFiles);
            }

            var catalogPath = Path.Combine(dataDirectory.ToString(), SceneSystem.k_SceneInfoFileName);

            WriteCatalogFile(catalogPath, buildScenes);
            manifest.AddAdditionalFilesToDeploy(new FileInfo(catalogPath.ToString()));

            sceneBuildConfigGuids.Dispose();
            artifactHashes.Dispose();

            if (succeeded)
            {
                return(context.Success());
            }
            return(context.Failure($"Failed to export scenes"));
        }