代码之家  ›  专栏  ›  技术社区  ›  FutureCake

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

  •  1
  • FutureCake  · 技术社区  · 7 年前

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

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

    我尝试了以下方法:

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

    我得到的错误如下:

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

    1 回复  |  直到 7 年前
        1
  •  1
  •   Programmer    7 年前

    我该怎么做?这甚至是改变

    不。这不是如何更改图像的导入设置。要更改导入图像的设置,必须创建从 AssetPostprocessor 然后更改中的图像设置 OnPostprocessTexture 函数,该函数将在图像完成导入时调用。图像更改为 TextureImporter

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