[Unity3D self-learning Record] uses code to modify image attributes (Inspector) and unity3dinspector

Source: Internet
Author: User

[Unity3D self-learning Record] uses code to modify image attributes (Inspector) and unity3dinspector

It is troublesome to package resources for a long time and change the image attributes for each import. Therefore, we have been searching for a one-click modification and packaging method.

I finally found it.

I believe everyone can understand the code as needed.

Core part:

TextureImporter ti = (TextureImporter)TextureImporter.GetAtPath(AssetDatabase.GetAssetPath(obj));            ti.textureType = TextureImporterType.GUI;            ti.filterMode = FilterMode.Point;            ti.textureFormat = TextureImporterFormat.RGBA32;


The Code is as follows:

Using UnityEngine; using System. collections; using UnityEditor; public class AssetBundleTest: Editor {[MenuItem ("Creat/CreateAssetBunldes")] public static void CreateAssetBunldes () {Object [] SelectedAsset = Selection. getFiltered (typeof (Object), SelectionMode. deepAssets); foreach (Object obj in SelectedAsset) {TextureImporter ti = (TextureImporter) TextureImporter. getAtPath (AssetDatabase. getAssetPath (obj); ti. textureType = TextureImporterType. GUI; ti. filterMode = FilterMode. point; ti. textureFormat = TextureImporterFormat. RGBA32; string targetPath = Application. dataPath + "/Asset/" + obj. name + ". assetbundle "; if (BuildPipeline. buildAssetBundle (obj, null, targetPath, BuildAssetBundleOptions. collectDependencies) {Debug. log (obj. name + "Resource Package successful");} else {Debug. log (obj. name + "resource packaging failed") ;}} AssetDatabase. refresh ();}}

I hope you will like it.


In unity3d, click the button to automatically change the character attribute data. For example, how to write the code for increasing attack power?

Define the attribute first, obtain the attribute, and assign a value to the button click event.
 
How does unity3d display custom class variables in inspector?

You can add the [System. Serializable] class to display it. If it is js, you do not need to add it. :)

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.