Playmaker Forum

Playmaker Updates & Downloads => Share New Actions => Topic started by: giyomu on July 20, 2011, 05:04:23 PM

Title: ReadBool.cs
Post by: giyomu on July 20, 2011, 05:04:23 PM
Inspired form jean action,

a ReadBool, that allow you to not need store variable eventually and just pass directly an event from the value you read.

Code: [Select]
using UnityEngine;
using HutongGames.PlayMaker;

[Tooltip("Read a bool from another Fsm, either store it value and assign it to another variable in this fsm , or just send event from the value found")]
public class ReadBool : FsmStateAction
public FsmOwnerDefault gameObject;
[Tooltip("Optional name of FSM on Game Object")]
public FsmString fsmName;
public FsmString variableName;
public FsmBool storeValue;
public FsmEvent IsTrue;
public FsmEvent IsFalse;
public bool everyFrame;

GameObject goLastFrame;
PlayMakerFSM fsm;

// cache
GameObject go;

public override void Reset ()
gameObject = null;
fsmName = "";
storeValue = null;
IsTrue = null;
IsFalse = null;

public override void OnEnter ()
// get owner reference and cache it here
go = Fsm.GetOwnerDefaultTarget(gameObject);



void DoReadBool()
if (go == null)

// only get the fsm component if go has changed
if (go != goLastFrame)
goLastFrame = go;
fsm = ActionHelpers.GetGameObjectFsm(go, fsmName.Value);

if (fsm == null)

FsmBool fsmBool = fsm.FsmVariables.GetFsmBool(variableName.Value);

if (fsmBool == null)

// store in variable if defined
if(storeValue != null)
storeValue.Value = fsmBool.Value;

// send event if not null
if(IsFalse != null && fsmBool.Value == false)
else if(IsTrue != null && fsmBool.Value == true)