UnityEditor.MathUtils.DiscardLeastSignificantDecimal C# (CSharp) Method

DiscardLeastSignificantDecimal() static private method

static private DiscardLeastSignificantDecimal ( double v ) : double
v double
return double
        internal static double DiscardLeastSignificantDecimal(double v)
        {
            int digits = Math.Max(0, (int) (5.0 - Math.Log10(Math.Abs(v))));
            try
            {
                return Math.Round(v, digits);
            }
            catch (ArgumentOutOfRangeException)
            {
                return 0.0;
            }
        }

Same methods

MathUtils::DiscardLeastSignificantDecimal ( float v ) : float

Usage Example

示例#1
0
        internal static void AnimProp(GUIContent label, SerializedProperty prop, float min, float max, bool useNormalizedValue)
        {
            // AnimProp can be called from other classes so styes have not necessarily been inited yet.
            InitStyles();

            if (prop.hasMultipleDifferentValues)
            {
                EditorGUILayout.TargetChoiceField(prop, label);
                return;
            }

            AnimationCurve curve = prop.animationCurveValue;

            if (curve == null)
            {
                Debug.LogError(label.text + " curve is null!");
                return;
            }
            else if (curve.length == 0)
            {
                Debug.LogError(label.text + " curve has no keys!");
                return;
            }

            Rect position = EditorGUILayout.GetControlRect();

            EditorGUI.BeginProperty(position, label, prop);
            if (curve.length != 1)
            {
                using (new EditorGUI.DisabledScope(true))
                {
                    EditorGUI.LabelField(position, label.text, ms_Styles.controlledByCurveLabel);
                }
            }
            else
            {
                float f = useNormalizedValue ? Mathf.Lerp(min, max, curve.keys[0].value) : curve.keys[0].value;
                f = MathUtils.DiscardLeastSignificantDecimal(f);
                EditorGUI.BeginChangeCheck();
                if (max > min)
                {
                    f = EditorGUI.Slider(position, label, f, min, max);
                }
                else
                {
                    f = EditorGUI.Slider(position, label, f, max, min);
                }

                if (EditorGUI.EndChangeCheck())
                {
                    Keyframe kf = curve.keys[0];
                    kf.time  = 0.0f;
                    kf.value = useNormalizedValue ? Mathf.InverseLerp(min, max, f) : f;
                    curve.MoveKey(0, kf);
                }
            }
            EditorGUI.EndProperty();

            prop.animationCurveValue = curve;
        }
All Usage Examples Of UnityEditor.MathUtils::DiscardLeastSignificantDecimal