Aseprite2Unity
Aseprite2Unity copied to clipboard
Create animation events from cel user data
Currently it's not possible to add animation events to the imported clips. Animation events are pretty critical. For example, if you want to emit foot steps at specific frames, or if you want to trigger an attack at a specific moment. Aseprite has support for custom "user data" per cel. It would be super handy to connect that to the importer and programmatically add events to the imported clips. Unity has support for this, but I couldn't sort out how to read the cel's user data -- any pointers? Happy to create a pull request once unblocked.
var animationEvent = new AnimationEvent();
animationEvent.time = time;
animationEvent.functionName = "foobar";
var events = new List<AnimationEvent>();
events.Add(animationEvent);
AnimationUtility.SetAnimationEvents(clip, events.ToArray());
Hi there, @aschearer. I can take a look at this. I don't currently use userData
for anything but it seems it can be done. I'd have to find a way to attach the proper event to the proper clip but I don't expect it to be too bad.
Cool! Quickly dabbling I found the above code snippet will add an event to the designated time in the animation clip -- I tested with start and end. So the main thing is just how to get the userData
during import. How did you figure out how many bytes to read, etc.?
Hello, @aschearer. I just pushed out version 1.2.0 of Aseprite2Unity which includes support for animation events. Further, the MegaDad example now uses animation events to play sound effects. See the example for further details and let me know how this works out for you.
https://seanba.itch.io/aseprite2unity/devlog/351816/aseprite-version-120
Wow you're a boss! 🎉
This is a great addition. Do events happen to support arguments?