hai-vr / animator-as-code-vrchat

🗨️ VRChat extension methods for AnimatorAsCode V1.
https://docs.hai-vr.dev/docs/products/animator-as-code/functions/vrchat
MIT License
2 stars 1 forks source link

Support Animator Play Audio State Behaviour #2

Closed Okabintaro closed 1 month ago

Okabintaro commented 3 months ago

Would be cool if you could use the newly introduced Play Audio State Behaviour in AaC: https://creators.vrchat.com/avatars/state-behaviors/#animator-play-audio

hai-vr commented 3 months ago

Drafted on https://github.com/hai-vr/animator-as-code-vrchat/pull/3#issuecomment-2187498104

hai-vr commented 3 months ago

I have not tested any of the following, it's up to you to choose if you want to give it a shot or not:

You can try installing the Developer Only VPM listing https://hai-vr.github.io/vpm-listing-developeronly/

Then, in VCC/ALCOM, enable pre-releases packages, and install 1.0.9941-alpha.1

If VCC still has the bug that prevents multiple listings from referencing the same package, then temporarily disable the regular VPM listing.

Usage:

    .NewState("Example")
    .Audio(source, audio =>
    {
        // Get the PlayAudio object if there's a need to edit it directly.
        VRCAnimatorPlayAudio vrcAnimatorPlayAudio = audio.PlayAudio;

        // By default, a PlayAudio created through AAC does nothing (unlike a manually created behaviour)
        // so you need to invoke anything that is relevant.
        audio
            .SelectsClip(VRC_AnimatorPlayAudio.Order.Random, clips)
            .SetsLooping()
            .RandomizesPitch(0.8f, 1.2f)
            .RandomizesVolume(0.5f, 1f)
            .StartsPlayingOnEnter()
            .StopsPlayingOnExit();
    });

Notes:

The Stop and Play checkboxes are grouped into three semantic functions.

You can only invoke one of the following:

All of the three above functions affect both the Stop and Play checkboxes at once.

If you want to do neither starting nor stopping the audio, then don't invoke any of those three functions.

By default, all invocations of Audio will empty the Animator Play Audio component at the beginning so that it does nothing.

A limitation of the current draft is that AAC will not allow 2 or more Animator Play Audio on the same state, which can be an issue, so I may later implement NewAudio(, as well as NewDriver( that follows a similar pattern (as Drivers have become more complex over time).

Okabintaro commented 3 months ago

Wow, thanks for the fast implementation. I will try it out later tonight and report back.

My use case is playing a single set of randomized clips on state enter so this should suffice.

Okabintaro commented 3 months ago

Thanks, it seems to work just fine. Looking at the generated state though, for some reason it seems to create two identical state behaviours:

grafik

Not sure if that's a problem or just an artifact/bug of Av3Emulator

hai-vr commented 3 months ago

AFAIK this is an artifact of Play mode, I don't know more than that

hai-vr commented 1 month ago

Feature is being staged for V1.1.0

hai-vr commented 1 month ago

Released in 2f82700a945abf0c474923182bd9ba8888f7b9a2