miepzerino
2025-04-01 6db269b9430900667b240bada58f8436ef3442af
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
using Assets.Scripts.Enums;
using System;
using System.Reflection;
using TMPro;
using UnityEngine;
 
namespace Assets.Scripts.Helpers
{
    internal static class TextMeshProHelper
    {
 
        /// <summary>
        /// Will get the string value for a given enums value, this will
        /// only work if you assign the StringValue attribute to
        /// the items in your enum.
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public static void UpdateItemMaxCountText(TextMeshProUGUI inventoryText, int itemCount, int maxCount)
        {
            float fillPercentage = (float)itemCount / maxCount * 100;
 
            // Set color based on fill percentage
            if (fillPercentage >= 100)
            {
                inventoryText.color = Color.red;
            }
            else if (fillPercentage >= 50)
            {
                inventoryText.color = Color.yellow;
            }
            else
            {
                inventoryText.color = Color.green;
            }
 
            inventoryText.text = $"{itemCount} ({maxCount})";
        }
    }
}