DiscardLeastSignificantDecimal() статический приватный Метод

static private DiscardLeastSignificantDecimal ( double v ) : double
v double
Результат double
Пример #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;
        }
Пример #2
0
 internal static double RoundBasedOnMinimumDifference(double valueToRound, double minDifference)
 {
     if (minDifference == 0.0)
     {
         return(MathUtils.DiscardLeastSignificantDecimal(valueToRound));
     }
     return(Math.Round(valueToRound, MathUtils.GetNumberOfDecimalsForMinimumDifference(minDifference), MidpointRounding.AwayFromZero));
 }
Пример #3
0
 internal static void AnimProp(GUIContent label, SerializedProperty prop, float min, float max, bool useNormalizedValue)
 {
     InitStyles();
     if (prop.hasMultipleDifferentValues)
     {
         EditorGUILayout.TargetChoiceField(prop, label, new GUILayoutOption[0]);
     }
     else
     {
         AnimationCurve animationCurveValue = prop.animationCurveValue;
         if (animationCurveValue == null)
         {
             Debug.LogError(label.text + " curve is null!");
         }
         else if (animationCurveValue.length == 0)
         {
             Debug.LogError(label.text + " curve has no keys!");
         }
         else
         {
             if (animationCurveValue.length != 1)
             {
                 using (new EditorGUI.DisabledScope(true))
                 {
                     EditorGUILayout.LabelField(label.text, ms_Styles.controlledByCurveLabel, new GUILayoutOption[0]);
                 }
             }
             else
             {
                 float v = !useNormalizedValue ? animationCurveValue.keys[0].value : Mathf.Lerp(min, max, animationCurveValue.keys[0].value);
                 v = MathUtils.DiscardLeastSignificantDecimal(v);
                 EditorGUI.BeginChangeCheck();
                 if (max > min)
                 {
                     v = EditorGUILayout.Slider(label, v, min, max, new GUILayoutOption[0]);
                 }
                 else
                 {
                     v = EditorGUILayout.Slider(label, v, max, min, new GUILayoutOption[0]);
                 }
                 if (EditorGUI.EndChangeCheck())
                 {
                     Keyframe key = animationCurveValue.keys[0];
                     key.time  = 0f;
                     key.value = !useNormalizedValue ? v : Mathf.InverseLerp(min, max, v);
                     animationCurveValue.MoveKey(0, key);
                 }
             }
             prop.animationCurveValue = animationCurveValue;
         }
     }
 }
Пример #4
0
        internal static float RoundBasedOnMinimumDifference(float valueToRound, float minDifference)
        {
            float result;

            if (minDifference == 0f)
            {
                result = MathUtils.DiscardLeastSignificantDecimal(valueToRound);
            }
            else
            {
                result = (float)Math.Round((double)valueToRound, MathUtils.GetNumberOfDecimalsForMinimumDifference(minDifference), MidpointRounding.AwayFromZero);
            }
            return(result);
        }
Пример #5
0
        internal static void AnimProp(GUIContent label, SerializedProperty prop, float min, float max, bool useNormalizedValue)
        {
            AudioSourceInspector.InitStyles();
            if (prop.hasMultipleDifferentValues)
            {
                EditorGUILayout.TargetChoiceField(prop, label, new GUILayoutOption[0]);
                return;
            }
            AnimationCurve animationCurveValue = prop.animationCurveValue;

            if (animationCurveValue == null)
            {
                Debug.LogError(label.text + " curve is null!");
                return;
            }
            if (animationCurveValue.length == 0)
            {
                Debug.LogError(label.text + " curve has no keys!");
                return;
            }
            if (animationCurveValue.length != 1)
            {
                EditorGUI.BeginDisabledGroup(true);
                EditorGUILayout.LabelField(label.text, AudioSourceInspector.ms_Styles.controlledByCurveLabel, new GUILayoutOption[0]);
                EditorGUI.EndDisabledGroup();
            }
            else
            {
                float num = (!useNormalizedValue) ? animationCurveValue.keys[0].value : Mathf.Lerp(min, max, animationCurveValue.keys[0].value);
                num = MathUtils.DiscardLeastSignificantDecimal(num);
                EditorGUI.BeginChangeCheck();
                if (max > min)
                {
                    num = EditorGUILayout.Slider(label, num, min, max, new GUILayoutOption[0]);
                }
                else
                {
                    num = EditorGUILayout.Slider(label, num, max, min, new GUILayoutOption[0]);
                }
                if (EditorGUI.EndChangeCheck())
                {
                    Keyframe key = animationCurveValue.keys[0];
                    key.time  = 0f;
                    key.value = ((!useNormalizedValue) ? num : Mathf.InverseLerp(min, max, num));
                    animationCurveValue.MoveKey(0, key);
                }
            }
            prop.animationCurveValue = animationCurveValue;
        }