104 lines
3.2 KiB
C#
104 lines
3.2 KiB
C#
|
|
using System.Collections;
|
|||
|
|
using System.Collections.Generic;
|
|||
|
|
using System.ComponentModel;
|
|||
|
|
#if !UNITY_WEBGL
|
|||
|
|
using System.Reflection;
|
|||
|
|
#endif
|
|||
|
|
using UnityEngine;
|
|||
|
|
/********************************************************************************
|
|||
|
|
*Create By CG
|
|||
|
|
*Function 枚举控制
|
|||
|
|
*********************************************************************************/
|
|||
|
|
namespace CG.UTility
|
|||
|
|
{
|
|||
|
|
public class EnumCtrl
|
|||
|
|
{
|
|||
|
|
//public enum ModelType
|
|||
|
|
//{
|
|||
|
|
// /// <summary>
|
|||
|
|
// /// 缺省值
|
|||
|
|
// /// </summary>
|
|||
|
|
// [Description("默认状态")]
|
|||
|
|
// None,
|
|||
|
|
// /// <summary>
|
|||
|
|
// /// 牛的同期发情处理
|
|||
|
|
// /// </summary>
|
|||
|
|
// [Description("牛的同期发情处理")]
|
|||
|
|
// TQFAQCL,
|
|||
|
|
// /// <summary>
|
|||
|
|
// /// 牛的超数排卵处理
|
|||
|
|
// /// </summary>
|
|||
|
|
// [Description("牛的超数排卵处理")]
|
|||
|
|
// CSPLCL,
|
|||
|
|
// /// <summary>
|
|||
|
|
// /// 精子活率检查
|
|||
|
|
// /// </summary>
|
|||
|
|
// [Description("精子活率检查")]
|
|||
|
|
// JZLVJC,
|
|||
|
|
// /// <summary>
|
|||
|
|
// /// 牛的人工授精
|
|||
|
|
// /// </summary>
|
|||
|
|
// [Description("牛的人工授精")]
|
|||
|
|
// RGSJ,
|
|||
|
|
// /// <summary>
|
|||
|
|
// /// 牛的冲胚
|
|||
|
|
// /// </summary>
|
|||
|
|
// [Description("牛的冲胚")]
|
|||
|
|
// CP,
|
|||
|
|
// /// <summary>
|
|||
|
|
// /// 胚胎选择
|
|||
|
|
// /// </summary>
|
|||
|
|
// [Description("胚胎选择")]
|
|||
|
|
// PTXZ,
|
|||
|
|
// /// <summary>
|
|||
|
|
// /// 胚胎移植
|
|||
|
|
// /// </summary>
|
|||
|
|
// [Description("胚胎移植")]
|
|||
|
|
// PTYZ,
|
|||
|
|
// /// <summary>
|
|||
|
|
// /// 妊娠诊断
|
|||
|
|
// /// </summary>
|
|||
|
|
// [Description("妊娠诊断")]
|
|||
|
|
// YYZD
|
|||
|
|
//}
|
|||
|
|
public static string GetEnumDescription(System.Enum enumValue)
|
|||
|
|
{
|
|||
|
|
#if UNITY_WEBGL
|
|||
|
|
return null;
|
|||
|
|
#else
|
|||
|
|
string value = enumValue.ToString();
|
|||
|
|
FieldInfo field = enumValue.GetType().GetField(value);
|
|||
|
|
object[] objs = field.GetCustomAttributes(typeof(DescriptionAttribute), false);
|
|||
|
|
if (objs == null || objs.Length == 0)
|
|||
|
|
{
|
|||
|
|
return value;
|
|||
|
|
}
|
|||
|
|
DescriptionAttribute descriptionAttribute = (DescriptionAttribute)objs[0];
|
|||
|
|
return descriptionAttribute.Description;
|
|||
|
|
#endif
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
public static T GetEnumByDescription<T>(string description) where T : struct
|
|||
|
|
{
|
|||
|
|
#if UNITY_WEBGL
|
|||
|
|
|
|||
|
|
return default(T);
|
|||
|
|
#else
|
|||
|
|
System.Type type = typeof(T);
|
|||
|
|
FieldInfo[] fields = type.GetFields(BindingFlags.Public | BindingFlags.Static | BindingFlags.DeclaredOnly);
|
|||
|
|
|
|||
|
|
foreach (FieldInfo field in fields)
|
|||
|
|
{
|
|||
|
|
object[] attributes = field.GetCustomAttributes(typeof(DescriptionAttribute), false);
|
|||
|
|
if (attributes.Length > 0 && ((DescriptionAttribute)attributes[0]).Description == description)
|
|||
|
|
{
|
|||
|
|
return (T)field.GetValue(null);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
return default(T);
|
|||
|
|
#endif
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|