I notice this post, and I have not seen an answer. I am very new to playmaker but I believe the answer to a custom action which plays a random animation would be something like this..
// (c) Copyright HutongGames, LLC 2010-2011. All rights reserved.
// Random factor created by Armada Animations
using System;
using UnityEngine;
namespace HutongGames.PlayMaker.Actions
{
[ActionCategory(ActionCategory.Animation)]
[Tooltip("Plays an Random Animation on a Game Object.")]
public class PlayRandomAnimation : FsmStateAction
{
[RequiredField]
[CheckForComponent(typeof(Animation))]
[Tooltip("Game Object to play the animation on.")]
public FsmOwnerDefault gameObject;
[UIHint(UIHint.Animation)]
[Tooltip("The name of the animation to play.")]
[CompoundArray("Anim Names", "Anim Name", "Play Mode")]
public FsmString[] animName;
[Tooltip("How to treat previously playing animations.")]
public PlayMode[] playMode;
[Tooltip("The behavior of the animation when it wraps.")]
public WrapMode wrapMode;
[HasFloatSlider(0f, 5f)]
[Tooltip("Time taken to blend to this animation.")]
public FsmFloat blendTime;
[Tooltip("Event to send when the animation is finished playing. NOTE: Not sent with Loop or PingPong wrap modes!")]
public FsmEvent finishEvent;
[Tooltip("Event to send when the animation loops. If you want to send this event to another FSM use Set Event Target. NOTE: This event is only sent with Loop and PingPong wrap modes.")]
public FsmEvent loopEvent;
[Tooltip("Stop playing the animation when this state is exited.")]
public bool stopOnExit;
private AnimationState anim;
private float prevAnimtTime;
private int randomIndex;
public override void Reset()
{
gameObject = null;
animName = new FsmString[1];
//animName = null;
playMode = new PlayMode[] {PlayMode.StopAll};
wrapMode = WrapMode.Once;
blendTime = 0.3f;
finishEvent = null;
loopEvent = null;
stopOnExit = false;
}
public override void OnEnter()
{
DoPlayAnimation();
}
void DoPlayAnimation()
{
var go = Fsm.GetOwnerDefaultTarget(gameObject);
if (animName.Length == 0) return;
//int randomIndex = ActionHelpers.GetRandomWeightedIndex(weights);
randomIndex = UnityEngine.Random.Range(0, animName.Length-1);
if (go == null || string.IsNullOrEmpty(animName[randomIndex].Value))
{
Finish();
return;
}
if (string.IsNullOrEmpty(animName[randomIndex].Value))
{
LogWarning("Missing animName!");
Finish();
return;
}
if (go.animation == null)
{
LogWarning("Missing animation component!");
Finish();
return;
}
anim = go.animation[animName[randomIndex].Value];
if (anim == null)
{
LogWarning("Missing animation: " + animName[randomIndex].Value);
Finish();
return;
}
var time = blendTime.Value;
if (time < 0.001f)
{
go.animation.Play(animName[randomIndex].Value, playMode[randomIndex]);
}
else
{
go.animation.CrossFade(animName[randomIndex].Value, time, playMode[randomIndex]);
}
anim.wrapMode = wrapMode;
prevAnimtTime = anim.time;
}
public override void OnUpdate()
{
var go = Fsm.GetOwnerDefaultTarget(gameObject);
if (go == null || anim == null)
{
return;
}
if (!anim.enabled || (anim.wrapMode == WrapMode.ClampForever && anim.time > anim.length))
{
Fsm.Event(finishEvent);
Finish();
}
if (anim.wrapMode != WrapMode.ClampForever && anim.time > anim.length && prevAnimtTime < anim.length)
{
Fsm.Event(loopEvent);
}
}
public override void OnExit()
{
if (stopOnExit)
{
StopAnimation();
}
}
void StopAnimation()
{
var go = Fsm.GetOwnerDefaultTarget(gameObject);
if (go != null && go.animation != null)
{
go.animation.Stop(animName[randomIndex].Value);
}
}
}
}
I hope it helps anyone who is looking for a code like this.
Armada Animations - David.