12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- using UnityEditor;
- using UnityEngine;
- using System;
- using System.IO;
- using System.Collections.Generic;
- /// <summary>
- /// 自动裁剪出模型,需要把模型放入到/Artise/ClipAnimation目录下
- /// </summary>
- namespace James.Editor
- {
- public class ModelProcessor : AssetPostprocessor
- {
- public void OnPostprocessModel(GameObject go)
- {
- //Set the file path variable for our models
- string lowerCaseAssetPath = assetPath.ToLower();
- //Apply this script ONLY if we are in our folder
- if (lowerCaseAssetPath.IndexOf("artise/clipanimation") == -1) //type your file location with all your models here in lowercase
- return;
- string HowToClipCfgPath = lowerCaseAssetPath.Replace(".fbx", ".txt");
- if (!File.Exists(Directory.GetCurrentDirectory() + "/" + HowToClipCfgPath)) return;
- ModelInterpret mi = ModelInterpretor.read(HowToClipCfgPath);
- if (mi == null) return;
- ///Model importer lets you modify model import settings from editor scripts.
- ModelImporter modelImporter = assetImporter as ModelImporter;
- modelImporter.animationType = ModelImporterAnimationType.Legacy;
- List<ModelImporterClipAnimation> clips = new List<ModelImporterClipAnimation>();
- foreach (CustomizeAnim curConfig in mi.anims)
- {
- clips.Add(ParseAnimationClip(curConfig));
- }
- if (clips.Count > 0)
- modelImporter.clipAnimations = clips.ToArray();
- modelImporter.assetBundleName = mi.abName;
- }
- ModelImporterClipAnimation ParseAnimationClip(CustomizeAnim anim)
- {
- string clipName = anim.name;
- int startIndex = anim.start;
- int endIndex = anim.end;
- ModelImporterClipAnimation clip = new ModelImporterClipAnimation();
- clip.firstFrame = Convert.ToSingle(startIndex);
- clip.lastFrame = Convert.ToSingle(endIndex);
- clip.loopTime = true;
- clip.name = clipName;
- return clip;
- }
- }
- }
|