Ejemplo n.º 1
0
        /// <summary>
        /// 获取指定类型的所有字段值以及描述
        /// </summary>
        /// <param name="enumType"></param>
        /// <returns></returns>
        public static Dictionary <string, string> GetList(Type type)
        {
            if (CACHE_TYPE.ContainsKey(type))
            {
                return(CACHE_TYPE[type]);
            }
            else
            {
                var entity_desc = new Dictionary <string, string>();
                var entity_att  = type.GetCustomAttribute(typeof(DescriptionAttribute), false) as DescriptionAttribute;
                if (entity_att != null)
                {
                    entity_desc.Add(Entity_Name_Key, entity_att.Description);
                }

                var propertyInfos = type.GetProperties();
                foreach (var pf in propertyInfos)
                {
                    var att = pf.GetCustomAttribute(typeof(DescriptionAttribute), false) as DescriptionAttribute;
                    if (att != null)
                    {
                        entity_desc.Add(pf.Name, att.Description);
                    }
                }
                CACHE_TYPE[type] = entity_desc;
                return(entity_desc);
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// 获取指定枚举的所有字段值以及描述
 /// </summary>
 /// <param name="enumType"></param>
 /// <returns></returns>
 public static Dictionary <ValueType, string> GetList(Type type)
 {
     if (CACHE_TYPE.ContainsKey(type))
     {
         return(CACHE_TYPE[type]);
     }
     else
     {
         var ret       = new Dictionary <ValueType, string>();
         var fieldInfo = type.GetFields();
         foreach (var field in fieldInfo)
         {
             var atts = field.GetCustomAttributes(typeof(DescriptionAttribute), false);
             foreach (DescriptionAttribute att in atts)
             {
                 var value = field.GetValue(type) as ValueType;
                 if (ret.ContainsKey(value))
                 {
                     Log4netHelper.Fatal(string.Format("类型{0}拥有相同的Value{1}", type.FullName, value));
                 }
                 else
                 {
                     ret.Add(value, att.Description);
                 }
                 break;
             }
         }
         CACHE_TYPE[type] = ret;
         return(ret);
     }
 }
Ejemplo n.º 3
0
    private static void RLoadPlayAudioOneShot(string soundName, AudioSource audioSource, float volume = 1f, float gvolume = 1f)
    {
        AudioClip resource;

        ResourceMgr.Load(soundName, _object =>
        {
            resource = _object as AudioClip;
            if (resource != null)
            {
                if (!CachePool.ContainsKey(soundName))
                {
                    CachePool.Add(soundName, resource);
                }

                if (audioSource != null)
                {
                    PlayAudioOneShot(audioSource, resource, volume, gvolume);
                }
            }
            else
            {
                Debug.LogError(string.Format("The AudioClip[resource={0}] is null.", resource));
            }
        });
    }
Ejemplo n.º 4
0
    private static void RLoadPlayAudio(string soundName, AudioSource audioSource, float volume, bool loop, Action playCallBack)
    {
        AudioClip resource;

        ResourceMgr.Load(soundName, _object =>
        {
            resource = _object as AudioClip;
            if (resource)
            {
                if (!CachePool.ContainsKey(soundName))
                {
                    CachePool.Add(soundName, resource);
                }

                DoPlayAudio(audioSource, resource, volume, loop, playCallBack);
            }
            else
            {
                Debug.LogError("加载声音失败:" + soundName);
            }
        });
    }