Unity3d Ngui Atlas cut into pictures
Sometimes use Ngui to do the atlas, then the original image is not necessary to put into the unity3d, seriously affect the speed of unity3d. But suddenly the right side wants to get the picture out. Of course Ngui is provided with a single picture in the gallery save, but if the picture is too many, compare time, so with Python wrote a cut the image of the tool code as follows:
Python environment: 2.7 test pass, need to rely on image Library
Ngui Version: 3.7
#coding: Utf-8#unity Atlas cut into Png#author:wiker yong#date:2015-07-08import osimport sysimport argparseimport Imagedef Middle (str= ", left=", right= "): # Print Str.index (Right,str.index (left) +1) return Str[str.index (left) +len (left): St R.find (Right,str.find (left) +1)]parser = Argparse. Argumentparser (description= ' Unity Atlas cut to PNGs ') parser.add_argument ("-F", dest= ' file ', help= ' cut prefab,no ext Name ') parser.add_argument ("-P", dest= ' path ', help= ' Output path ') args = Parser.parse_args () out_path= "if args.path! = None and not Os.path.exists (Args.path): Os.makedirs (args.path) Out_path = args.pathif Args.file = = NONE:PARSER.P Rint_help () sys.exit (0) Prefab_path = args.filepngprefab_file = open (prefab_path+ '. Prefab ') Pngname= ' x=0y=0w=0h= 0while 1:line= prefab_file.readline () if not line:break; If Line.startswith ('-Name: '): Pngname=middle (line, '-Name: ', ' \ r \ n ') if Line.startswith (' x: '): X=int (Middle (line, ' x: ', ' \ r \ n ')) if LINE.STARTSWith (' y: '): Y=int (Middle (line, ' Y: ', ' \ r \ n ')) if Line.startswith (' width: '): W=int (Middle (line , ' width: ', ' \ r \ n ')) if Line.startswith (' Height: '): H=int (Middle (line, ' Height: ', ' \ r \ n ')) PRI NT Pngname,x,y,w,h img = Image.open (prefab_path+ '. png ') region = (x,y,w+x,h+y) cropimg=img.crop (Regio N) cropimg.save (out_path+ '/' +pngname+ '. png ')
Follow up the whole Unity Anti-compilation, restore to the picture, please pay attention!
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Unity3d Ngui Atlas cut into pictures