65 lines
2.2 KiB
C#
65 lines
2.2 KiB
C#
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<string> ItemTypeFormats = new List<string>();
|
|
private static readonly List<string> ItemAttributeFormats = new List<string>();
|
|
|
|
/// <summary>
|
|
/// Get Item type string format using Description in <seealso cref="bItemType"/> value
|
|
/// </summary>
|
|
/// <param name="value">target Item type</param>
|
|
/// <returns></returns>
|
|
public static string DisplayFormat(this bItemType value)
|
|
{
|
|
if (ItemTypeFormats.Count == 0)
|
|
{
|
|
var values = System.Enum.GetValues(typeof(bItemType)).OfType<bItemType>().ToArray();
|
|
for (int i = 0; i < values.Length; i++)
|
|
{
|
|
bItemType v = values[i];
|
|
ItemTypeFormats.Add(GetDisplayFormat(v));
|
|
}
|
|
}
|
|
return ItemTypeFormats[(int)value];
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get Item Attribute string format using Description in <seealso cref="bItemAttributes"/> value
|
|
/// </summary>
|
|
/// <param name="value">target Item Attribute</param>
|
|
/// <returns></returns>
|
|
public static string DisplayFormat(this bItemAttributes value)
|
|
{
|
|
if (ItemAttributeFormats.Count == 0)
|
|
{
|
|
var values = System.Enum.GetValues(typeof(bItemAttributes)).OfType<bItemAttributes>().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<T>(this T value) where T : System.Enum
|
|
{
|
|
return
|
|
value
|
|
.GetType()
|
|
.GetMember(value.ToString())
|
|
.FirstOrDefault()
|
|
?.GetCustomAttribute<DescriptionAttribute>()
|
|
?.Description
|
|
?? value.ToString();
|
|
}
|
|
}
|
|
} |