当前位置:网站首页>Unity asset import settings

Unity asset import settings

2022-04-23 20:34:00 One Mr rabbit one

Inherit AssetPostprocessor
Relevant settings are handled in advance OnPreprocessTexture
Post import processing OnPostprocessTexture

Complete code :

using Framework;
using UnityEditor;
using UnityEngine;

namespace Editor.Tools
{
    
    public class ImportAssetSettings : AssetPostprocessor
    {
    
        private const string ISIMPORTED = "isImported";
        private bool IsImported()
        {
    
            if (Application.isBatchMode) return true;
            return !assetPath.StartsWith(Constants.ArtDirPath) || assetImporter.userData.EndsWith(ISIMPORTED);
        }
        private void OnPostprocessTexture(Texture2D texture)
        {
    
            assetImporter.userData = ISIMPORTED;
        }

        private void OnPreprocessTexture()
        {
    
            if(IsImported()) return;
            TextureImporter textureImporter = (TextureImporter) assetImporter;
            textureImporter.textureType = TextureImporterType.Sprite;
            textureImporter.mipmapEnabled = false;
            textureImporter.isReadable = false;
        }
    }
}

版权声明
本文为[One Mr rabbit one]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204210548406386.html