NLDClient-yudde/ProjectNLD/Assets/Editor/Story/Utils/ClipAutoCutter.cs

76 lines
2.8 KiB
C#
Raw Normal View History

2023-10-19 15:00:19 +08:00
using System.Collections.Generic;
using Framework;
using UnityEditor;
using UnityEngine;
namespace Gameplay.Story.Cmp.Utils
{
public class ClipAutoCutter
{
2025-02-25 15:03:08 +08:00
[MenuItem("Tools/*剧情编辑器/自动切割动画")]
2023-10-19 15:00:19 +08:00
public static void AutoCut()
{
var configList = EditorTableManager.instance.tables.MotionMapperConfig.DataList;
for (int i = 0; i < configList.Count; i++)
{
var config = configList[i];
2024-03-25 18:42:27 +08:00
// Assets/Art/Animations/Show/ani_s_stand05_a001.fbx
2023-10-19 15:00:19 +08:00
var fbxPath = config.MotionFullPath;
fbxPath = $"Assets/Art/Animations/Show/Story/{fbxPath}.fbx";
2023-10-19 15:00:19 +08:00
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<int> startFrames, List<int> loopFrames, List<int> endFrames)
{
2023-10-23 16:54:35 +08:00
// VersionControlSystem.Checkout(fbxPath);
2023-10-19 15:00:19 +08:00
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<ModelImporterClipAnimation>();
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();
}
}
}