I originally made the action for myself and the person who wanted it, that's why the namespace and tooltip were different. I didn't think to place it here or make it on the Ecosystem, that's cool. I can add all the changes you suggested and look at the reset on exit issue.
Here is an edited version. Let me know if this works fine...
// (c) Copyright HutongGames, LLC 2010-2018. All rights reserved.
// author : ransomink
// Keywords: fsm, enable, disable, multi, multiple
/*--- __ECO__ __PLAYMAKER__ __ACTION__ ---*/
using UnityEngine;
namespace HutongGames.PlayMaker.Actions
{
[ActionCategory(ActionCategory.StateMachine)]
[Tooltip("Enable/Disable multiple FSM Components on GameObjects")]
public class EnableMultiFSM : FsmStateAction
{
public class FSMController
{
public class FSM
{
[UIHint(UIHint.FsmName)]
[Tooltip("Optional name of FSM on GameObject. Useful if you have more than one FSM on a GameObject.")]
public FsmString fsmName;
[Tooltip("Set to True to enable, False to disable.")]
public FsmBool enable = true;
[Tooltip("Reset the initial enabled state when exiting the state.")]
public FsmBool resetOnExit = true;
[Tooltip("The FSM component.")]
private PlayMakerFSM component;
/// <summary>
/// The GameObject PlayMakerFSM component.
/// </summary>
public PlayMakerFSM Component
{
get { return component; }
set { component = value; }
}
}
[RequiredField]
[Tooltip("The GameObject that owns the FSM components.")]
public FsmOwnerDefault gameObject;
[RequiredField]
[Title("PlayMaker Fsm")]
[Tooltip("The FSM components to enable.")]
public FSM[] fsms;
}
[Tooltip("An array of GameObjects controlling multiple PlayMaker FSMs.")]
public FSMController[] fsmController;
public override void Reset()
{
fsmController = new FSMController[ 1 ];
}
public override void OnEnter()
{
DoMultiEnableFSM();
Finish();
}
public override void OnExit()
{
foreach ( var controller in fsmController )
{
foreach ( var fsm in controller.fsms )
{
if ( fsm.resetOnExit.Value )
{
fsm.Component.enabled = !fsm.enable.Value;
}
}
}
}
void DoMultiEnableFSM()
{
for ( int i = 0; i < fsmController.Length; i++ )
{
var go = fsmController[ i ].gameObject.OwnerOption == OwnerDefaultOption.UseOwner ? Owner : fsmController[ i ].gameObject.GameObject.Value;
if ( go == null ) return;
var fsms = fsmController[ i ].fsms;
if ( fsms == null )
{
LogError( "No Components assigned" );
return;
}
// find by FSM component name
var fsmComponents = go.GetComponents<PlayMakerFSM>();
for ( int j = 0; j < fsms.Length; j++ )
{
var fsm = fsms[ j ];
if ( !string.IsNullOrEmpty( fsm.fsmName.Value ) )
{
foreach ( var component in fsmComponents )
{
if ( component.FsmName == fsm.fsmName.Value )
{
fsm.Component = component;
break;
}
}
}
else
{
// get first FSM component
fsm.Component = go.GetComponent<PlayMakerFSM>();
}
if ( fsm.Component == null )
{
LogError( "Missing Component" );
return;
}
fsm.Component.enabled = fsm.enable.Value;
}
}
}
}
}