@@ -167,7 +167,17 @@ static void InitPostprocessors(AssetImportContext context, string pathName)
167
167
{
168
168
m_ImportProcessors = new ArrayList ( ) ;
169
169
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
+ }
171
181
s_AnalyticsEventsStack . Push ( analyticsEvent ) ;
172
182
173
183
// @TODO: This is just a temporary workaround for the import settings.
@@ -396,7 +406,9 @@ static string GetTextureProcessorsHashString()
396
406
var type = inst . GetType ( ) ;
397
407
bool hasPreProcessMethod = type . GetMethod ( "OnPreprocessTexture" , BindingFlags . Public | BindingFlags . NonPublic | BindingFlags . Instance ) != null ;
398
408
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 ) ;
400
412
uint version = inst . GetVersion ( ) ;
401
413
if ( hasPreProcessMethod || hasPostProcessMethod )
402
414
{
@@ -437,6 +449,20 @@ static void PostprocessCubemap(Cubemap tex, string pathName)
437
449
CallPostProcessMethods ( "OnPostprocessCubemap" , args ) ;
438
450
}
439
451
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
+
440
466
[ RequiredByNativeCode ]
441
467
static void PostprocessSprites ( Texture2D tex , string pathName , Sprite [ ] sprites )
442
468
{
@@ -617,6 +643,11 @@ static void CallPostProcessMethodsUntilReturnedObjectIsValid<T>(string methodNam
617
643
618
644
static void CallPostProcessMethods ( string methodName , object [ ] args )
619
645
{
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
+
620
651
if ( IsAssetPostprocessorAnalyticsEnabled ( ) )
621
652
{
622
653
int invocationCount = 0 ;
0 commit comments