随着代码:结构扩展方法
someVector.FixRounding(); //round vector's values to integers if the difference is 1 epsilon
float x = someVector.x; //still getting old value
public static void FixRounding(this Vector3 v)
{
if (Mathf.Approximately(v.x, Mathf.Round(v.x))) v.x = Mathf.Round(v.x);
if (Mathf.Approximately(v.y, Mathf.Round(v.y))) v.y = Mathf.Round(v.y);
if (Mathf.Approximately(v.z, Mathf.Round(v.z))) v.z = Mathf.Round(v.z);
}
的FixRounding方法实际上并没有改变载体的价值观虽然Mathf.Approximately返回true。
请注意,截图会显示一个可能已经四舍五入的值。这就是为什么我建议使用往返格式或使用“BitConverter.DoubleToInt64Bits”显式转换为字符串。 –
@AlexeiLevenkov:现在完成 - 您可能想要删除您的评论。 –