UnityEngine.Mathf.Clamp C# (CSharp) Method

Clamp() public static method

public static Clamp ( float value, float min, float max ) : float
value float
min float
max float
return float
        public static float Clamp(float value, float min, float max)
        {
            if ((double)value < min)
                value = min;
            else if ((double)value > max)
                value = max;
            return value;
        }

Same methods

Mathf::Clamp ( int value, int min, int max ) : int

Usage Example

コード例 #1
0
#pragma warning restore 414

    KMSelectable[] ProcessTwitchCommand(string command)
    {
        command = command.ToLowerInvariant().Trim();

        if (Regex.IsMatch(command, @"^press +[0-9^, |&]+$"))
        {
            command = command.Substring(6).Trim();

            var presses   = command.Split(new[] { ',', ' ', '|', '&' }, StringSplitOptions.RemoveEmptyEntries);
            var pressList = new List <KMSelectable>();

            for (var i = 0; i < presses.Length; i++)
            {
                if (Regex.IsMatch(presses[i], @"^[0-9]{1,2}$"))
                {
                    pressList.Add(ModuleButtons[Math.Clamp(Math.Max(1, int.Parse(presses[i].ToString())) - 1, 0, ModuleButtons.Length - 1)]);
                }
            }

            return(pressList.ToArray());
        }

        if (Regex.IsMatch(command, @"^(submit|sub|s)$"))
        {
            return new[] { SubmitButton }
        }
        ;

        return(null);
    }
}
All Usage Examples Of UnityEngine.Mathf::Clamp