目录
* 作者:闪电Y黑客
* 日期:2019.6.20
* 功能:一些简单的计算
1.NearlyNumber 求最近值的间隔个数
/// <summary>
/// 求最近值的间隔个数
/// </summary>
/// <param name="NowValue">数值</param>
/// <param name="Distance">间隔距离</param>
/// <returns>间隔个数</returns>
static public int NearlyNumber(float NowValue, float Distance)
{
float saveValue = 0;
float RedundantValue;
int saveNum = 0;
RedundantValue = NowValue % Distance;
saveValue = NowValue - RedundantValue;
saveValue += Mathf.RoundToInt(RedundantValue / Distance) * Distance;
saveNum = (int)(saveValue / Distance);
return saveNum;
}
2.NearlyValue 求最近值
/// <summary>
/// 求最近值
/// </summary>
/// <param name="NowValue">数值</param>
/// <param name="Distance">间隔距离</param>
/// <returns>最近值</returns>
static public float NearlyValue(float NowValue, float Distance)
{
float saveValue = 0;
float RedundantValue;
RedundantValue = NowValue % Distance;
saveValue = NowValue - RedundantValue;
saveValue += Mathf.RoundToInt(RedundantValue / Distance) * Distance;
return saveValue;
}
全篇:
using UnityEngine;
/*
* 作者:闪电Y黑客
*
* 日期:2019.6.20
*
* 功能:一些简单的计算
*
*/
namespace SDHK_Tool.Static
{
/// <summary>
/// 数学类
/// </summary>
static public class SS_Mathf
{
/// <summary>
/// 求最近值的间隔个数
/// </summary>
/// <param name="NowValue">数值</param>
/// <param name="Distance">间隔距离</param>
/// <returns>间隔个数</returns>
static public int NearlyNumber(float NowValue, float Distance)
{
float saveValue = 0;
float RedundantValue;
int saveNum = 0;
RedundantValue = NowValue % Distance;
saveValue = NowValue - RedundantValue;
saveValue += Mathf.RoundToInt(RedundantValue / Distance) * Distance;
saveNum = (int)(saveValue / Distance);
return saveNum;
}
/// <summary>
/// 求最近值
/// </summary>
/// <param name="NowValue">数值</param>
/// <param name="Distance">间隔距离</param>
/// <returns>最近值</returns>
static public float NearlyValue(float NowValue, float Distance)
{
float saveValue = 0;
float RedundantValue;
RedundantValue = NowValue % Distance;
saveValue = NowValue - RedundantValue;
saveValue += Mathf.RoundToInt(RedundantValue / Distance) * Distance;
return saveValue;
}
}
}