Unity3d's new UI system has brought us a lot of convenience, but also added a little bit of trouble. Each time you import pictures from your computer to Unity3d you need to manually set texture type to Sprite (2D and UI) and set Packing Tag. For pictures that need to be packaged as an atlas, we typically put them in a folder. Based on the above, we can make the Packing Tag of the picture automatically set to the name of the folder.
Transfer from Http://blog.csdn.net/huutu http://www.thisisgame.com.cn
Unity3d provides a callback function for resource import, and we can use Assetpostprocessor to perform some of our own processing before and after the Unity3d processing the image.
Transfer from Http://blog.csdn.net/huutu http://www.thisisgame.com.cn
Here, we first modify its Texture Type and Packing Tag before the image is Unity3d processed.
Transfer from Http://blog.csdn.net/huutu http://www.thisisgame.com.cn
You can refer to Unity3d official documentation for details.
Http://docs.unity3d.com/ScriptReference/AssetPostprocessor.OnPreprocessTexture.html
/************************** * file name: AutoSetTextureUISprite.cs; * File Description: Import picture resources to unity, automatically modified to UI 2D Sprite, automatically set the packaging tag folder name; * Date Created: 2015/05/04; * Author: Chen Peng; /using unityengine;using system.collections;using Unityeditor;public class autosettextureuisprite:assetpostprocessor { void onpreprocesstexture () { //auto set type; Textureimporter Textureimporter = (textureimporter) assetimporter; Textureimporter.texturetype=textureimportertype.sprite; Automatically set up packaging tag; String dirName = System.IO.Path.GetDirectoryName (Assetpath); Debug.Log ("Import--- " +dirname); String folderstr = System.IO.Path.GetFileName (dirName); Debug.Log ("Set Packing Tag--- " +folderstr); Textureimporter.spritepackingtag = Folderstr; }}
Put the above code file in the Editor folder (not the rules, just the habit).
Then drag a picture from your computer into Project view and you can see that the picture is automatically modified.
Transfer from Http://blog.csdn.net/huutu http://www.thisisgame.com.cn
Transfer from Http://blog.csdn.net/huutu http://www.thisisgame.com.cn
Sample Download:
Http://pan.baidu.com/s/1dDcZigT
Unity3d import picture automatically modifies texture type to Sprite (2D and UI) and set Packing tag as folder name