playMaker

Author Topic: GameObject Is Active In Hierarchy  (Read 6225 times)

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
GameObject Is Active In Hierarchy
« 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.
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D

szomaza

  • Sr. Member
  • ****
  • Posts: 253
Re: GameObject Is Active In Hierarchy
« Reply #1 on: May 27, 2014, 01:39:37 AM »
Thanks, just what I needed and seems to work perfectly so far.

Br,
Szomaza

doppelmonster

  • Full Member
  • ***
  • Posts: 157
    • Grinder Games
Re: GameObject Is Active In Hierarchy
« Reply #2 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);
}
}
}
}

szomaza

  • Sr. Member
  • ****
  • Posts: 253
Re: GameObject Is Active In Hierarchy
« Reply #3 on: February 27, 2015, 08:48:00 AM »
Sounds good! Must have improvements!
Thanks for sharing, doppelmonster.

br,
szomaza

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Re: GameObject Is Active In Hierarchy
« Reply #4 on: February 27, 2015, 12:37:11 PM »
Cool! I should have added that from the start. =)
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D