http://jingpin.jikexueyuan.com/article/17984.html
动画
using UnityEditor;
using UnityEngine;
using System.Collections.Generic;
public class AnimationEventBatch
{
[MenuItem("Animation/AnimationEvent Batch")]
static void Execute()
{
List<string> lstAnimName = new List<string>();
foreach (Object o in Selection.GetFiltered(typeof(Object), SelectionMode.DeepAssets))
{
if (!(o is GameObject)) continue;
if (o.name.Contains("@")) continue;
if (o.name.Contains("anim") || o.name.Contains("ANIM")) continue;
if (o.name.Contains("meta")) continue;
GameObject charFbx = (GameObject)o;
AnimationClip[] clips = AnimationUtility.GetAnimationClips(charFbx);
foreach (AnimationClip clip in clips)
{
if (clip.name.Contains("Take 0")) continue;
List<AnimationEvent> events = new List<AnimationEvent>(AnimationUtility.GetAnimationEvents(clip));
if (HasStartEvent(events) && HasEndEvent(events)) continue;
if (!HasStartEvent(events))
{
AnimationEvent startEvent = new AnimationEvent();
startEvent.time = 0.0005f;
startEvent.functionName = "StartCallBack";
events.Add(startEvent);
}
if (!HasEndEvent(events))
{
AnimationEvent endEvent = new AnimationEvent();
endEvent.time = clip.length - 0.0005f;
endEvent.functionName = "EndCallBack";
events.Add(endEvent);
}
AnimationUtility.SetAnimationEvents(clip, events.ToArray());
}
EditorUtility.DisplayDialog("fbxname", clips[0].name, "OK");
}
}
static bool HasStartEvent(List<AnimationEvent> events)
{
foreach (AnimationEvent eventElem in events)
{
if (eventElem.functionName == "StartCallBack") return true;
}
return false;
}
static bool HasEndEvent(List<AnimationEvent> events)
{
foreach (AnimationEvent eventElem in events)
{
if (eventElem.functionName == "EndCallBack") return true;
}
return false;
}
}