/** * Copyright(c) Live2D Inc. All rights reserved. * * Use of this source code is governed by the Live2D Open Software license * that can be found at https://www.live2d.com/eula/live2d-open-software-license-agreement_en.html. */ using System; using System.Collections.Generic; using UnityEngine; namespace Live2D.Cubism.Editor.Deleters { /// /// Helper functionality for s. /// public static class CubismDeleter { /// /// Tries to get an deleter for a Cubism asset. /// /// Deleter type. /// Path to the asset. /// The deleter on success; otherwise. public static T GetDeleterAsPath(string assetPath) where T : class, ICubismDeleter { return GetDeleterAsPath(assetPath) as T; } /// /// Tries to deserialize an deleter from . /// /// Path to the asset. /// The deleter on success; otherwise. public static ICubismDeleter GetDeleterAsPath(string assetPath) { var deleterEntry = _registry.Find(e => assetPath.EndsWith(e.FileExtension)); // Return early in case no valid deleter is registered. if (deleterEntry.DeleterType == null) { return null; } var deleter = Activator.CreateInstance(deleterEntry.DeleterType) as ICubismDeleter; // Finalize deleter initialization. if (deleter != null) { deleter.SetAssetPath(assetPath); } return deleter; } #region Registry /// /// Registry entry. /// private struct DeleterEntry { /// /// Deleter type. /// public Type DeleterType; /// /// File extension valid for the deleter. /// public string FileExtension; } /// /// List of registered s. /// private static List _registry = new List(); /// /// Registers an deleter type. /// /// The type of deleter to register. /// The file extension the deleter supports. internal static void RegisterDeleter(string fileExtension) where T : ICubismDeleter { _registry.Add(new DeleterEntry { DeleterType = typeof(T), FileExtension = fileExtension }); } #endregion } }