Ejemplo n.º 1
0
        public static string GetModifierGUIName(IModifier m)
        {
            CustomModifier attr =
                m.GetType().GetCustomAttributes(typeof(CustomModifier), false).FirstOrDefault() as CustomModifier;

            return(attr.Name);
        }
Ejemplo n.º 2
0
        public static Type GetModifierTargetType(IModifier m)
        {
            CustomModifier attr =
                m.GetType().GetCustomAttributes(typeof(CustomModifier), false).FirstOrDefault() as CustomModifier;

            UnityEngine.Assertions.Assert.IsNotNull(attr);
            return(attr.For);
        }
Ejemplo n.º 3
0
        public static bool HasValidCustomModifierAttribute(Type t)
        {
            CustomModifier attr =
                t.GetCustomAttributes(typeof(CustomModifier), false).FirstOrDefault() as CustomModifier;

            if (attr != null)
            {
                return(!string.IsNullOrEmpty(attr.Name) && attr.For != null);
            }
            return(false);
        }
Ejemplo n.º 4
0
        public static Type GetModifierTargetType(string className)
        {
            var type = Type.GetType(className);

            if (type != null)
            {
                CustomModifier attr = type.GetCustomAttributes(typeof(CustomModifier), false).FirstOrDefault() as CustomModifier;
                if (attr != null)
                {
                    return(attr.For);
                }
            }
            return(null);
        }
Ejemplo n.º 5
0
        public static Dictionary <string, string> GetAttributeAssemblyQualifiedNameMap(Type targetType)
        {
            UnityEngine.Assertions.Assert.IsNotNull(targetType);

            if (s_attributeAssemblyQualifiedNameMap == null)
            {
                s_attributeAssemblyQualifiedNameMap = new Dictionary <Type, Dictionary <string, string> >();
            }

            if (!s_attributeAssemblyQualifiedNameMap.Keys.Contains(targetType))
            {
                var map = new Dictionary <string, string>();

                var allBuilders = new List <Type>();

                foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
                {
                    var builders = assembly.GetTypes()
                                   .Where(t => t != typeof(IModifier))
                                   .Where(t => typeof(IModifier).IsAssignableFrom(t));
                    allBuilders.AddRange(builders);
                }

                foreach (var type in allBuilders)
                {
                    CustomModifier attr =
                        type.GetCustomAttributes(typeof(CustomModifier), false).FirstOrDefault() as CustomModifier;

                    if (attr != null && attr.For == targetType)
                    {
                        if (!map.ContainsKey(attr.Name))
                        {
                            map[attr.Name] = type.AssemblyQualifiedName;
                        }
                        else
                        {
                            LogUtility.Logger.LogWarning(LogUtility.kTag, "Multiple CustomModifier class with the same name/type found. Ignoring " + type.Name);
                        }
                    }
                }
                s_attributeAssemblyQualifiedNameMap[targetType] = map;
            }
            return(s_attributeAssemblyQualifiedNameMap[targetType]);
        }