Esempio n. 1
0
        public static (string[], bool) GetStringArrayLines(string[] _String, int _StartLine = 0, int _EndLine = -1)
        {
            string[] lines    = _String;
            int      lastLine = 0;

            if (lines.Length < 1)
            {
                HEVConsole.Print("GetStringArrayLines() Empty string array.", EPrintType.eError);
                return(lines, false);
            }
            lastLine = lines.Length - 1;
            if (_StartLine == 0 && _EndLine == -1)
            {
            }
            else if (_StartLine == -1)
            {
                lines = new string[] { lines[lastLine] };
            }
            else
            {
                int startLine = HEVMath.Max(_StartLine, 0);
                startLine = HEVMath.Min(startLine, lastLine);
                int endLine = HEVMath.Min(_EndLine, lastLine);
                endLine = HEVMath.Max(_StartLine, _EndLine);
                List <string> linesList = new List <string>();
                for (int i = startLine; i < endLine; i++)
                {
                    linesList.Add(lines[i]);
                }
                lines = linesList.ToArray();
            }
            return(lines, true);
        }
Esempio n. 2
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
        }
Esempio n. 3
0
        /// <summary>Print on console an empty line jump or line break.</summary>
        public static void LineJump(int _Lines = 1)
        {
            int lines = HEVMath.Min(_Lines, 10);

#if UNITY_EDITOR || UNITY_STANDALONE
#else
            for (int i = 0; i < lines; i++)
            {
                Console.WriteLine();
            }
#endif
        }
Esempio n. 4
0
        public static int CryptoRandomInt(int _Min, int _Max)
        {
            byte[] randomNumber = new byte[1];
            CryptoGenerator.GetBytes(randomNumber);

            double asciiValueOfRandomCharacter = Convert.ToDouble(randomNumber[0]);
            double multiplier         = HEVMath.Max(0, (asciiValueOfRandomCharacter / 255d) - 0.00000000001d);
            int    range              = _Max - _Min + 1;
            double randomValueInRange = HEVMath.Floor(multiplier * range);

            return((int)(_Min + randomValueInRange));
        }
Esempio n. 5
0
        // 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);
        }
Esempio n. 6
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;
             * }
             */
        }
Esempio n. 7
0
        public static int CryptoRandomInt(uint _Length = 1)
        {
            int length = (int)HEVMath.Max(1, _Length);

            return(CryptoRandomInt(0, (10 ^ length) - 1));
        }