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

Add new lambda expression functions to create VRCAnimatorPlayAudio and VRCAvatarParameterDriver #3

Closed hai-vr closed 3 months ago

hai-vr commented 3 months ago

Open draft for #2, not tested

hai-vr commented 3 months ago

Example usage

AudioSource source = MyAudioSource();
AudioClip[] clips = MyAudioClipsWithNullValues();
AacV1.Create(new AacConfiguration())
    .NewAnimatorController()
    .NewLayer()
    .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();
    });