Example #1
0
        public override BuildStepResult RunBuildStep(BuildContext context)
        {
            m_TemporaryFileTracker = new TemporaryFileTracker();

            // Delete SubScenes build folder defensively (Eg. if unity crashes during build)
            var streamingAssetsSubscenes = "Assets/StreamingAssets/SubScenes";

            FileUtil.DeleteFileOrDirectory(streamingAssetsSubscenes);

            m_TemporaryFileTracker.CreateDirectory(streamingAssetsSubscenes);

            List <(string sourceFile, string destinationFile)> filesToCopy = new List <(string sourceFile, string destinationFile)>();

            void RegisterFileCopy(string sourceFile, string destinationFile)
            {
                filesToCopy.Add((sourceFile, destinationFile));
            }

            SubSceneBuildCode.PrepareAdditionalFiles(BuildContextInternals.GetBuildConfigurationGUID(context), type => GetRequiredComponent(context, type), RegisterFileCopy, Application.streamingAssetsPath, $"Library/SubsceneBundles");

            foreach (var(sourceFile, targetFile) in filesToCopy)
            {
                m_TemporaryFileTracker.TrackFile(targetFile);
                File.Copy(sourceFile, targetFile, true);
            }

            return(Success());
        }
        public override BuildStepResult RunBuildStep(BuildContext context)
        {
            m_TemporaryFileTracker = new TemporaryFileTracker();

            var sceneList = GetRequiredComponent <SceneList>(context);

            ResourceCatalogBuildCode.WriteCatalogFile(sceneList, m_TemporaryFileTracker.TrackFile(SceneInfoPath));

            return(Success());
        }
        public void Should_Delete_File_When_Starting_To_Track()
        {
            var existingFile = m_TestDirectory + "/Parent/Existing.txt";

            Directory.CreateDirectory(m_TestDirectory + "/Parent");
            File.WriteAllText(existingFile, "hello world");

            using (var tracker = new TemporaryFileTracker())
            {
                tracker.TrackFile(existingFile);
                FileAssert.DoesNotExist(existingFile);
            }
        }
        public void Should_Delete_Existing_File()
        {
            var existingFile = m_TestDirectory + "/Parent/Existing.txt";
            var newFile      = m_TestDirectory + "/Parent/File.txt";

            Directory.CreateDirectory(m_TestDirectory + "/Parent");
            File.Create(existingFile).Dispose();

            FileAssert.Exists(existingFile);

            using (var tracker = new TemporaryFileTracker())
            {
                tracker.TrackFile(existingFile, ensureDoesntExist: false);
                File.Create(tracker.TrackFile(newFile)).Dispose();

                FileAssert.Exists(existingFile);
                FileAssert.Exists(newFile);
            }

            FileAssert.DoesNotExist(existingFile);
            FileAssert.DoesNotExist(newFile);
        }
        public void Should_Create_And_Delete_Directory()
        {
            using (var trackerA = new TemporaryFileTracker())
            {
                trackerA.CreateDirectory(m_TestDirectory + "/Parent/Child");
                using (var trackerB = new TemporaryFileTracker())
                {
                    File.Create(trackerB.TrackFile(m_TestDirectory + "/Parent/Child/File.txt")).Dispose();
                    File.Create(trackerB.TrackFile(m_TestDirectory + "/Parent/File.txt")).Dispose();

                    DirectoryAssert.Exists(m_TestDirectory + "/Parent/Child");
                    FileAssert.Exists(m_TestDirectory + "/Parent/Child/File.txt");
                    FileAssert.Exists(m_TestDirectory + "/Parent/File.txt");
                }

                FileAssert.DoesNotExist(m_TestDirectory + "/Parent/Child/File.txt");
                FileAssert.DoesNotExist(m_TestDirectory + "/Parent/File.txt");
                DirectoryAssert.Exists(m_TestDirectory + "/Parent/Child");
            }

            DirectoryAssert.DoesNotExist(m_TestDirectory + "/Parent/Child");
            DirectoryAssert.DoesNotExist(m_TestDirectory + "/Parent");
            DirectoryAssert.Exists(m_TestDirectory);
        }
Example #6
0
        public override BuildStepResult RunBuildStep(BuildContext context)
        {
            m_TempFileTracker = new TemporaryFileTracker();
            var generalSettings = GetRequiredComponent <GeneralSettings>(context);
            var profile         = GetRequiredComponent <ClassicBuildProfile>(context);
            var sceneList       = GetRequiredComponent <SceneList>(context);

            if (profile.Target <= 0)
            {
                return(BuildStepResult.Failure(this, $"Invalid build target '{profile.Target.ToString()}'."));
            }

            if (profile.Target != EditorUserBuildSettings.activeBuildTarget)
            {
                return(BuildStepResult.Failure(this, $"{nameof(EditorUserBuildSettings.activeBuildTarget)} must be switched before {nameof(BuildStepBuildClassicLiveLink)} step."));
            }

            //any initial scenes that cannot be live linked must be added to the scenes list
            var embeddedScenes = new List <string>(sceneList.GetScenePathsToLoad().Where(path => !SceneImporterData.CanLiveLinkScene(path)));

            //if none of the startup scenes are embedded, add empty scene
            if (embeddedScenes.Count == 0)
            {
                embeddedScenes.Add(k_EmptyScenePath);
            }

            //add any additional scenes that cannot be live linked
            foreach (var path in sceneList.GetScenePathsForBuild())
            {
                if (!SceneImporterData.CanLiveLinkScene(path) && !embeddedScenes.Contains(path))
                {
                    embeddedScenes.Add(path);
                }
            }

            var outputPath = this.GetOutputBuildDirectory(context);

            if (!Directory.Exists(outputPath))
            {
                Directory.CreateDirectory(outputPath);
            }

            var buildPlayerOptions = new BuildPlayerOptions
            {
                scenes           = embeddedScenes.ToArray(),
                target           = profile.Target,
                locationPathName = Path.Combine(outputPath, generalSettings.ProductName + profile.GetExecutableExtension()),
                targetGroup      = UnityEditor.BuildPipeline.GetBuildTargetGroup(profile.Target),
                options          = BuildOptions.Development | BuildOptions.ConnectToHost
            };

            var sourceBuild = GetOptionalComponent <SourceBuildConfiguration>(context);

            if (sourceBuild.Enabled)
            {
                buildPlayerOptions.options |= BuildOptions.InstallInBuildFolder;
            }

            if (profile.Configuration == BuildType.Debug)
            {
                buildPlayerOptions.options |= BuildOptions.AllowDebugging;
            }

            if (UseAutoRunPlayer(context))
            {
                UnityEngine.Debug.Log($"Using BuildOptions.AutoRunPlayer, since RunStep is not provided for {profile.Target}");
                buildPlayerOptions.options |= BuildOptions.AutoRunPlayer;
            }

            var settings = BuildContextInternals.GetBuildConfiguration(context);

            if (AssetDatabase.TryGetGUIDAndLocalFileIdentifier(settings, out var guid, out long _))
            {
                using (var stream = new StreamWriter(m_TempFileTracker.TrackFile(k_BootstrapPath)))
                {
                    stream.WriteLine(guid);
                    stream.WriteLine(EditorAnalyticsSessionInfo.id);
                }
            }

            var report = UnityEditor.BuildPipeline.BuildPlayer(buildPlayerOptions);
            var result = new BuildStepResult(this, report);

            context.SetValue(report);
            return(result);
        }