Playmaker Forum

PlayMaker Updates & Downloads => Share New Actions => Topic started by: Lane on April 23, 2014, 09:55:33 AM

Title: GameObject Is Active In Hierarchy
Post by: Lane on April 23, 2014, 09:55:33 AM
This is for checking to see if a GameObject is activated or deactivated, returning a bool and/or firing events.
Title: Re: GameObject Is Active In Hierarchy
Post by: szomaza on May 27, 2014, 01:39:37 AM
Thanks, just what I needed and seems to work perfectly so far.

Br,
Szomaza
Title: Re: GameObject Is Active In Hierarchy
Post by: doppelmonster on February 26, 2015, 10:51:45 AM
Hi,
i added the feature to choose a gameobject instead of using a variable.
I removed the debug feature and made a bypass default when game object is null.

Code: [Select]
// (c) Copyright HutongGames, LLC 2010-2013. All rights reserved.

using UnityEngine;
using System.Collections;

namespace HutongGames.PlayMaker.Actions
{
[ActionCategory(ActionCategory.Logic)]
[Tooltip("Tests if a GameObject Variable is Active or not.")]
public class GameObjectIsActiveInHierarchy : FsmStateAction
{
[RequiredField]
[UIHint(UIHint.Variable)]
        [Tooltip("The GameObject variable to test.")]
public FsmOwnerDefault gameObject;

        [Tooltip("Event to send if the GamObject is Active.")]
public FsmEvent isActive;

        [Tooltip("Event to send if the GamObject is NOT Active.")]
public FsmEvent isNotActive;

[UIHint(UIHint.Variable)]
        [Tooltip("Store the result in a bool variable.")]
public FsmBool storeResult;

        [Tooltip("Repeat every frame.")]
public bool everyFrame;


GameObject go;


public override void Reset()
{
gameObject = null;
isActive = null;
isNotActive = null;
storeResult = null;
everyFrame = false;
}

public override void OnEnter()
{
DoIsGameObjectActive();

if (!everyFrame)
{
Finish();
}
}

public override void OnUpdate()
{
DoIsGameObjectActive();
}


void DoIsGameObjectActive()
{
go = Fsm.GetOwnerDefaultTarget(gameObject);
if(go != null)
{
var goIsActive = go.activeInHierarchy;

storeResult.Value = goIsActive;

Fsm.Event(goIsActive ? isActive : isNotActive);
}
}
}
}
Title: Re: GameObject Is Active In Hierarchy
Post by: szomaza on February 27, 2015, 08:48:00 AM
Sounds good! Must have improvements!
Thanks for sharing, doppelmonster.

br,
szomaza
Title: Re: GameObject Is Active In Hierarchy
Post by: Lane on February 27, 2015, 12:37:11 PM
Cool! I should have added that from the start. =)