- Home /
Question by
Harrier · Jul 23, 2018 at 12:31 PM ·
animationeventsassetpostprocessor
Add animation events on model import?
I'm trying to add events to end of animations. I have no idea how AssetPostprocessor works.
using UnityEngine;
using UnityEditor;
using System.Linq;
public class ImportAddEvents : AssetPostprocessor
{
void OnPostprocessModel(GameObject model)
{
if (assetPath.IndexOf(".fbx") == -1)
{
return;
}
if (EditorUtility.DisplayDialog("Events", "Add animation events to " + model.name + "?", "Yes", "No"))
{
AnimationClip[] clips = AssetDatabase.LoadAllAssetsAtPath(assetPath).OfType<AnimationClip>().ToArray();
foreach (AnimationClip clip in clips)
{
AnimationEvent[] events = new AnimationEvent[1] { new AnimationEvent() { time = 0/*clip.length*/, functionName = "On" + clip.name + "End"} };
AnimationUtility.SetAnimationEvents(clip, events);
}
}
}
}
Events are added to animations, but i don't see them in import settings. Any idea how to fix it? Thanks
Comment
Your answer
Follow this Question
Related Questions
having an event play at a certain time durring an animation? 0 Answers
Animation Event calling function 1 Answer
Empty animation clips when copying to Prefab 1 Answer
Bone of human avatar is out of reference with asset post processor 0 Answers
Access MecAnim animation clips in a AssetPostprocessor 1 Answer