diff --git a/Editor/Build/BuildProject.cs b/Editor/Build/BuildProject.cs index 265a587..c78f28a 100644 --- a/Editor/Build/BuildProject.cs +++ b/Editor/Build/BuildProject.cs @@ -189,6 +189,16 @@ private static void PerformBuild(string[] buildConfigs, BuildOptions options = B int successCount = 0; int failCount = 0; + // Save current script defines, build constants, etc. so we can restore them after build. + string currentDefines = PlayerSettings.GetScriptingDefineSymbolsForGroup(BuildTargetGroup.Standalone); + string buildConstantsPath = BuildConstantsGenerator.FindFile(); + string currentBuildConstantsFile = null; + if (!string.IsNullOrEmpty(buildConstantsPath)) + { + currentBuildConstantsFile = FileUtil.GetUniqueTempPathInProject(); + File.Copy(buildConstantsPath, currentBuildConstantsFile); + } + DateTime buildTime; PerformPreBuild(out buildTime); @@ -213,6 +223,14 @@ private static void PerformBuild(string[] buildConfigs, BuildOptions options = B PerformPostBuild(); + // Restore editor status. + PlayerSettings.SetScriptingDefineSymbolsForGroup(BuildTargetGroup.Standalone, currentDefines); + if (!string.IsNullOrEmpty(buildConstantsPath)) + { + File.Copy(currentBuildConstantsFile, buildConstantsPath, true); + File.Delete(currentBuildConstantsFile); + } + // Report success/failure. StringBuilder sb = new StringBuilder(); if (failCount == 0) diff --git a/Editor/BuildConstantsGenerator.cs b/Editor/BuildConstantsGenerator.cs index db38626..de89a6b 100644 --- a/Editor/BuildConstantsGenerator.cs +++ b/Editor/BuildConstantsGenerator.cs @@ -12,15 +12,8 @@ public static class BuildConstantsGenerator { public const string NONE = "None"; - public static void Generate( - DateTime buildTime, - string currentVersion = "", - BuildReleaseType currentReleaseType = null, - BuildPlatform currentBuildPlatform = null, - BuildArchitecture currentBuildArchitecture = null, - BuildDistribution currentBuildDistribution = null) + public static string FindFile() { - // Find the BuildConstants file. string[] fileSearchResults = Directory.GetFiles(Application.dataPath, "BuildConstants.cs", SearchOption.AllDirectories); string filePath = null; string desiredFilePath = string.Format("UnityBuild{0}BuildConstants.cs", Path.DirectorySeparatorChar); @@ -33,6 +26,20 @@ public static void Generate( } } + return filePath; + } + + public static void Generate( + DateTime buildTime, + string currentVersion = "", + BuildReleaseType currentReleaseType = null, + BuildPlatform currentBuildPlatform = null, + BuildArchitecture currentBuildArchitecture = null, + BuildDistribution currentBuildDistribution = null) + { + // Find the BuildConstants file. + string filePath = FindFile(); + if (string.IsNullOrEmpty(filePath)) { return;