示例#1
0
        /// <summary>Main thread wait for given seconds, max 5 min.</summary>
        public static void WaitForSeconds(int _Seconds)
        {
            int secs = HEVMath.Clamp(_Seconds, 0, 300);

#if UNITY_EDITOR || UNITY_STANDALONE
            new WaitForSeconds(secs);
#else
            System.Threading.Thread.Sleep(secs * 1000);
#endif
        }
示例#2
0
文件: HEVIO.cs 项目: Hevedy/HevLib
        // Integer
        public static bool DataINIReadWrite(this IniData _Data, string _Section, string _Key, ref int _Value, bool _Write = true, bool _Clamp = false, int _Min = 0, int _Max = 9999)
        {
            IniData data   = _Data;
            bool    status = false;
            int     value  = _Value;

            if (!HEVText.TryParse(data[_Section][_Key], out value, false))
            {
                value = _Value;
                if (_Clamp)
                {
                    value = HEVMath.Clamp(value, _Min, _Max);
                }
                if (_Write)
                {
                    data[_Section][_Key] = value.ToString();
                }
                status = false;
            }
            else
            {
                if (HEVMath.Validate(_Min, _Max, value))
                {
                    status = true;
                }
                else
                {
                    if (_Clamp)
                    {
                        value  = HEVMath.Clamp(value, _Min, _Max);
                        status = false;
                    }
                    else
                    {
                        status = true;
                    }
                }
            }
            _Data  = data;
            _Value = value;
            return(status);
        }
示例#3
0
        public static bool TryParse(string _String, out int _Result, bool _Clamp = false, int _Min = 0, int _Max = 9999)
        {
            int value = -1;

            if (!Validate(_String))
            {
                _Result = value; return(false);
            }
            string str = _String.ToLower();

            if (!int.TryParse(str, out value))
            {
                _Result = value; return(false);
            }

            if (_Clamp)
            {
                int min = HEVMath.Min(_Min, _Max);
                int max = HEVMath.Max(_Min, _Max);
                if (min == max)
                {
                    value = max;
                }
                else
                {
                    value = HEVMath.Clamp(value, min, max);
                }
            }
            _Result = value;
            return(true);

            /* Sensitive
             * if ( HEVMath.Validate( _Min, _Max, value ) ) {
             *      _Result = value;
             *      return true;
             * } else {
             *      value = Math.Clamp( value, _Min, _Max );
             *      _Result = value;
             *      return false;
             * }
             */
        }