[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. :)