Please forgive my lack of knowledge of the Mac, and the entire PostprocessBuildPlayer process -
I have two scripts - one from Agon, and one from the enhancement pack - that need to be merged.
Any assistance in merging these two would greatly be appriciated!
The Enhancement Pack one -
#!/usr/bin/perl
# Post Process Build Script
# for
# Unity iPhone Enhancement Pack
use File::Basename;
use Foundation;
...
`sleep 3; osascript -e \'tell application \"Finder\" to display dialog \"Enhancement Pack added! Ready to build in XCode!\" buttons \"OK\"\'`;
and the Agon One -
#!/usr/bin/env python
# Bumped with every new release of the AGON Online Unity plugin
agonUnityVersion = 41
import sys
import os
import os.path
import shutil
import distutils.dir_util
import fnmatch
from xml.dom import minidom
import subprocess
import zipfile
def main():
agonUnityVersionStringFileName = '/agonUnityVersionString.txt'
publishTarget = sys.argv[2]
if publishTarget == 'iPhone':
xcodeProjectRoot = sys.argv[1]
print 'Xcode project root: ' + xcodeProjectRoot
workingDir = os.getcwd() + '/Assets/Editor'
agonRootDir = '/AGON Online'
agonDataBundle = '/AgonData.bundle/'
agonDataBundleZipped = '/AgonData.zip'
agonPackageBundle = '/AgonPackage.bundle/'
print 'Starting AGON Online patch...'
# Sanity check
if os.path.exists(workingDir + '/AGON Online Files' + agonPackageBundle):
# Check for AGON version
newAgonDataPackage = True
versionFileExists = False
agonVersionFileFullPath = xcodeProjectRoot + agonRootDir + agonUnityVersionStringFileName
print 'Checking version of AgonData.bundle'
if os.path.exists(agonVersionFileFullPath):
versionFileExists = True
versionFile = open(agonVersionFileFullPath, 'r')
versionString = versionFile.readline()
version = convertStr(versionString)
if agonUnityVersion <= version:
print 'AgonData.bundle is up-to-date. Version is: ' + versionString
newAgonDataPackage = False
else:
print 'New AGON Unity version. Current version: ' + versionString + ', new version: ' + str(agonUnityVersion)
else:
print "AGON version file doesn't exist yet"
if newAgonDataPackage:
print 'New version of AGON found, copying resources...'
if os.path.exists(workingDir + '/AGON Online Files' + agonDataBundle):
# Remove the unzipped AgonData.bundle
shutil.rmtree(workingDir + '/AGON Online Files' + agonDataBundle)
if os.path.exists(xcodeProjectRoot + agonDataBundle):
# Remove the AgonData.bundle from the Unity Player project
shutil.rmtree(xcodeProjectRoot + agonDataBundle)
# Copy AGON source files
print 'Copying AGON Online source files...'
shutil.copytree(workingDir + '/AGON Online Files/Classes/', xcodeProjectRoot + agonRootDir + '/Classes/')
# Copy the AGON library
print 'Copying AGON Online library...'
shutil.copytree(workingDir + '/AGON Online Files/lib/', xcodeProjectRoot + agonRootDir + '/lib/')
# Copy the AGON data bundle
print 'Copying AGON Online data bundle...'
decompressZip(workingDir + '/AGON Online Files' + agonDataBundleZipped, workingDir + '/AGON Online Files/')
shutil.copytree(workingDir + '/AGON Online Files' + agonDataBundle, xcodeProjectRoot + agonDataBundle)
shutil.rmtree(workingDir + '/AGON Online Files' + agonDataBundle)
# Copy the game package bundle
print 'Copying game package bundle...'
if os.path.exists(xcodeProjectRoot + agonPackageBundle):
shutil.rmtree(xcodeProjectRoot + agonPackageBundle)
shutil.copytree(workingDir + '/AGON Online Files' + agonPackageBundle, xcodeProjectRoot + agonPackageBundle)
# If the version file didn't exist, create one
if not versionFileExists:
print 'Creating AGON Unity version file...'
versionFile = open(agonVersionFileFullPath, 'w')
versionFile.write(str(agonUnityVersion))
versionFile.flush()
versionFile.close()
# Patch the project to include the necessary settings and files
patchDir = workingDir + '/AGON Online Files/Xcode'
patch_project(patchDir, xcodeProjectRoot)
else:
print "AgonPackage.bundle is missing from your /Assets/Editor/AGON Online Files/ folder. Please download your game package from your game's page on the web management site ([url]http://devdb.agon-online.com/developer[/url]) and place it in that folder."
print 'Cannot continue AGON Online patch until the AgonPackage.bundle is available.'
cmd = """/usr/bin/osascript -e 'tell application "Xcode"' -e 'display dialog "AGON Online notice:\nAgonPackage.bundle is missing from /Assets/Editor/AGON Online Files." buttons {"Ok"}' -e 'end tell'"""
os.system(cmd)
return
def patch_project(patchDir, xcodeProjectRoot):
print 'Patching XCode project file...'
cmd = '/usr/bin/osascript patchXCodeProject.scpt "%s"' % xcodeProjectRoot
retcode = subprocess.call(cmd, shell=True, cwd=patchDir)
if retcode < 0:
print >> sys.stderr, "Child was terminated by signal", -retcode
return
print 'Patching AppController.mm'
appControllerPath = xcodeProjectRoot + '/Classes/AppController.mm'
appControllerFile = open(appControllerPath, 'r')
lines = appControllerFile.readlines()
newLines = []
hasInclude = False
needPatching = False
firstLine = True
for line in lines:
if firstLine and not line == '#import "../AGON Online/Classes/AGON.h"\n':
newLines.append('#import "../AGON Online/Classes/AGON.h"\n')
newLines.append('#import "../AGON Online/Classes/UnityAgon.h"\n')
firstLine = False
needPatching = True
if not needPatching:
print 'Already patched, skipping...'
break
newLines.append(line)
if line == """\tUnityInitApplication(appPath);\n""":
newLines.append("\t[UnityAgon create];\n")
if line == """\tUnityCleanup();\n""":
newLines.append('\t[UnityAgon destroy];\n')
if line == """\t_window = [[UIWindow alloc] initWithFrame:rect];\n""":
newLines.append('\tUnityAgonViewController* v = [[UnityAgonViewController alloc] init];\n')
newLines.append('\t[_window addSubview:v.view];\n')
if line == """void UnityInputProcess();\n""":
newLines.append('\n')
newLines.append('@interface UnityAgonViewController : UIViewController {}\n')
newLines.append('@end\n')
newLines.append('@implementation UnityAgonViewController\n')
newLines.append('- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {\n')
newLines.append('\treturn AgonShouldAutorotateToInterfaceOrientation(interfaceOrientation);\n')
newLines.append('}\n')
newLines.append('@end\n')
appControllerFile.close()
if needPatching:
appControllerFile = open(appControllerPath, 'w')
appControllerFile.writelines(newLines)
appControllerFile.flush()
appControllerFile.close()
print 'Completed AGON Online patch'
def decompressZip(file, dir):
zf = zipfile.ZipFile(file)
# Create directory structure to house files
makeDirs(file, zf)
# Extract files to directory structure
for i, name in enumerate(zf.namelist()):
if not name.endswith('/'):
fullPath = os.path.join(dir, name)
outfile = open(fullPath, 'wb')
outfile.write(zf.read(name))
outfile.flush()
outfile.close()
def makeDirs(file, zf):
isdir = os.path.isdir
join = os.path.join
norm = os.path.normpath
split = os.path.split
dirname = os.path.dirname
for each in zf.namelist():
if not each.endswith('/'):
root, name = split(each)
absDirRoot = dirname(file) + '/'
directory = norm(absDirRoot + root)
if not isdir(directory):
os.makedirs(directory)
def convertStr(s):
"""Convert string to int"""
ret = 0
try:
ret = int(s)
except ValueError:
print 'Invalid version number string in AGON version file: ' + s
return ret
if __name__ == '__main__':
main()