playMaker

Author Topic: Activate / Deactivate Multiple Game Objects  (Read 12786 times)

joeyjr

  • 1.2 Beta
  • Playmaker Newbie
  • *
  • Posts: 12
Activate / Deactivate Multiple Game Objects
« 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;
}

}
}

}
« Last Edit: August 09, 2011, 03:24:01 PM by joeyjr »

qholmes

  • 1.2 Beta
  • Hero Member
  • *
  • Posts: 509
Re: Activate / Deactivate Multiple Game Objects
« Reply #1 on: August 09, 2011, 04:37:42 PM »
Cool thanks.. Was thinking of doing something like this..

Appreciate it!

Q

amaranth

  • Full Member
  • ***
  • Posts: 172
Re: Activate / Deactivate Multiple Game Objects
« Reply #2 on: July 05, 2012, 03:41:26 PM »
This exactly what I needed. Thank you!

3d_Artist1987

  • Beta Group
  • Full Member
  • *
  • Posts: 157
Re: Activate / Deactivate Multiple Game Objects
« Reply #3 on: July 05, 2012, 11:36:36 PM »
very useful!! :D

matrismatris

  • Playmaker Newbie
  • *
  • Posts: 1
Re: Activate / Deactivate Multiple Game Objects
« Reply #4 on: June 19, 2014, 02:42:41 AM »
hi
this action not for unity 4
please upload for unity 4
thanks

Aaddiction

  • Full Member
  • ***
  • Posts: 166
Re: Activate / Deactivate Multiple Game Objects
« Reply #5 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?


PaulH

  • Junior Playmaker
  • **
  • Posts: 50
Re: Activate / Deactivate Multiple Game Objects
« Reply #6 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

Gav (HeyBud)

  • Full Member
  • ***
  • Posts: 126
    • Tumblr
Re: Activate / Deactivate Multiple Game Objects
« Reply #7 on: January 24, 2020, 04:26:02 PM »
Could this be included?  ;D

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Activate / Deactivate Multiple Game Objects
« Reply #8 on: February 06, 2020, 05:43:56 AM »
Hi,

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

Bye,

 Jean