playMaker

Author Topic: Float Window Test  (Read 2980 times)

qholmes

  • 1.2 Beta
  • Hero Member
  • *
  • Posts: 509
    • View Profile
Float Window Test
« on: October 19, 2011, 07:38:33 AM »
Here is a little Action i made for doing a window test on float values.. has been very handy for me. Dont think there was already one here.. but i have been wrong before.

Q

Code: [Select]
//



using UnityEngine;



namespace HutongGames.PlayMaker.Actions

{

[ActionCategory(ActionCategory.Logic)]

[Tooltip("Sends Events based on a float being inside a window of values.")]

public class FloatWindowCompare : FsmStateAction

{

[RequiredField]

[Tooltip("Float to Check")]

public FsmFloat floatTest;

[RequiredField]

[Tooltip("Lower limit for window")]

public FsmFloat floatLower;

[RequiredField]

[Tooltip("Upper limit for window")]

public FsmFloat floatUpper;

[Tooltip("Event sent if FloatTest is inside the window")]

public FsmEvent inWindow;

[Tooltip("Event sent if FloatTest is outside the window")]

public FsmEvent outOfWindow;

public bool everyFrame;



public override void Reset()

{

floatTest = 0f;

floatLower = 0f;

floatUpper = 0f;

inWindow = null;

outOfWindow = null;

everyFrame = false;

}



public override void OnEnter()

{

DoCompare();



if (!everyFrame)

Finish();

}



public override void OnUpdate()

{

DoCompare();

}



void DoCompare()

{



if (floatTest.Value > floatLower.Value && floatTest.Value < floatUpper.Value)

{

Fsm.Event(inWindow);

return;

}



if (floatTest.Value < floatLower.Value || floatTest.Value > floatUpper.Value)

{

Fsm.Event(outOfWindow);

return;

}



}



public override string ErrorCheck()

{

if (FsmEvent.IsNullOrEmpty(inWindow ) &&

FsmEvent.IsNullOrEmpty(outOfWindow))

return "Action sends no events!";

return "";

}

}

}

Dev_Sebas

  • 1.2 Beta
  • Sr. Member
  • *
  • Posts: 398
    • View Profile
    • Blog
Re: Float Window Test
« Reply #1 on: October 19, 2011, 07:52:34 AM »
Good luck

qholmes

  • 1.2 Beta
  • Hero Member
  • *
  • Posts: 509
    • View Profile
Re: Float Window Test
« Reply #2 on: October 19, 2011, 07:53:32 AM »
with what?


Q

Dev_Sebas

  • 1.2 Beta
  • Sr. Member
  • *
  • Posts: 398
    • View Profile
    • Blog
Re: Float Window Test
« Reply #3 on: October 19, 2011, 07:57:02 AM »
With your amazing scripts

qholmes

  • 1.2 Beta
  • Hero Member
  • *
  • Posts: 509
    • View Profile
Re: Float Window Test
« Reply #4 on: October 19, 2011, 07:59:15 AM »
Ahh thanks...  ;D

but mine are very simple..

Q

Dev_Sebas

  • 1.2 Beta
  • Sr. Member
  • *
  • Posts: 398
    • View Profile
    • Blog
Re: Float Window Test
« Reply #5 on: October 19, 2011, 08:04:37 AM »
For me it´s horrible the scripts
And thanks by your script I will test it later