playMaker

Author Topic: FloatRoundToDecimal  (Read 3363 times)

ransomink

  • Playmaker Newbie
  • *
  • Posts: 44
FloatRoundToDecimal
« on: January 03, 2018, 05:52:18 AM »
I have a few other actions I did so I might as well place them here to see if they're of use to anyone else. This action will round a float to a number of specified decimal places. The other actions I saw didn't do this...

Code: [Select]
// (c) Copyright HutongGames, LLC 2010-2018. All rights reserved.
// author : ransomink
// Keywords: decimal, float, round
/*--- __ECO__ __PLAYMAKER__ __ACTION__ ---*/

using UnityEngine;

namespace HutongGames.PlayMaker.Actions
{

    [ActionCategory(ActionCategory.Math)]
[Tooltip("Round a Float value to the nearest whole number or add a specified number of decimal places.")]
public class FloatRoundToDecimal : FsmStateAction
{
[RequiredField]
[UIHint(UIHint.Variable)]
[Tooltip("The float value to round. The end result will remain as a float, not an integer.")]
public FsmFloat floatVariable;

        [Tooltip("The number of digits after a decimal point.")]
public FsmInt digits;

        [UIHint(UIHint.Variable)]
        public FsmFloat storeResult;

        public bool everyFrame;

public override void Reset()
{
floatVariable = null;
digits        = null;
            storeResult   = null;
everyFrame    = false;
}

public override void OnEnter()
{
DoRoundFloat();

if (!everyFrame)
{
Finish();
}
}

public override void OnUpdate()
{
DoRoundFloat();
}

void DoRoundFloat()
{
            if ( storeResult.IsNone )
            {
                floatVariable.Value = ( float )System.Math.Round( floatVariable.Value, digits.Value );
            }
            else
            {
                storeResult.Value = ( float )System.Math.Round( floatVariable.Value, digits.Value );
            }
}
}

}

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: FloatRoundToDecimal
« Reply #1 on: January 29, 2018, 03:53:55 AM »
Hi,

 Cool, thanks for contributing! You could maybe put it on the Ecosystem? Are you ok with github?

 Bye,

 Jean

ransomink

  • Playmaker Newbie
  • *
  • Posts: 44
Re: FloatRoundToDecimal
« Reply #2 on: February 03, 2018, 03:43:50 PM »
I'd be glad to but I haven't really used it before, any tips?

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: FloatRoundToDecimal
« Reply #3 on: February 07, 2018, 04:06:18 AM »
Hi,

 Cool, you need a github account, once you have one, pm me and I'll give you access to the Ecosystem repositories, you clone them on your computer, and open them using Unity ( each rep needs to be open with the right version of Unity), then you check your action and put it inside the lowest possible repository in terms of Unity version. You can safely start with the Unity 5 repository, but if an action only works starting from Uity 2017, then it's another one.

 so you put your action in the rep, check it works inside this rep and doesn't produce errors, and you commit and push, it becomes instantly visible to the Ecosystem ( given a series of convention, check out the header of other ecosystem actions)

 Bye,

 Jean

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: FloatRoundToDecimal
« Reply #4 on: February 04, 2019, 01:18:04 AM »
Hi,

 ok, just gave you access.

here the run down:

- Repositories are organized per Unity versions ( finishing with _Uxxxx), you need to put action in the lowest possible repository. Ignore Unity 4 repository, I am going to soon deprecate it and move all its content to U5

- when you add an action, you need to make sure it compiles ok, so you need to have all the necessary Unity editors. For Unity 5.6, Unity 2017 lts, and Unity 2018.3 ( Use Unity hub to manage this, it's easy).

- pull a given repository, open that repository with the right version of Unity, verify it compiles ok, add your actions, verify it's ok, then you can commit and push


Let's try with one action first, let me know when you have pushed, and I'll double check on my end. I am on skype/slack/discord, let me know if you have questions.

Bye,

 Jean