Skip to content

Added MultiTagSwitch for be able to iterate over the multi tags given… #10

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
102 changes: 102 additions & 0 deletions Assets/PlayMaker Custom Actions/Logic/FloatAndBoolDecision.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
using System;

namespace HutongGames.PlayMaker.Actions
{
[ActionCategory(ActionCategory.Logic)]
[Tooltip("Make decision by accepting multiple data types. Returns a bool.")]
public class FloatAndBoolDecision : FsmStateAction
{
public enum Operation
{
Greater,
Lower,
Equals,
GreaterThenEquals,
LowerThenEquals
}

[RequiredField] [UIHint(UIHint.Variable)] [Tooltip("The float variable should be tested.")]
public FsmFloat targetFloat;

[RequiredField] [UIHint(UIHint.Variable)] [Tooltip("The tester float variable.")]
public FsmFloat testerFloat;

[RequiredField] [Tooltip("Operation which is used between the target and tester.")]
public Operation operation = Operation.Equals;

[RequiredField]
[UIHint(UIHint.Variable)]
[Tooltip("Boolean to be tested, which is used with short circuit and statement.")]
public FsmBool targetBool;

[Tooltip("Event to send if the Bool variable is True.")]
public FsmEvent isTrue;

[Tooltip("Event to send if the Bool variable is False.")]
public FsmEvent isFalse;

public bool everyFrame;

// Code that runs on entering the state.
public override void OnEnter()
{
Fsm.Event(areTheyTrue().Value ? isTrue : isFalse);

if (!everyFrame)
Finish();
}

// Code that runs every frame.
public override void OnUpdate()
{
Fsm.Event(areTheyTrue().Value ? isTrue : isFalse);
}

public override void Reset()
{
targetFloat = null;
testerFloat = null;
targetBool = false;
isTrue = null;
isFalse = null;
everyFrame = false;
}

// Perform custom error checking here.
public override string ErrorCheck()
{
return null;
}


private FsmBool areTheyTrue()
{
FsmBool result = new FsmBool();

switch (operation)
{
case Operation.Equals:
result = targetFloat.Value.Equals(testerFloat.Value) && targetBool.Value;
break;

case Operation.Greater:
result = targetFloat.Value > testerFloat.Value && targetBool.Value;
break;

case Operation.Lower:
result = targetFloat.Value < testerFloat.Value && targetBool.Value;
break;

case Operation.GreaterThenEquals:
result = targetFloat.Value >= testerFloat.Value && targetBool.Value;
break;

case Operation.LowerThenEquals:
result = targetFloat.Value <= testerFloat.Value && targetBool.Value;
break;
}

return result;
}
}
}
101 changes: 101 additions & 0 deletions Assets/PlayMaker Custom Actions/Logic/IntAndBoolDecision.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
namespace HutongGames.PlayMaker.Actions
{

[ActionCategory(ActionCategory.Logic)]
[Tooltip("Make decision by accepting multiple data types. Returns a bool.")]
public class IntAndBoolDecision: FsmStateAction
{
public enum Operation
{
Greater,
Lower,
Equals,
GreaterThenEquals,
LowerThenEquals
}

[RequiredField] [UIHint(UIHint.Variable)] [Tooltip("The float variable should be tested.")]
public FsmInt targetVariable;

[RequiredField] [Tooltip("The tester float variable.")]
public FsmInt testerVariable;

[RequiredField] [Tooltip("Operation which is used between the target and tester.")]
public Operation operation = Operation.Equals;

[RequiredField]
[UIHint(UIHint.Variable)]
[Tooltip("Boolean to be tested, which is used with short circuit and statement.")]
public FsmBool targetBool;

[Tooltip("Event to send if the Bool variable is True.")]
public FsmEvent isTrue;

[Tooltip("Event to send if the Bool variable is False.")]
public FsmEvent isFalse;

public bool everyFrame;

// Code that runs on entering the state.
public override void OnEnter()
{
Fsm.Event(areTheyTrue().Value ? isTrue : isFalse);

if (!everyFrame)
Finish();
}

// Code that runs every frame.
public override void OnUpdate()
{
Fsm.Event(areTheyTrue().Value ? isTrue : isFalse);
}

public override void Reset()
{
targetVariable = null;
testerVariable = null;
targetBool = false;
isTrue = null;
isFalse = null;
everyFrame = false;
}

// Perform custom error checking here.
public override string ErrorCheck()
{
return null;
}


private FsmBool areTheyTrue()
{
FsmBool result = new FsmBool();

switch (operation)
{
case Operation.Equals:
result = targetVariable.Value.Equals(testerVariable.Value) && targetBool.Value;
break;

case Operation.Greater:
result = targetVariable.Value > testerVariable.Value && targetBool.Value;
break;

case Operation.Lower:
result = targetVariable.Value < testerVariable.Value && targetBool.Value;
break;

case Operation.GreaterThenEquals:
result = targetVariable.Value >= testerVariable.Value && targetBool.Value;
break;

case Operation.LowerThenEquals:
result = targetVariable.Value <= testerVariable.Value && targetBool.Value;
break;
}

return result;
}
}
}
111 changes: 111 additions & 0 deletions Assets/PlayMaker Custom Actions/Logic/IntAndFloatAndBoolDecision.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
using static HutongGames.PlayMaker.Actions.FloatAndBoolDecision;

namespace HutongGames.PlayMaker.Actions.Logic
{

/// <summary>
/// Author is Istvan Nemeth. <see cref="https://github.com/PlayMakerEcosystem/PlayMakerCustomActions_U5"/>
/// </summary>
[ActionCategory(ActionCategory.Logic)]
[Tooltip("Make decision by accepting multiple data types. Returns a bool.")]
public class IntAndFloatAndBoolDecision : FsmStateAction
{
[RequiredField] [UIHint(UIHint.Variable)] [Tooltip("The int variable should be tested.")]
public FsmInt targetInt;

[RequiredField] [UIHint(UIHint.Variable)] [Tooltip("The tester int variable.")]
public FsmInt testerInt;

[RequiredField]
[Tooltip("Operation which is used between the target and tester.")]
public Operation intOperation = Operation.Equals;

[RequiredField] [UIHint(UIHint.Variable)] [Tooltip("The float variable should be tested.")]
public FsmFloat targetFloat;

[RequiredField] [UIHint(UIHint.Variable)] [Tooltip("The tester float variable.")]
public FsmFloat testerFloat;

[RequiredField]
[Tooltip("Operation which is used between the target and tester.")]
public Operation floatOperation = Operation.Equals;

[RequiredField]
[UIHint(UIHint.Variable)]
[Tooltip("Boolean to be tested, which is used with short circuit and statement.")]
public FsmBool targetBool;

[Tooltip("Event to send if the Bool variable is True.")]
public FsmEvent isTrue;

[Tooltip("Event to send if the Bool variable is False.")]
public FsmEvent isFalse;

public bool everyFrame;

// Code that runs on entering the state.
public override void OnEnter()
{
Fsm.Event(areTheyTrue().Value ? isTrue : isFalse);

if (!everyFrame)
Finish();
}

// Code that runs every frame.
public override void OnUpdate()
{
Fsm.Event(areTheyTrue().Value ? isTrue : isFalse);
}

public override void Reset()
{
targetFloat = null;
testerFloat = null;
targetBool = false;
isTrue = null;
isFalse = null;
everyFrame = false;
}

private FsmBool areTheyTrue()
{
FsmBool result = new FsmBool();

if (intOperation == Operation.Equals)
{
result = targetInt.Value.Equals(testerInt.Value);
if (floatOperation == Operation.Equals)
{
result = result.Value && targetFloat.Value.Equals(testerFloat.Value) && targetBool.Value;
}
}


switch (floatOperation)
{
case Operation.Equals:
result = targetFloat.Value.Equals(testerFloat.Value) && targetBool.Value;
break;

case Operation.Greater:
result = targetFloat.Value > testerFloat.Value && targetBool.Value;
break;

case Operation.Lower:
result = targetFloat.Value < testerFloat.Value && targetBool.Value;
break;

case Operation.GreaterThenEquals:
result = targetFloat.Value >= testerFloat.Value && targetBool.Value;
break;

case Operation.LowerThenEquals:
result = targetFloat.Value <= testerFloat.Value && targetBool.Value;
break;
}

return result;
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

68 changes: 68 additions & 0 deletions Assets/PlayMaker Custom Actions/Logic/MultiTagSwitch.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
using UnityEngine;

namespace HutongGames.PlayMaker.Actions
{

[ActionCategory(ActionCategory.Logic)]
[Tooltip("Iterate over the tags on the given gameobject. Defines for each an exit point as a switch flow control statement.")]
public class MultiTagSwitch : FsmStateAction
{
[RequiredField]
[UIHint(UIHint.Variable)]
[Tooltip("The GameObject to be tested.")]
public FsmGameObject gameObject;

[UIHint(UIHint.Tag)]
[Tooltip("The Tag to check for.")]
[CompoundArray("Tag switches", "Compare Tag", "Send Event")]
public FsmString[] compareTo;

[Tooltip("On compare success, the event to be sent.")]
public FsmEvent[] sendEvent;

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

[Tooltip("Store the matching Tag in a String variable.")]
public FsmString storeTag;

public override void Reset()
{
gameObject = null;
compareTo = new FsmString[1];
sendEvent = new FsmEvent[1];
everyFrame = false;
storeTag = null;
}

// Code that runs on entering the state.
public override void OnEnter()
{
CompareAllTags();

if (!everyFrame)
Finish();
}

// Code that runs every frame.
public override void OnUpdate()
{
CompareAllTags();
}

void CompareAllTags()
{
for (int i=0; i<compareTo.Length; i++)
{
if (gameObject.Value != null)
{
if (gameObject.Value.CompareTag(compareTo[i].Value))
{
Fsm.Event(sendEvent[i]);
storeTag = compareTo[i].Value;
}
}
}
}
}
}
Loading