using System.Collections; using System.Collections.Generic; using System.ComponentModel; using System.Linq; using System.Reflection; using UnityEngine; namespace Beyond { public static class bInventoryDisplayFormat { private static readonly List ItemTypeFormats = new List(); private static readonly List ItemAttributeFormats = new List(); /// /// Get Item type string format using Description in value /// /// target Item type /// public static string DisplayFormat(this bItemType value) { if (ItemTypeFormats.Count == 0) { var values = System.Enum.GetValues(typeof(bItemType)).OfType().ToArray(); for (int i = 0; i < values.Length; i++) { bItemType v = values[i]; ItemTypeFormats.Add(GetDisplayFormat(v)); } } return ItemTypeFormats[(int)value]; } /// /// Get Item Attribute string format using Description in value /// /// target Item Attribute /// public static string DisplayFormat(this bItemAttributes value) { if (ItemAttributeFormats.Count == 0) { var values = System.Enum.GetValues(typeof(bItemAttributes)).OfType().ToArray(); for (int i = 0; i < values.Length; i++) { bItemAttributes v = values[i]; ItemAttributeFormats.Add(GetDisplayFormat(v)); } } return ItemAttributeFormats[(int)value]; } private static string GetDisplayFormat(this T value) where T : System.Enum { return value .GetType() .GetMember(value.ToString()) .FirstOrDefault() ?.GetCustomAttribute() ?.Description ?? value.ToString(); } } }