Unity uses code to modify texture properties, one-click to generate Sprites

Source: Internet
Author: User

Complaining: Unity infrastructure is not my strong point, I mainly do the engine and project combat, how to use the unity engine to efficiently realize the function of the game is my main research direction.

But after taking office has been doing UI, tuning components, layout, not Kai Sen, not Kai Sen!

Today, ah light to share is a small tool, write their own. Because the company's UI is rich, a variety of basemaps and so many. In order not to let the picture resources repeat for reasons such as importing pictures

When you need a picture from the art resources to take, one by one to add to the project. Then, as usual, modify the picture to make it into a sprite.

Add a picture to a project resource by default this is the case,

The Required property setting is this:

If you manually adjust it, it's too much trouble, click Select, apply options, and then I write a gadget right away. It's good to write code in C #, but.

I can only write in Lua right now.

Now share this gadget with everyone.

Today's mood so down, do not want to comment. The code is simple, which is to set some properties. You can try to modify to achieve your desired requirements.

usingUnityengine;usingSystem.Collections;usingUnityeditor;usingSystem.IO;/// <summary>///This function is automatically processed for the image resource, set type, format, etc./// </summary> Public classTextureeditor {StaticObject targetobj; [MenuItem ("Textureedit/edit")]    Static voidedittexture () {targetobj= Selection.activeobject;//This function will give you the object you selected.        if(Targetobj && Targetobj isTexture) {            stringPath =Assetdatabase.getassetpath (targetobj); Textureimporter Texture= Assetimporter.getatpath (path) asTextureimporter; Texture.texturetype=Textureimportertype.sprite; Texture.spritepixelsperunit=1; Texture.filtermode=filtermode.trilinear; Texture.mipmapenabled=false; Texture.textureformat=Textureimporterformat.automatictruecolor;                    Assetdatabase.importasset (path); }    }    }

After you finish writing, you may need to reopen the project, and you'll see this stuff:

Select the picture and click Edit to see the effect yourself!

Unity uses code to modify texture properties, one-click to generate Sprites

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.