Skip to content

Instantly share code, notes, and snippets.

@Knetic
Last active January 6, 2017 03:55
Show Gist options
  • Save Knetic/0ed46af56d38347cc8d4af7f7857add3 to your computer and use it in GitHub Desktop.
Save Knetic/0ed46af56d38347cc8d4af7f7857add3 to your computer and use it in GitHub Desktop.
fixed copy/paste error
#!/usr/bin/env python
# Invokes a build of this project's assets as a unitypackage.
# Working directory must be in the top-level of the project, i.e., "Assets" must be directly underneath cwd.
import sys
import os
import subprocess
from distutils.spawn import find_executable
# Determines a Unity editor executable that is available from the PATH.
# If none can be found, returns None.
def determineUnityExecutable():
possibleExecutables = ["Unity", "unityEditor"]
for executable in possibleExecutables:
actualExecutable = find_executable(executable)
if(actualExecutable != None):
return actualExecutable
return None
def main():
workingDirectory = os.getcwd()
baseDirectory = os.path.basename(os.path.normpath(workingDirectory))
executable = determineUnityExecutable()
if(executable == None):
print("Unable to find unity executable, make sure either 'Unity' or 'unityEditor' are available within your path.")
sys.exit(1)
# Shellout.
arguments = [
executable,
"-batchmode",
"-nographics",
"-quit",
"-projectPath",
workingDirectory,
"-exportPackage",
"Assets",
baseDirectory + ".unityPackage"
]
friendlyArguments = ' '.join(arguments)
print("Calling Unity: [" + friendlyArguments + "]")
statusCode = subprocess.call(arguments, shell=False, stdout=sys.stdout, stderr=sys.stderr)
if(statusCode != 0):
print("Call to unity failed with status code " + str(statusCode))
return statusCode
sys.exit(main())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment