Playmaker Forum

PlayMaker Updates & Downloads => Share New Actions => Topic started by: joeyjr on August 09, 2011, 12:41:11 PM

Title: Activate / Deactivate Multiple Game Objects
Post by: joeyjr on August 09, 2011, 12:41:11 PM
I figured it might be use to have an action that can activate multiple game objects so I modified the existing action to work with multiple game objects.
I normally code in javaScript so this is my first attempt at C#, but I tested it and it appears to work fine.  It only took me all day to get it right! LOL, but this Action will save me and hopefully others a lot of frustration by now being able to consolidate all my Activated/Deactivated game objects into a single Action.

Also, it would be useful to have the Action name automatically change to "Deactivate" whenever the activate checkbox is unchecked so that when I'm reviewing all the actions on a particular state it would be easier and quicker to understand what has been coded. If anyone on this forum knows how to add that functionality that would be great!

Code: [Select]
// (c) copyright Hutong Games, LLC 2010-2011. All rights reserved.

using UnityEngine;

namespace HutongGames.PlayMaker.Actions
{
[ActionCategory(ActionCategory.GameObject)]
[Tooltip("Activates/deactivates multiple Game Objects.\nUse this to hide/show areas, or enable/disable many Behaviours at once.")]
public class ActivateMultipleGameObjects : FsmStateAction
{
[RequiredField]
public FsmOwnerDefault[] gameObjects;

[Tooltip("Check to activate, uncheck to deactivate Game Object.")]
[RequiredField]
public FsmBool activate;
[Tooltip("Recursively activate/deactivate all children.")]
public FsmBool recursive;
[Tooltip("Reset the game objects when exiting this state. Useful if you want an object to be active only while this state is active.")]
public bool resetOnExit;


// store the game object that we activated on enter
// so we can de-activate it on exit.
GameObject activatedgameObjects;


public override void Reset()
{
gameObjects = new FsmOwnerDefault[1];
gameObjects[0] = null;
activate = true;
recursive = true;
resetOnExit = false;
}

public override void OnEnter()
{
DoActivateGameObject();

Finish();
}

public override void OnExit()
{
// the stored game object might be invalid now
if (gameObjects == null) return;

if (resetOnExit)
{
if (recursive.Value)
activatedgameObjects.SetActiveRecursively(!activate.Value);
else
activatedgameObjects.active = !activate.Value;
}

}

void DoActivateGameObject()
{
foreach (var gonum in gameObjects)
{
        GameObject go = Fsm.GetOwnerDefaultTarget(gonum);
if (go == null) return;

if (recursive.Value)
go.SetActiveRecursively(activate.Value);
else
go.active = activate.Value;

activatedgameObjects = go;
}

}
}

}
Title: Re: Activate / Deactivate Multiple Game Objects
Post by: qholmes on August 09, 2011, 04:37:42 PM
Cool thanks.. Was thinking of doing something like this..

Appreciate it!

Q
Title: Re: Activate / Deactivate Multiple Game Objects
Post by: amaranth on July 05, 2012, 03:41:26 PM
This exactly what I needed. Thank you!
Title: Re: Activate / Deactivate Multiple Game Objects
Post by: 3d_Artist1987 on July 05, 2012, 11:36:36 PM
very useful!! :D
Title: Re: Activate / Deactivate Multiple Game Objects
Post by: matrismatris on June 19, 2014, 02:42:41 AM
hi
this action not for unity 4
please upload for unity 4
thanks
Title: Re: Activate / Deactivate Multiple Game Objects
Post by: Aaddiction on July 20, 2014, 08:51:12 AM
Hello, this action is great, maybe should be in the official actions, but it shows some warnings on import. Please see attached. Is it possible to be updated?

Title: Re: Activate / Deactivate Multiple Game Objects
Post by: PaulH on August 16, 2014, 05:59:16 PM
has this action been updated yet? its so handy and time saving. or been added to the standard action set?

thanks
Title: Re: Activate / Deactivate Multiple Game Objects
Post by: Gav (HeyBud) on January 24, 2020, 04:26:02 PM
Could this be included?  ;D
Title: Re: Activate / Deactivate Multiple Game Objects
Post by: jeanfabre on February 06, 2020, 05:43:56 AM
Hi,

 can you try ActivateGameObjects on the Ecosystem? I think it does the same.

Bye,

 Jean