Unity3d import picture automatically modifies texture type to Sprite (2D and UI) and set Packing tag as folder name

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.