Hi all,
is there any way to catch the object by code after importing an asset?
Even I drag an asset to unity or import it by menu (Asset / Import New Asset…)
Cheers:
Greg
Hi all,
is there any way to catch the object by code after importing an asset?
Even I drag an asset to unity or import it by menu (Asset / Import New Asset…)
Cheers:
Greg
You can inherit from [AssetImporter][1] and define the desired function according to the type of the imported asset.
using UnityEngine;
using UnityEditor;
class MyPostprocessor : AssetPostprocessor
{
static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths)
{
foreach (string str in importedAssets)
{
Debug.Log("Reimported Asset: " + str);
}
foreach (string str in deletedAssets)
{
Debug.Log("Deleted Asset: " + str);
}
for (int i = 0; i < movedAssets.Length; i++)
{
Debug.Log("Moved Asset: " + movedAssets _+ " from: " + movedFromAssetPaths*);*_
}
}
void OnPreprocessTexture()
{
if (assetPath.Contains(“_bumpmap”))
{
TextureImporter textureImporter = (TextureImporter)assetImporter;
textureImporter.convertToNormalmap = true;
}
}
}
_*[1]: https://docs.unity3d.com/ScriptReference/AssetPostprocessor.html*_