CreatDamageMode(DamageMode modo)
 {
     if (!cache.ContainsKey(modo.ToString()))
     //命名空间
     {
         string classNameSpace = typeof(SelectorFactory).Namespace;
         //类名
         string attackTypeName = string.Format("{0}AttackMode", modo.ToString());
         //反射需要的命名空+类名
         attackTypeName = classNameSpace + "." + attackTypeName;
         //通过反射获取类型
         cache.Add(modo.ToString(), Activator.CreateInstance(Type.GetType(attackTypeName)) as ISelectAttackMode);
     }
     return(cache[modo.ToString()]);
 }
Esempio n. 2
0
    public static IAttackSelector CreateSelector(DamageMode mode)
    {
        //没有缓存则创建
        if (!cache.ContainsKey(mode.ToString()))
        {
            var    nameSpace     = typeof(SelectorFactory).Namespace;
            string classFullName = string.Format("{0}AttackSelector", mode.ToString());

            if (!String.IsNullOrEmpty(nameSpace))
            {
                classFullName = nameSpace + "." + classFullName;
            }

            Type type = Type.GetType(classFullName);
            cache.Add(mode.ToString(), Activator.CreateInstance(type) as IAttackSelector);
        }
        //从缓存中取得创建好的选择器对象
        return(cache[mode.ToString()]);
    }