using System; using System.Reflection; using System.Collections.Generic; namespace UnityEngine.UI{ /// /// Helps with getting ModifierID Attributes etc. /// public static class ModifierUtility { /// /// Gets the instance with identifier specified in a ModifierID Attribute. /// /// The instance with identifier. /// Identifier. public static ProceduralImageModifier GetInstanceWithId(string id){ return (ProceduralImageModifier)Activator.CreateInstance(GetTypeWithId(id)); } /// /// Gets the type with specified in a ModifierID Attribute. /// /// The type with identifier. /// Identifier. public static Type GetTypeWithId(string id){ foreach(Type type in Assembly.GetAssembly(typeof(ProceduralImageModifier)).GetTypes()) { if (type.IsSubclassOf(typeof(ProceduralImageModifier))){ if(((ModifierID[])type.GetCustomAttributes(typeof(ModifierID),false))[0].Name == id){ return type; } } } return null; } /// /// Gets a list of Attributes of type ModifierID. /// /// The attribute list. public static List GetAttributeList(){ List l = new List (); foreach(Type type in Assembly.GetAssembly(typeof(ProceduralImageModifier)).GetTypes()) { if (type.IsSubclassOf(typeof(ProceduralImageModifier))){ l.Add (((ModifierID[])type.GetCustomAttributes(typeof(ModifierID),false))[0]); } } return l; } } }