From 6f1286cb4a8b71f6306a948023f221fe0aabff93 Mon Sep 17 00:00:00 2001 From: shenjianxing <”315615051@qq.com“> Date: Fri, 10 Jan 2025 20:33:28 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=B7=A5=E5=85=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Editor/FbxAnimListPostprocessor.cs | 80 ++++++++++++++++--- Assets/Scripts/Editor/SetReadWrite.cs | 3 + 2 files changed, 71 insertions(+), 12 deletions(-) diff --git a/Assets/Scripts/Editor/FbxAnimListPostprocessor.cs b/Assets/Scripts/Editor/FbxAnimListPostprocessor.cs index fdb5e5fe..c44922ab 100644 --- a/Assets/Scripts/Editor/FbxAnimListPostprocessor.cs +++ b/Assets/Scripts/Editor/FbxAnimListPostprocessor.cs @@ -4,7 +4,6 @@ using UnityEditor; using System.Collections; using System.IO; using System.Text.RegularExpressions; -using System; public class FbxAnimListPostprocessor : MonoBehaviour @@ -16,17 +15,73 @@ public class FbxAnimListPostprocessor : MonoBehaviour if (null != obj) { string assetPath = AssetDatabase.GetAssetPath(obj); - try + SplitAnim(assetPath); + } + } + + [MenuItem("Assets/SplitAnimFloder")] + public static void SetAplitAnim() + { + Object[] selectedObjects = Selection.GetFiltered(SelectionMode.DeepAssets); + foreach (Object obj in selectedObjects) + { + if (obj != null) + { + string path = AssetDatabase.GetAssetPath(obj); + if (Directory.Exists(path)) + { + EnableFBXReadWriteInFolder(path); + } + else if (path.EndsWith(".fbx", System.StringComparison.OrdinalIgnoreCase)) + { + EnableFBXReadWriteForFile(path); + } + } + } + } + public static void EnableFBXReadWriteInFolder(string folderPath) + { + string[] files = Directory.GetFiles(folderPath, "*.fbx", SearchOption.AllDirectories); + foreach (string file in files) + { + EnableFBXReadWriteForFile(file); + } + } + + public static void EnableFBXReadWriteForFile(string filePath) + { + string relativePath = filePath; + SplitAnim(filePath, true); + } + + + public static void SplitAnim(string assetPath, bool autoImport = false) + { + try + { + string fileAnim; + fileAnim = assetPath; + string ClipText = Path.ChangeExtension(fileAnim, ".txt"); + StreamReader file = new StreamReader(ClipText); + string sAnimList = file.ReadToEnd(); + file.Close(); + // + if (autoImport) + { + System.Collections.ArrayList List = new ArrayList(); + ParseAnimFile(sAnimList, ref List); + + ModelImporter modelImporter = ModelImporter.GetAtPath(assetPath) as ModelImporter; + modelImporter.animationType = ModelImporterAnimationType.Legacy; + //modelImporter.clipAnimations. = true; + modelImporter.clipAnimations = (ModelImporterClipAnimation[]) + List.ToArray(typeof(ModelImporterClipAnimation)); + AssetDatabase.ImportAsset(assetPath); + } + else { - string fileAnim; - fileAnim = assetPath; - string ClipText = Path.ChangeExtension(fileAnim, ".txt"); - StreamReader file = new StreamReader(ClipText); - string sAnimList = file.ReadToEnd(); - file.Close(); - // if (EditorUtility.DisplayDialog("FBX Animation Import from file", - fileAnim, "Import", "Cancel")) + fileAnim, "Import", "Cancel")) { System.Collections.ArrayList List = new ArrayList(); ParseAnimFile(sAnimList, ref List); @@ -43,9 +98,10 @@ public class FbxAnimListPostprocessor : MonoBehaviour + modelImporter.clipAnimations.GetLength(0).ToString(), "OK"); } } - catch { } - // (Exception e) { EditorUtility.DisplayDialog("Imported animations", e.Message, "OK"); } + } + catch { } + // (Exception e) { EditorUtility.DisplayDialog("Imported animations", e.Message, "OK"); } } static void ParseAnimFile(string sAnimList, ref System.Collections.ArrayList List) diff --git a/Assets/Scripts/Editor/SetReadWrite.cs b/Assets/Scripts/Editor/SetReadWrite.cs index cb45e4f0..45cf043f 100644 --- a/Assets/Scripts/Editor/SetReadWrite.cs +++ b/Assets/Scripts/Editor/SetReadWrite.cs @@ -27,6 +27,9 @@ public class SetReadWrite : Editor } } + + + public static void EnableFBXReadWriteInFolder(string folderPath) { string[] files = Directory.GetFiles(folderPath, "*.fbx", SearchOption.AllDirectories);