using Superlazy; using UnityEditor; using UnityEngine; public static class SLAssetPostprocessorAnim { private static string GetDestPath(string path) { return SLFileUtility.FolderPath(SLFileUtility.FolderPath(path)).Replace("/Raw/", "/Addressables/") + "/" + SLFileUtility.FileName(path) + ".anim"; } public static void OnPreprocessModel(ModelImporter importer) { importer.materialImportMode = ModelImporterMaterialImportMode.None; importer.importAnimation = true; importer.generateSecondaryUV = false; } internal static void OnPreprocessAnim(ModelImporter importer) { var clips = new ModelImporterClipAnimation[importer.defaultClipAnimations.Length]; var i = 0; foreach (var clip in importer.defaultClipAnimations) { clips[i] = clip; clips[i].name = SLFileUtility.FileName(importer.assetPath); i += 1; } importer.clipAnimations = clips; } public static void OnRemove(string path) { var upperPath = path.ToUpper(); if (upperPath.IsLeft("ASSETS/RAW/UNITS/") && SLFileUtility.FileName(path).Contains("_") && upperPath.Contains(".FBX")) { var newPath = GetDestPath(path); AssetDatabase.DeleteAsset(newPath); } if (upperPath.IsLeft("ASSETS/RAW/UNITS/") && SLFileUtility.FileName(path).Contains("_") && upperPath.Contains(".ANIM")) { var newPath = GetDestPath(path); AssetDatabase.DeleteAsset(newPath); } } public static void OnAdd(string path) { var upperPath = path.ToUpper(); if (upperPath.IsLeft("ASSETS/RAW/UNITS/") && SLFileUtility.FileName(path).Contains("_") && upperPath.Contains(".FBX")) { CreateAnimation(path, GetDestPath(path)); } if (upperPath.IsLeft("ASSETS/RAW/UNITS/") && SLFileUtility.FileName(path).Contains("_") && upperPath.Contains(".ANIM")) { AssetDatabase.CopyAsset(path, GetDestPath(path)); } } public static void CreateAnimation(string path, string destPath) { SLFileUtility.MakeFolderFromFilePath(destPath); var motion = AssetDatabase.LoadAssetAtPath(path); if (motion == null) { Debug.LogError("Cant load motion: " + path); return; } var newMotion = Object.Instantiate(motion); AssetDatabase.CreateAsset(newMotion, destPath); Debug.Log("Animation Build : " + destPath, newMotion); } }