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()); }
unsafe public override BuildStepResult RunBuildStep(BuildContext context) { m_TemporaryFileTracker = new TemporaryFileTracker(); var sceneList = GetRequiredComponent <SceneList>(context); var sceneInfos = sceneList.GetSceneInfosForBuild(); var builder = new BlobBuilder(Allocator.Temp); ref var root = ref builder.ConstructRoot <ResourceCatalogData>();
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); }
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); }
public override BuildStepResult RunBuildStep(BuildContext context) { m_TemporaryFileTracker = new TemporaryFileTracker(); var profile = GetRequiredComponent <ClassicBuildProfile>(context); if (profile.Target == UnityEditor.BuildTarget.NoTarget) { return(Failure($"Invalid build target '{profile.Target.ToString()}'.")); } if (profile.Target != EditorUserBuildSettings.activeBuildTarget) { return(Failure($"ActiveBuildTarget must be switched before the {nameof(BuildStepSubSceneBundles)} step.")); } var buildConfigurationGuid = new Hash128(BuildContextInternals.GetBuildConfigurationGUID(context)); var content = new UnityEditor.Build.Pipeline.BundleBuildContent(new AssetBundleBuild[0]); var sceneList = GetRequiredComponent <SceneList>(context); var visited = new HashSet <Hash128>(); foreach (var scenePath in sceneList.GetScenePathsForBuild()) { var sceneGuid = AssetDatabase.AssetPathToGUID(scenePath); var subSceneGuids = SceneMetaDataImporter.GetSubSceneGuids(sceneGuid); foreach (var subSceneGuid in subSceneGuids) { if (!visited.Add(subSceneGuid)) { continue; } var hash128Guid = EntityScenesPaths.CreateBuildConfigurationSceneFile(subSceneGuid, buildConfigurationGuid); content.CustomAssets.Add(new UnityEditor.Build.Pipeline.Interfaces.CustomContent { Asset = hash128Guid, Processor = SubSceneImporter.ConvertToBuild }); } } if (content.CustomAssets.Count == 0) { return(Success()); } var buildPath = Path.GetDirectoryName(EntityScenesPaths.GetLoadPath(new Hash128(), EntityScenesPaths.PathType.EntitiesUnityObjectReferences, 0)); // Delete SubScenes build folder defensively (Eg. if unity crashes during build) FileUtil.DeleteFileOrDirectory(buildPath); m_TemporaryFileTracker.CreateDirectory(buildPath); var group = UnityEditor.BuildPipeline.GetBuildTargetGroup(profile.Target); var parameters = new UnityEditor.Build.Pipeline.BundleBuildParameters(profile.Target, group, buildPath); parameters.BundleCompression = UnityEngine.BuildCompression.Uncompressed; var status = UnityEditor.Build.Pipeline.ContentPipeline.BuildAssetBundles(parameters, content, out UnityEditor.Build.Pipeline.Interfaces.IBundleBuildResults result); context.SetValue(result); var succeeded = status >= UnityEditor.Build.Pipeline.ReturnCode.Success; return(succeeded ? Success() : Failure($"BuildAssetBundles failed with status '{status}'.")); }
public override BuildStepResult RunBuildStep(BuildContext context) { m_tempFileTracker = new TemporaryFileTracker(); string output = "using Unity.Entities;\n" + "namespace Latios.PhysicsEngine.BurstPatch\n" + "{\n" + " class BurstPatchSystem : SubSystem\n" + " {\n" + " protected override void OnUpdate()\n" + " {\n" + " if (Enabled == true)\n" + " {\n" + " Enabled = false;\n" + " return;\n" + " }\n"; output += BuildJobInstances(out List <string> assembliesToReference); output += " }\n" + " }\n" + "}\n" + "\n"; //File.WriteAllText("Temp/LatiosPhysicsBurstPatchScript.cs", output); Directory.CreateDirectory("Assets/LatiosGenerated"); File.WriteAllText("Assets/LatiosGenerated/LatiosPhysicsBurstPatchScript.cs", output); WriteAssemblyDef("Assets/LatiosGenerated/Latios.Physics.BurstPatch.asmdef", assembliesToReference); AssetDatabase.ImportAsset("Assets/LatiosGenerated/Latios.Physics.BurstPatch.asmdef"); AssetDatabase.ImportAsset("Assets/LatiosGenerated/LatiosPhysicsBurstPatchScript.cs"); /* * //var builder = new AssemblyBuilder("Library/ScriptAssemblies/Latios.Physics.BurstPatch.dll", "Temp/LatiosPhysicsBurstPatchScript.cs"); * var builder = new AssemblyBuilder("Assets/LatiosGenerated/Latios.Physics.BurstPatch.dll", "Temp/LatiosPhysicsBurstPatchScript.cs"); * string debugOut = ""; * //foreach (var s in builder.defaultReferences) * // debugOut += $"{s}\n"; * //return Failure($"Default assemblies: {debugOut}"); * builder.additionalReferences = assembliesToReference.ToArray(); * * builder.buildFinished += Builder_buildFinished; * * if (!builder.Build()) * { * return Failure("Failed to start build of Latios.Physics.BurstPatch.dll"); * } * * while (builder.status != AssemblyBuilderStatus.Finished) * System.Threading.Thread.Sleep(10); * * if (m_buildErrors != 0) * { * return Failure($"Encountered {m_buildErrors} build errors during compilation of Latios.Physics.BurstPatch.dll: {m_firstBuildError}"); * } * //context.BuildManifest.Add(Guid.NewGuid(), "Library/ScriptAssemblies/Latios.Physics.BurstPatch.dll", * // new FileInfo[] { new FileInfo("Temp/LatiosPhysicsBurstPatchScript.cs") }); * AssetDatabase.ImportAsset("Assets/LatiosGenerated/Latios.Physics.BurstPatch.dll"); */ return(Success()); //return Failure("Not fully implemented yet"); }