Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save PoisonousJohn/a1d8c6ad204d7e5d88802fdf2da949a5 to your computer and use it in GitHub Desktop.
Save PoisonousJohn/a1d8c6ad204d7e5d88802fdf2da949a5 to your computer and use it in GitHub Desktop.
Copy iPad Pro icon 83.5@2x (167x167) to the XCode project if Unity doesn't support this yet
#!/usr/bin/python
# This script adds ipad pro icon to xcode project. Icon should be located at path Assets/Icons/size@Scalex
import argparse
import json
import os
import shutil
import sys
parser = argparse.ArgumentParser()
parser.add_argument("args", type=str, nargs='+')
arguments = parser.parse_args(sys.argv)
iconSize = 167
iconScale = 2
buildpath = arguments.args[1]
print 'Adding ipad pro icon'
iconsPath = '%s/Unity-iPhone/Images.xcassets/AppIcon.appiconset/' % buildpath
iconsContentsFilename = '%s/Contents.json' % iconsPath
print 'reading json at path: %s' % iconsContentsFilename
with open(iconsContentsFilename, 'r+') as iconsContents:
data = json.loads(iconsContents.read())
targetImage = None
searchSize = '%sx%s' % (iconSize / 2.0, iconSize / 2.0)
filename = '%s@%sx.png' % (searchSize, iconScale)
print 'Expected icon filename: %s' % filename
for image in data["images"]:
if image["size"] == searchSize:
targetImage = image
break
if targetImage is None:
targetImage = {}
data["images"].append(targetImage)
targetImage["filename"] = filename
targetImage["scale"] = '%sx' % iconScale
targetImage["idiom"] = 'ipad'
targetImage["size"] = '%sx%s' % (iconSize / 2.0, iconSize / 2.0)
resultJson = json.dumps(data, indent=4);
print 'result json: \n%s' % resultJson
iconsContents.seek(0)
iconsContents.write(resultJson)
shutil.copyfile('%s/Assets/Icons/%s' % (os.getcwd(), filename), '%s/%s' % (iconsPath, filename))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment