通过脚本更改导入的图像设置

Change imported image settings via script

我正在尝试制作一个编辑器脚本来为我的图像设置导入设置。我不想做这个手册,因为我需要导入数百张图片。

所以我想设置编辑默认导入设置。

我尝试了以下方法:

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.
    }
}

我得到的错误如下:

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

我该怎么做? (这与统一如何让我访问属性有关。)
这甚至是更改图像导入设置的正确方法吗?

如果有任何不清楚的地方,请告诉我,以便我澄清。

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

没有。这不是更改图像导入设置的方法。要更改导入图像的设置,您必须创建一个派生自 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;
    }
}