Alright. Some success and progress. Here is what I found out so far.
Old SetupI already had an FSM for all the FX, sound and particles, and which also used to communicate with Mechanim. You can see some part in the lower left of the image below.
Other FSMs send out an event, like when jumping, or when grounding, typically as a game object wide broadcast, e.g. "JUMPING". Those FSMs who care about it, like this FX FSM then go to the respective state and do their thing. In this case, it used to play the particles, sound and also switched a couple of booleans around. For instance, isGrounded = false and suchlike. But this gets cumbersome quickly, and it doubles logic I already have in Playmaker.
New SetupNow I have just two parameters, one for current running Speed and one Random Int to play random clips (I had this before, too).
I have a character script anyway for the stats, contained in scriptable objects, and I decided to directly update the animator. Here's the bit you need.
Animator anim;
Rigidbody2D rb;
...
void Awake()
{
rb = gameObject.GetComponent<Rigidbody2D>();
anim = gameObject.GetComponent<Animator>();
}
private void FixedUpdate()
{
anim.SetFloat("Speed", Mathf.Abs(rb.velocity.x));
}
You can do this also with Playmaker in a single state FSM, but that's fast and direct, and I had a script there anyway.
Next, I only needed to machete the Mechanim jungle, and use the
Animator Cross Fade to go to the Mechanim State I want directly. In Mechanim, I typically use sub-state-machines and blend trees, because I can easily add variations using the random int trick.
The landing > ground > running transitions are done by switching the state to action sequence (right click on action list), a wait action and another
Animator Cross Fade. I find this better than using clunky transitions in Mechanim.
Randomizing animations is easy. Make an int parameter. In PM use
Random Int and
Set Animator Int to set this parameter some random number as specified. Next, when entering the sub-state add your different animation clips with the variations, and random int equal to X into the conditions, e.g. if RandomInt equals 1, play jump_01, if equal 2 play jump_02 and so on. You can super easily expand it that way. You can typically use and reuse just one randomize paramter in Mechanim for everything.
I guess with this setup, I can do most of the remaining animations, too.