hi, i saw the intSubtract on github with the per second option
and found this very interesting...
so i made this with the int operator.
// (c) Copyright HutongGames, LLC 2010-2015. All rights reserved.
// idea by Jean Fabre
// edited by DjayDino
/*--- __ECO__ __ACTION__ ---*/
using UnityEngine;
namespace HutongGames.PlayMaker.Actions
{
[ActionCategory(ActionCategory.Math)]
[Tooltip("Performs math operations on 2 Floats: Add, Subtract, Multiply, Divide, Min, Max.")]
public class IntOperatorPerSecond : FsmStateAction
{
public enum Operation
{
Add,
Subtract,
Multiply,
Divide
}
[RequiredField]
[UIHint(UIHint.Variable)]
[Tooltip("The int variable to add / subtract / multiply / divide from and store")]
public FsmInt intVariable;
[RequiredField]
[Tooltip("The int variable to add / subtract / multiply / divide")]
public FsmInt intOperator;
[Tooltip("The math operation to perform on the intVariable.")]
public Operation operation = Operation.Add;
[RequiredField]
[UIHint(UIHint.Variable)]
[Tooltip("Used with Every Frame. Adds the value over one second to make the operation frame rate independent.")]
public bool perSecond;
[Tooltip("Repeat every frame. Useful if the variables are changing.")]
public bool everyFrame;
float _acc = 0f;
public override void Reset()
{
intOperator = null;
operation = Operation.Add;
intVariable = null;
perSecond = false;
everyFrame = false;
}
public override void OnEnter()
{
DoIntOperator();
if (!everyFrame)
{
Finish();
}
}
public override void OnUpdate()
{
DoIntOperator();
}
void DoIntOperator()
{
if (!perSecond)
{
switch (operation)
{
case Operation.Add:
intVariable.Value += intOperator.Value;
break;
case Operation.Subtract:
intVariable.Value -= intOperator.Value;
break;
case Operation.Multiply:
intVariable.Value *= intOperator.Value;
break;
case Operation.Divide:
intVariable.Value /= intOperator.Value;
break;
}
}
else
{
switch (operation)
{
case Operation.Add:
DoIntAdd();
break;
case Operation.Subtract:
DoIntSubtract();
break;
case Operation.Multiply:
DoIntMultiply();
break;
case Operation.Divide:
DoIntDivide();
break;
}
}
}
void DoIntAdd()
{
int _absSub = Mathf.Abs(intOperator.Value);
_acc += ( _absSub* Time.deltaTime);
if (_acc>=_absSub)
{
_acc = 0f;
intVariable.Value += intOperator.Value;
}
}
void DoIntSubtract()
{
int _absSub = Mathf.Abs(intOperator.Value);
_acc += ( _absSub* Time.deltaTime);
if (_acc>=_absSub)
{
_acc = 0f;
intVariable.Value -= intOperator.Value;
}
}
void DoIntMultiply()
{
int _absSub = Mathf.Abs(intOperator.Value);
_acc += ( _absSub* Time.deltaTime);
if (_acc>=_absSub)
{
_acc = 0f;
intVariable.Value *= intOperator.Value;
}
}
void DoIntDivide()
{
int _absSub = Mathf.Abs(intOperator.Value);
_acc += ( _absSub* Time.deltaTime);
if (_acc>=_absSub)
{
_acc = 0f;
intVariable.Value /= intOperator.Value;
}
}
}
}
the divide option will end in 0, and will always Round to int value
i am still doubting to take it out or not, but i think its ok
let me know if i should add this , and/or if i should take out the divide option.
friendly greetings,
Dino