public static string ConvertToHexString(UnityEngine.Color color)
        {
            int r = (int)(color.r * 255.0);
            int g = (int)(color.g * 255.0);
            int b = (int)(color.b * 255.0);
            int a = (int)(color.a * 255.0);

            if (color.a == 1.0f)
            {
                return(BetterStringBuilder.New()
                       .Append(decimalToHex[r >> 4])
                       .Append(decimalToHex[r & 15])
                       .Append(decimalToHex[g >> 4])
                       .Append(decimalToHex[g & 15])
                       .Append(decimalToHex[b >> 4])
                       .Append(decimalToHex[b & 15])
                       .ToString());
            }
            else
            {
                return(BetterStringBuilder.New()
                       .Append(decimalToHex[r >> 4])
                       .Append(decimalToHex[r & 15])
                       .Append(decimalToHex[g >> 4])
                       .Append(decimalToHex[g & 15])
                       .Append(decimalToHex[b >> 4])
                       .Append(decimalToHex[b & 15])
                       .Append(decimalToHex[a >> 4])
                       .Append(decimalToHex[a & 15])
                       .ToString());
            }
        }
        //// TODO [bgish]: This can be highly optimized.  Picking up where we last left off, or having
        ////               multiiple lists for playing audio sources vs non-playing audio sources.  It
        ////               works for now though, so going with it.
        private AudioSource GetAudioSource()
        {
            int poolCount = this.audioSourcePoolItems.Count;

            for (int i = 0; i < poolCount; i++)
            {
                if (this.audioSourcePoolItems[i].isPlaying == false)
                {
                    return(this.audioSourcePoolItems[i]);
                }
            }

            // If we got here, then we need to grow the pool
            Debug.LogError("AudioManager Pool Forced to Grow. Please set initial capacity ahead of time so this doesn't happen at runtime.", this);
            this.audioSourcePoolItems.Capacity = this.audioSourcePoolItems.Count + this.audioSourcePoolGrowSize;

            for (int i = 0; i < this.audioSourcePoolGrowSize; i++)
            {
                var poolItem = GameObject.Instantiate(this.audioSourcePrefab, this.audioPool.transform);
                poolItem.enabled = false;
                poolItem.name    = BetterStringBuilder.New().Append("Audio Source (").Append(this.audioSourcePoolItems.Count).Append(")").ToString();
                this.audioSourcePoolItems.Add(poolItem);
            }

            return(this.audioSourcePoolItems[poolCount]);
        }
Beispiel #3
0
        public static void SetLong(string key, long value, bool save = false)
        {
            SetString(key, BetterStringBuilder.New().Append(value).ToString());

            if (save)
            {
                Save();
            }
        }
Beispiel #4
0
        private void Update()
        {
            if (!this.cameraCache)
            {
                if (this.Dialog.Canvas.worldCamera)
                {
                    this.cameraCache = this.Dialog.Canvas.worldCamera;
                }
                else
                {
                    this.cameraCache = Camera.main;
                    this.Dialog.Canvas.worldCamera = this.cameraCache;
                }
            }

            if (this.showFps == false)
            {
                return;
            }

            this.fpsDeltaTime += Time.deltaTime;

            this.fpsCurrentTickCount++;

            if (this.fpsCurrentTickCount == this.fpsUpdateTicks)
            {
                float msec = (this.fpsDeltaTime / (float)this.fpsUpdateTicks) * 1000.0f;
                float fps  = 1.0f / (this.fpsDeltaTime / (float)this.fpsUpdateTicks);

                // building the new string
                BetterStringBuilder.New()
                .Append((int)msec)
                .Append(".")
                .Append(this.GetDecimalPoint(msec))
                .Append(" ms (")
                .Append((int)fps)
                .Append(".")
                .Append(this.GetDecimalPoint(fps))
                .Append(" fps)")
                .Set(this.GetCornerText(this.fpsCorner));

                this.fpsCurrentTickCount = 0;
                this.fpsDeltaTime        = 0.0f;
            }
        }
Beispiel #5
0
 private void UpdateText()
 {
     if (this.text != null)
     {
         if (this.intValue == int.MinValue)
         {
             this.text.text = this.unsetText;
         }
         else
         {
             BetterStringBuilder.New()
             .Append(this.prefixValue)
             .Append(this.intValue, this.format)
             .Append(this.postfixValue)
             .Set(this.text);
         }
     }
 }
Beispiel #6
0
        private BetterStringBuilder AppendAbbreviated(long value)
        {
            long   number    = value;
            long   remainder = 0;
            string postfix   = string.Empty;

            if (value >= Billion)
            {
                number    = value / Billion;
                remainder = (value - (number * Billion)) / (Billion / 10);
                postfix   = "B";
            }
            else if (value >= Million)
            {
                number    = value / Million;
                remainder = (value - (number * Million)) / (Million / 10);
                postfix   = "M";
            }
            else if (value >= Thousand)
            {
                number    = value / Thousand;
                remainder = (value - (number * Thousand)) / (Thousand / 10);
                postfix   = "K";
            }

            if (remainder != 0)
            {
                return(BetterStringBuilder.New()
                       .Append(number)
                       .Append(Localization.Localization.GetDecimalPointSeperator())
                       .Append(remainder)
                       .Append(postfix));
            }
            else
            {
                return(BetterStringBuilder.New().Append(number).Append(postfix));
            }
        }
Beispiel #7
0
        private void UpdateText()
        {
            // update text can be called before Awake is called, so this is very necessary, but this will get called again OnEnable
            if (this.text == null)
            {
                return;
            }

            int days    = this.seconds / 60 / 60 / 24;
            int hours   = (this.seconds / 60 / 60) % 24;
            int minutes = (this.seconds / 60) % 60;
            int seconds = this.seconds % 60;

            switch (this.GetFormat())
            {
            case TimespanTextFormat.ColonSeparatedDHMS:
            {
                BetterStringBuilder.New()
                .Append(days).Append(":")
                .AppendTwoDigitNumber(hours).Append(":")
                .AppendTwoDigitNumber(minutes).Append(":")
                .AppendTwoDigitNumber(seconds)
                .Set(this.text);

                break;
            }

            case TimespanTextFormat.ColonSeparatedHMS:
            {
                BetterStringBuilder.New()
                .Append((days * 24) + hours).Append(":")
                .AppendTwoDigitNumber(minutes).Append(":")
                .AppendTwoDigitNumber(seconds)
                .Set(this.text);

                break;
            }

            case TimespanTextFormat.ColonSeparatedMS:
            {
                BetterStringBuilder.New()
                .Append((((days * 24) + hours) * 60) + minutes).Append(":")
                .AppendTwoDigitNumber(seconds)
                .Set(this.text);

                break;
            }

            case TimespanTextFormat.ColonSeparatedS:
            {
                BetterStringBuilder.New()
                .Append(this.seconds)
                .Set(this.text);

                break;
            }

            case TimespanTextFormat.SingleLettersDHMS:
            {
                BetterStringBuilder.New()
                .Append(days).Append("d ")
                .AppendTwoDigitNumber(hours).Append("h ")
                .AppendTwoDigitNumber(minutes).Append("m ")
                .AppendTwoDigitNumber(seconds).Append("s")
                .Set(this.text);

                break;
            }

            case TimespanTextFormat.SingleLettersHMS:
            {
                BetterStringBuilder.New()
                .Append((days * 24) + hours).Append("h ")
                .AppendTwoDigitNumber(minutes).Append("m ")
                .AppendTwoDigitNumber(seconds).Append("s")
                .Set(this.text);

                break;
            }

            case TimespanTextFormat.SingleLettersMS:
            {
                BetterStringBuilder.New()
                .Append((((days * 24) + hours) * 60) + minutes).Append("m ")
                .AppendTwoDigitNumber(seconds).Append("s")
                .Set(this.text);

                break;
            }

            case TimespanTextFormat.SingleLettersS:
            {
                BetterStringBuilder.New()
                .Append(this.seconds).Append("s")
                .Set(this.text);

                break;
            }

            default:
            {
                Debug.LogErrorFormat("Found Unknown Timespan Format {0}", this.GetFormat());
                break;
            }
            }
        }
 public static void SetLong(string key, long value)
 {
     SetString(key, BetterStringBuilder.New().Append(value).ToString());
 }