Playmaker Forum
PlayMaker Updates & Downloads => Share New Actions => Topic started 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.
-
Thanks, just what I needed and seems to work perfectly so far.
Br,
Szomaza
-
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.
// (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);
}
}
}
}
-
Sounds good! Must have improvements!
Thanks for sharing, doppelmonster.
br,
szomaza
-
Cool! I should have added that from the start. =)