Question by 
               Gergely_Maros · Feb 12, 2018 at 02:54 PM · 
                c#importasset  
              
 
              Import asset
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
               Comment
              
 
               
               
               Best Answer 
              
 
              Answer by Hellium · Feb 12, 2018 at 03:46 PM
You can inherit from AssetImporter 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[i] + " from: " + movedFromAssetPaths[i]);
         }
     }
     void OnPreprocessTexture()
     {
         if (assetPath.Contains("_bumpmap"))
         {
             TextureImporter textureImporter  = (TextureImporter)assetImporter;
             textureImporter.convertToNormalmap = true;
         }
     }
 }
 
              Your answer
 
             Follow this Question
Related Questions
In Editor - Update Material and save it to disk 0 Answers
Can't integrate Project Tango with Unity 1 Answer
AssetImporeter to GameObject Editor Mode 0 Answers
How to use RenderStaticPreview OR get project viewer thumbnails for ScriptableObject assets? 2 Answers
Good practices for storing readonly data 0 Answers