Importer/Deleter

Updated: 01/30/2020

This page is for Cubism version 4.2 or earlier. Click here for the latest version.

Summary

Importer/Deleter is an extension to the Unity editor using [AssetPostprocessor.OnPostprocessAllAssets()].

OnPostprocessAllAssets is called after any number of assets have been imported and the path to the imported and removed assets can be retrieved from the argument.

The Importer/Deleter function calls the corresponding Importer/Deleter process from the acquired path.

// Retrieve the importer from the path of the imported asset and perform the import process
foreach (var assetPath in importedAssetPaths)
{
    var importer = CubismImporter.GetImporterAtPath(assetPath);

    if (importer == null)
    {
        continue;
    }

    importer.Import();
}

// Retrieve the importer from the path of the imported asset and perform the import process
foreach (var assetPath in deletedAssetPaths)
{
    var deleter = CubismDeleter.GetDeleterAsPath(assetPath);

    if (deleter == null)
    {
        continue;
    }

    deleter.Delete();
}

This is done by ‘CubismAssetProcessor.OnPostprocessAllAssets().’

CubismImporter / CubismDeleter

This class brings together Importer/Deleter.

  • This structure is used to associate the Importer/Deleter type with the target file extension.
    • ImporterEntry
    • DeleterEntry
  • List to store entries.
    • private static List _registry = new List();
    • private static List _registry = new List();
  • Method to register Importer/Deleter to an entry.
    • internal static void RegisterImporter(string fileExtension) where T : ICubismImporter
    • internal static void RegisterDeleter(string fileExtension) where T : ICubismDeleter
  • Method to obtain Importer/Deleter of the corresponding type from the path.
    • public static T GetImporterAtPath(string assetPath) where T : class, ICubismImporter
    • public static ICubismImporter GetImporterAtPath(string assetPath)
    • public static T GetDeleterAsPath(string assetPath) where T : class, ICubismDeleter
    • public static ICubismDeleter GetDeleterAsPath(string assetPath)

ICubismImporter/ICubismDeleter

  • The process of saving the path of an asset.
    • SetAssetPath(string value)
  • Importer/Deleter processing.
    • Import()/Delete()
  • The process of saving the Importer and re-importing assets in the Importer interface.
    • Save()

CubismImporterBase / CubismDeleterBase

It inherits from the ICubismImporter/ICubismDeleter interface and is the base class for Importer/Deleter.

Importer Implementation Example

using Live2D.Cubism.Editor.Importers;

public sealed class ImporterCustomization : CubismImporterBase
{
    private static string _extension = ".asset";

    [UnityEditor.InitializeOnLoadMethod]
    private static void RegisterImporter()
    {
        CubismImporter.RegisterImporter<ImporterCustomization>(_extension);
    }

    public override void Import()
    {
        UnityEngine.Debug.Log("Asset Import as path : " + AssetPath);
    }
}

Deleter Implementation Example

using Live2D.Cubism.Editor.Deleters;

public sealed class DeleterCustomization : CubismDeleterBase
{
    private static string _extension = ".asset";

    [UnityEditor.InitializeOnLoadMethod]
    private static void RegisterDeleter()
    {
        CubismDeleter.RegisterDeleter<DeleterCustomization>(_deleterAssetExtension);
    }

    public override void Delete()
    {
        UnityEngine.Debug.Log("Asset deleted as path : " + AssetPath);
    }
}
Was this article helpful?
YesNo
Please let us know what you think about this article.