Seanba / Aseprite2Unity

Import Aseprite files to Unity
MIT License
48 stars 10 forks source link

Create animation events from cel user data #10

Open aschearer opened 2 years ago

aschearer commented 2 years ago

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());
Seanba commented 2 years ago

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.

aschearer commented 2 years ago

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.?

Seanba commented 2 years ago

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

aschearer commented 2 years ago

Wow you're a boss! 🎉

MabLuxx commented 1 year ago

This is a great addition. Do events happen to support arguments?