Created
July 24, 2012 22:11
-
-
Save darktable/3173013 to your computer and use it in GitHub Desktop.
Unity3D: C# replacement for the python version of PostprocessBuildPlayer
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 UnityEngine; | |
using System.Collections; | |
using UnityEditor; | |
using UnityEditor.Callbacks; | |
using System.IO; | |
public class PostprocessBuildPlayer : ScriptableObject { | |
[PostProcessBuild] | |
static void OnPostprocessBuildPlayer(BuildTarget target, string buildPath) { | |
string editorPath = Path.GetFullPath(Path.GetDirectoryName(AssetDatabase.GetAssetPath(MonoScript.FromScriptableObject(ScriptableObject.CreateInstance<PostprocessBuildPlayer>())))); | |
if (!Directory.Exists(editorPath)) { | |
Debug.LogError("No directory at: " + editorPath); | |
return; | |
} | |
if (!Directory.Exists(buildPath)) { | |
Debug.LogError("No directory at: " + buildPath); | |
return; | |
} | |
var files = Directory.GetFiles(editorPath, "*.*", SearchOption.TopDirectoryOnly); | |
files = System.Array.FindAll<string>(files, (x) => { | |
var name = Path.GetFileName(x).ToLower(); | |
return name.StartsWith("postprocessbuildplayer_") && !name.EndsWith("meta"); | |
}); | |
if (files.Length == 0) { | |
Debug.LogError("No postprocess scripts at: " + editorPath); | |
return; | |
} | |
var args = new string[] { | |
buildPath, | |
target.ToString() | |
}; | |
foreach (var file in files) { | |
Debug.Log("executing: " + file); | |
using (var process = new System.Diagnostics.Process()) { | |
process.StartInfo.FileName = file; | |
process.StartInfo.Arguments = string.Join(" ", args); | |
process.StartInfo.RedirectStandardError = true; | |
process.StartInfo.UseShellExecute = false; | |
process.Start(); | |
string error = process.StandardError.ReadToEnd(); | |
process.WaitForExit(); | |
if (process.ExitCode != 0) { | |
Debug.LogError(process.ExitCode + " : " + error); | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for sharing the script. I wonder if you are using the same Apache license on this as your other gist.