ForceExternalMaterialProcessor

mail@pastecode.io avatar
unknown
csharp
2 years ago
706 B
0
Indexable
Never
#if UNITY_EDITOR
using UnityEngine;
using UnityEditor;

public class ForceExternalMaterialProcessor : AssetPostprocessor
{
    void OnPreprocessModel()
    {
#if UNITY_2018_1_OR_NEWER
        var importSettingsMissing = assetImporter.importSettingsMissing;
#else
        var importSettingsMissing = !System.IO.File.Exists(AssetDatabase.GetTextMetaFilePathFromAssetPath(assetPath));
#endif
        if (!importSettingsMissing)
            return; // Asset imported already, do not process.

        var modelImporter = assetImporter as ModelImporter;
        modelImporter.materialLocation = ModelImporterMaterialLocation.External;
        modelImporter.isReadable = true;
    }
}
#endif