Custom Importers provide a programmatic way to completely transform the generated prefab during the import process. This is the most powerful extension method but requires writing C# code.
To implement a custom importer, inherit from CustomTmxImporter and override the TmxAssetImported method.
Important Requirements:
- Determinism: Any modifications made to the GameObjects or components must be deterministic; the same prefab must be produced every time the import runs.
- Accessing the Map: Use
args.ImportedSuperMap to access the root of the imported prefab. - Application: You can use the
[AutoCustomTmxImporter] attribute to force the importer to always be applied, or omit it to select the importer from a drop-down list in the Unity Inspector.
// The AutoCustomTmxImporterAttribute will force this importer to always be applied.
// Leave this attribute off if you want to choose a custom importer from a drop-down list instead.
[AutoCustomTmxImporter()]
public class MyTmxImporter : CustomTmxImporter
{
public override void TmxAssetImported(TmxAssetImportedArgs args)
{
// Note: args.ImportedSuperMap is the root of the imported prefab
// You can modify the gameobjects and components any way you wish here
// Howerver, the results must be deterministic (i.e. the same prefab is created each time)
var map = args.ImportedSuperMap;
Debug.LogFormat("Map '{0}' has been imported.", map.name);
}
}