@@ -167,7 +167,17 @@ static void InitPostprocessors(AssetImportContext context, string pathName)
167167 {
168168 m_ImportProcessors = new ArrayList ( ) ;
169169 var analyticsEvent = new AssetPostProcessorAnalyticsData ( ) ;
170- analyticsEvent . importActionId = ( ( int ) Math . Floor ( AssetImporter . GetAtPath ( pathName ) . GetImportStartTime ( ) * 1000 ) ) . ToString ( ) ;
170+
171+ // This may happen if the processors are initialized outside a proper importer context. This is currently
172+ // used by the TextureGenerator to be able to invoke the postprocessors on the generated texture.
173+ if ( AssetImporter . GetAtPath ( pathName ) != null )
174+ {
175+ analyticsEvent . importActionId = ( ( int ) Math . Floor ( AssetImporter . GetAtPath ( pathName ) . GetImportStartTime ( ) * 1000 ) ) . ToString ( ) ;
176+ }
177+ else
178+ {
179+ analyticsEvent . importActionId = "None" ;
180+ }
171181 s_AnalyticsEventsStack . Push ( analyticsEvent ) ;
172182
173183 // @TODO: This is just a temporary workaround for the import settings.
@@ -396,7 +406,9 @@ static string GetTextureProcessorsHashString()
396406 var type = inst . GetType ( ) ;
397407 bool hasPreProcessMethod = type . GetMethod ( "OnPreprocessTexture" , BindingFlags . Public | BindingFlags . NonPublic | BindingFlags . Instance ) != null ;
398408 bool hasPostProcessMethod = ( type . GetMethod ( "OnPostprocessTexture" , BindingFlags . Public | BindingFlags . NonPublic | BindingFlags . Instance ) != null ) ||
399- ( type . GetMethod ( "OnPostprocessCubemap" , BindingFlags . Public | BindingFlags . NonPublic | BindingFlags . Instance ) != null ) ;
409+ ( type . GetMethod ( "OnPostprocessCubemap" , BindingFlags . Public | BindingFlags . NonPublic | BindingFlags . Instance ) != null ) ||
410+ ( type . GetMethod ( "OnPostprocessTexture3D" , BindingFlags . Public | BindingFlags . NonPublic | BindingFlags . Instance ) != null ) ||
411+ ( type . GetMethod ( "OnPostprocessTexture2DArray" , BindingFlags . Public | BindingFlags . NonPublic | BindingFlags . Instance ) != null ) ;
400412 uint version = inst . GetVersion ( ) ;
401413 if ( hasPreProcessMethod || hasPostProcessMethod )
402414 {
@@ -437,6 +449,20 @@ static void PostprocessCubemap(Cubemap tex, string pathName)
437449 CallPostProcessMethods ( "OnPostprocessCubemap" , args ) ;
438450 }
439451
452+ [ RequiredByNativeCode ]
453+ static void PostprocessTexture3D ( Texture3D tex , string pathName )
454+ {
455+ object [ ] args = { tex } ;
456+ CallPostProcessMethods ( "OnPostprocessTexture3D" , args ) ;
457+ }
458+
459+ [ RequiredByNativeCode ]
460+ static void PostprocessTexture2DArray ( Texture2DArray tex , string pathName )
461+ {
462+ object [ ] args = { tex } ;
463+ CallPostProcessMethods ( "OnPostprocessTexture2DArray" , args ) ;
464+ }
465+
440466 [ RequiredByNativeCode ]
441467 static void PostprocessSprites ( Texture2D tex , string pathName , Sprite [ ] sprites )
442468 {
@@ -617,6 +643,11 @@ static void CallPostProcessMethodsUntilReturnedObjectIsValid<T>(string methodNam
617643
618644 static void CallPostProcessMethods ( string methodName , object [ ] args )
619645 {
646+ if ( m_ImportProcessors == null )
647+ {
648+ throw new Exception ( "m_ImportProcessors is null, InitPostProcessors should be called before any of the post process methods are called." ) ;
649+ }
650+
620651 if ( IsAssetPostprocessorAnalyticsEnabled ( ) )
621652 {
622653 int invocationCount = 0 ;
0 commit comments