Running a python/shell script from the UnityEditor

Running a python/shell script from the UnityEditor

onedayitwillmake No Comment

While working on your game, sometimes you develop little python or shell scripts that help along the process, and it’d be nice to run them from the editor.
Or better yet, during your automated build process, have it call out to this from within Unity.

It’s actually quite simple, and you can even capture the output into the editor.

[MenuItem("MyGame/Downscale Reference Textures")]
public static void DownscaleRefTextures() {
        // using System.Diagnostics;
    Process p = new Process();
    p.StartInfo.FileName = "python";
    p.StartInfo.Arguments = "";    
        // Pipe the output to itself - we will catch this later
    p.StartInfo.CreateNoWindow = true;
       // Where the script lives
    p.StartInfo.WorkingDirectory = Application.dataPath+"/SpriteCollections/"; 
    p.StartInfo.UseShellExecute = false;
        // Read the output - this will show is a single entry in the console - you could get  fancy and make it log for each line - but thats not why we're here
    UnityEngine.Debug.Log( p.StandardOutput.ReadToEnd() );

Leave a Reply