UnityEngine.Mathf.Clamp01 C# (CSharp) Method

Clamp01() public static method

public static Clamp01 ( float value ) : float
value float
return float
        public static float Clamp01(float value)
        {
            if (value < 0f)
                return 0f;
            return value > 1.0 ? 1f : value;
        }

Usage Example

コード例 #1
0
        void Tick()
        {
            if (Event.current.type == EventType.Repaint)
            {
                float deltaTime = Time.realtimeSinceStartup - lastUpdate;

                // Right at the start of a transition the deltaTime will
                // not be reliable, so use a very small value instead
                // until the next repaint
                if (value == 0f || value == 1f)
                {
                    deltaTime = 0.001f;
                }
                deltaTime = Mathf.Clamp(deltaTime, 0.00001F, 0.1F);

                // Larger regions fade slightly slower
                deltaTime /= Mathf.Sqrt(Mathf.Max(lastRect.height, 100));

                lastUpdate = Time.realtimeSinceStartup;


                float targetValue = open ? 1F : 0F;
                if (!Mathf.Approximately(targetValue, value))
                {
                    value += deltaTime * animationSpeed * Mathf.Sign(targetValue - value);
                    value  = Mathf.Clamp01(value);
                    editor.Repaint();

                    if (!fancyEffects)
                    {
                        value = targetValue;
                    }
                }
                else
                {
                    value = targetValue;
                }
            }
        }
All Usage Examples Of UnityEngine.Mathf::Clamp01