[Unity Notes] how to change the compression format of resources corresponding to Texture2D in Unity Editor, and save it, unitytexture2d

Source: Internet
Author: User

[Unity Notes] how to change the compression format of resources corresponding to Texture2D in Unity Editor, and save it, unitytexture2d


There were a lot of pitfalls (almost one afternoon) about storage ). Here is an additional description. If it is only used for the next time, you can use the UnityEditor. compressTexture method to modify the compression format, but this method is restored after the project is re-opened.

 

To modify the Format of Texture2D, you must modify ImportSettings in Texture2D and the TextureImporterFormat. The Code is as follows:

  Texture2D t2D = (Texture2D) AssetDatabase.LoadAssetAtPath(t2D_path, typeof(Texture2D));
  TextureImporter ti = (TextureImporter)TextureImporter.GetAtPath(AssetDatabase.GetAssetPath(t2D));  ti.textureFormat = changeTextureImporterFormat;

 

A t2D object is a read-in Texture2D object. For details about TextureImporterFormat, refer to the official Unity api. The link is as follows:

Http://docs.unity3d.com/ScriptReference/TextureImporterFormat.html

After ImporterFormat is changed, be sure to re-Import Texture2D !! Otherwise, the format conversion cannot be saved. Even if it is correct at the time, the changes will be restored after the project is re-opened. The re-Import method is as follows:

AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(t2D));

In this way, the compression format is changed and the project will not be restored after it is re-opened.



I hope to help students in need and try to step on them as little as possible.


How can I use global variables to save the website address of the resource server during Unity3D dynamic loading? It seems that everything I write is wrong. If I write an IP address wrong

The problem details are too messy.

When Unity3D is enabled in Win8, Unity Editor stops working.

The biggest problem with Unity is that it often crashes, but unity engineers are solving it. Unity occupies a large amount of resources.

Related Article

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.