Created
November 10, 2020 12:23
-
-
Save baba-s/9cd771f587620a07dc301a7401e46f03 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.IO; | |
using UnityEditor; | |
using UnityEditor.Build; | |
using UnityEditor.Build.Reporting; | |
namespace Kogane.Internal | |
{ | |
internal sealed class ActiveScriptCompilationDefinesWriter : | |
IPreprocessBuildWithReport, | |
IPostprocessBuildWithReport | |
{ | |
//============================================================================== | |
// 定数 | |
//============================================================================== | |
private static readonly string FILE_PATH = "Assets/Resources/active_script_compilation_defines.txt"; | |
private static readonly string DIRECTORY = Path.GetDirectoryName( FILE_PATH ); | |
//============================================================================== | |
// 変数 | |
//============================================================================== | |
private bool m_isReleaseBuild; | |
//============================================================================== | |
// プロパティ | |
//============================================================================== | |
public int callbackOrder => 0; | |
//============================================================================== | |
// 関数 | |
//============================================================================== | |
/// <summary> | |
/// ビルドが開始する前に呼び出されます | |
/// </summary> | |
public void OnPreprocessBuild( BuildReport report ) | |
{ | |
var summary = report.summary; | |
m_isReleaseBuild = !summary.options.HasFlag( BuildOptions.Development ); | |
if ( m_isReleaseBuild ) return; | |
if ( !Directory.Exists( DIRECTORY ) ) | |
{ | |
Directory.CreateDirectory( DIRECTORY ); | |
} | |
var contents = string.Join | |
( | |
"\n", | |
EditorUserBuildSettings.activeScriptCompilationDefines | |
); | |
File.WriteAllText( FILE_PATH, contents ); | |
AssetDatabase.ImportAsset( FILE_PATH ); | |
} | |
/// <summary> | |
/// ビルドが成功した後に呼び出されます | |
/// </summary> | |
public void OnPostprocessBuild( BuildReport report ) | |
{ | |
if ( m_isReleaseBuild ) return; | |
AssetDatabase.DeleteAsset( FILE_PATH ); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment