Question by
umurcg · May 16, 2017 at 10:36 PM ·
modelimporter
How to change importing settings of already imported models?
Hello,
I am trying to optimize my game. For that purpose I decided to play around with model importer settings. But I dont want to manually reimport all assets that I want to change for applying new settings. So I found OnPostprocessAllAssets method which loops all moved files. With that function I can apply all my settings with just moving root folder of my models.
Here is my code:
public class BuildingImporter : AssetPostprocessor
{
static string folder = "Assets/Models(blend)/Yapılar/";
// Use this for initialization
void Start () {
}
static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths)
{
//Loop in every moved asset and if directory is under of folder then goes into if condition
for (int i = 0; i < movedAssets.Length; i++)
{
if (movedAssets[i].Length > folder.Length && System.String.Compare(movedAssets[i].Substring(0, folder.Length), folder) == 0)
{
Debug.Log(movedAssets[i] + "is reimported");
ModelImporter importer=null;
try
{
//Get modelImporter
importer = (ModelImporter)AssetImporter.GetAtPath(movedAssets[i]);
}
catch (System.InvalidCastException e)
{
Debug.Log(movedAssets[i] + " doesnt have model importer");
return;
}
Debug.Log("compressed");
importer.meshCompression = ModelImporterMeshCompression.High;
}
}
}
However in that code asset importer cant be cast to model importer. So nothing happens to models after I move the folder.
Also if you have another approach for my purpose I would like to hear that. Thanks :)
Comment