using System.Collections.Generic; using Framework; using UnityEditor; using UnityEngine; namespace Gameplay.Story.Cmp.Utils { public class ClipAutoCutter { [MenuItem("Tools/*剧情编辑器/自动切割动画")] public static void AutoCut() { var configList = EditorTableManager.instance.tables.MotionMapperConfig.DataList; for (int i = 0; i < configList.Count; i++) { var config = configList[i]; // Assets/Art/Animations/Show/ani_s_stand05_a001.fbx var fbxPath = config.MotionFullPath; fbxPath = $"Assets/Art/Animations/Show/Story/{fbxPath}.fbx"; var startFrames = config.RangeStart; var loopFrames = config.RangeLoop; var endFrames = config.RangeEnd; _Process(fbxPath, startFrames, loopFrames, endFrames); } Debug.Log("处理完成"); } private static void _Process(string fbxPath, List startFrames, List loopFrames, List endFrames) { // VersionControlSystem.Checkout(fbxPath); var impoter = AssetImporter.GetAtPath(fbxPath) as ModelImporter; if (impoter == null) { return; } impoter.generateAnimations = ModelImporterGenerateAnimations.None; // impoter.clipAnimations = null; var fileName = System.IO.Path.GetFileNameWithoutExtension(fbxPath); var clipList = new List(); if (startFrames != null && startFrames.Count == 2) { var clip = new ModelImporterClipAnimation(); clip.name =fileName + "_start"; clip.firstFrame = startFrames[0]; clip.lastFrame = startFrames[1]; clip.loopTime = false; clipList.Add(clip); } if (loopFrames != null && loopFrames.Count == 2) { var clip = new ModelImporterClipAnimation(); clip.name =fileName + "_loop"; clip.firstFrame = loopFrames[0]; clip.lastFrame = loopFrames[1]; clip.loopTime = true; clip.loopPose = true; clipList.Add(clip); } if (endFrames != null && endFrames.Count == 2) { var clip = new ModelImporterClipAnimation(); clip.name =fileName + "_end"; clip.firstFrame = endFrames[0]; clip.lastFrame = endFrames[1]; clip.loopTime = false; clipList.Add(clip); } impoter.clipAnimations = clipList.ToArray(); impoter.SaveAndReimport(); } } }