FutureCake
FutureCake

Reputation: 2943

Change imported image settings via script

I am trying to make an editor script to set the import settings for my images. I don't want to do this manual since I need to import hundreds of images.

So I want to set edit the default import settings.

I tried the following:

using System.Collections;
using System.Collections.Generic;
using UnityEditor;

[InitializeOnLoad]
public class EditorSettings : Editor {

    private static TextureImporter CustomImporter;

    static EditorSettings()
    {
        CustomImporter.npotScale.None; // see below for error.
    }
}

the error I get is the following:

Member 'TextureImporterNPOTScale.None' cannot be accessed with an instance reference; qualify it with a type name instead

How do I do this? (it has something to do with how unity lets me acces the properties.)
And is this even the correct way to change the import settings for images?

Let me know if anything is unclear so I can clarify.

Upvotes: 2

Views: 2745

Answers (1)

Programmer
Programmer

Reputation: 125275

How do I do this? And is this even the correct way to change the import settings for images?

No. This is not how to change the import settings of images. To change the settings of an imported image, you have to create an Editor script that derives from AssetPostprocessor then change the image settings in the OnPostprocessTexture function which will be called when the image has finished importing. The image is changed with the TextureImporter class.

public class PostprocessImages : AssetPostprocessor
{
    void OnPostprocessTexture(Texture2D texture)
    {
        TextureImporter textureImporter = (TextureImporter)assetImporter;
        textureImporter.npotScale = TextureImporterNPOTScale.None;
    }
}

Upvotes: 1

Related Questions