Use String.Contains() to process only assets that have a given string in their asset paths.
// Process asset
A Basic Importer
Assume you have a custom file you want to create an importer for. It could be an .xls file or whatever. In this case we're going to use a JSON file because it's easy but we're going to pick a custom extension to make it easy to tell which files are ours?
Let's assume the format of the JSON file is
Let's save that as Example.test somewhere outside of assets for now.
Next make a MonoBehaviour with a custom class just for the data. The custom class is solely to make it easy to deserialize the JSON. You do NOT have to use a custom class but it makes this example shorter. We'll save this in TestData.cs
If you were to manually add that script to a GameObject you'd see something like
Next make an Editor folder somewhere under Assets. I can be at any level. Inside the Editor folder make a TestDataAssetPostprocessor.cs file and put this in it.
With that saved you should be able to drag and drop the Example.test file we created above into your Unity Assets folder and you should see the corresponding prefab created. If you edit Example.test you'll see the data in the prefab is updated immediately. If you drag the prefab into the scene hierarchy you'll see it update as well as Example.test changes. If you move Example.test to another folder the corresponding prefab will move with it. If you change a field on an instance then change the Example.test file you'll see only the fields you didn't modify on the instance get updated.
Improvements: In the example above, after you drag Example.test into your Assets folder you'll see there's both an Example.test and an Example.test.prefab. It would be great to know to make it work more like the model importers work we're you'd magically only see Example.test and it's an AssetBundle or some such thing. If you know how please provide that example
Create TexturePostProcessor.cs file anywhere in Assets folder:
public class TexturePostProcessor : AssetPostprocessor
void OnPostprocessTexture(Texture2D texture)
TextureImporter importer = assetImporter as TextureImporter;
importer.anisoLevel = 1;
importer.filterMode = FilterMode.Bilinear;
importer.mipmapEnabled = true;
importer.npotScale = TextureImporterNPOTScale.ToLarger;
importer.textureType = TextureImporterType.Advanced;
Now, every time Unity imports a texture it will have the following parameters:
If you use postprocessor, you can not change texture parameters by manipulating Import Settings in editor.
When you hit Apply button the texture will be reimported and postprocessor code will run again.
This modified text is an extract of the original Stack Overflow Documentation created by following contributors and released under CC BY-SA 3.0