74 lines
2.7 KiB
C#
74 lines
2.7 KiB
C#
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];
|
|
var fbxPath = config.MotionFullPath;
|
|
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)
|
|
{
|
|
// 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<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();
|
|
}
|
|
}
|
|
}
|