/// <summary> /// Used by designer /// </summary> /// <param name="componentType"></param> public static List <Type> GetSkinClasses(Type componentType) { List <Type> list = new List <Type>(); //Debug.Log("componentType: " + componentType); if (!componentType.IsSubclassOf(typeof(SkinnableComponent))) { //Debug.LogError("Component is not a subclass of SkinnableComponent: " + componentType); return(list); } List <Type> types = GuiReflector.GetAllLoadedTypes(); foreach (Type type in types) { if (!type.IsClass) { continue; } if (!type.IsSubclassOf(typeof(Skin))) { continue; } var componentTypeSpecifiedInAttribute = SkinUtil.GetHostComponent(type); if (componentTypeSpecifiedInAttribute == componentType) { list.Add(type); } } return(list); }
public static Type GetTypeByClassName(string className) { var types = GuiReflector.GetAllLoadedTypes(); return(types.Find(delegate(Type t) { return /*t.Namespace == nameSpace && */ t.Name == className; })); }
//private static List<Type> _allTypes; //public static List<Type> GetAllLoadedTypes() //{ // /** // * 1. Get all types for all loaded assemblies // * This is done only when componet tab expanded, so is no performance issue // * */ // if (null == _allTypes) // { // _allTypes = new List<Type>(); // Assembly[] loadedAssemblies = AppDomain.CurrentDomain.GetAssemblies(); // foreach (Assembly assembly in loadedAssemblies) // { // _allTypes.AddRange(assembly.GetTypes()); // } // } // return _allTypes; //} public static bool IsUniqueScriptName(string className) { var types = GuiReflector.GetAllLoadedTypes(); //Debug.Log(string.Format(@"nameToTest: {0}", className)); //Debug.Log(string.Format(@"types: {0}", types.Count)); bool found = types.Exists(delegate(Type t) { return /*t.Namespace == nameSpace && */ (t.Name == className); }); return(!found); }
internal void RefreshComponentList() { _showComponents = EditorSettings.ReferenceShowComponents; _showSkinnableComponents = EditorSettings.ReferenceShowSkinnableComponents; _showSkins = EditorSettings.ReferenceShowSkins; _selectedIndex = -1; _selectionChanged = false; _classes.Clear(); var allClasses = GuiReflector.GetAllLoadedTypes(); foreach (var type in allClasses) { if (typeof(Component).IsAssignableFrom(type)) { if (!string.IsNullOrEmpty(_searchText) && !PassesSearchFilter(type.FullName, _searchText)) { /*!type.FullName.ToUpper().Contains(_searchText.ToUpper())*/ continue; } _classes.Add(type); } } _classes.Sort(TypeSort); //Debug.Log("_classes: " + _classes.Count); List <GUIContent> contentList = new List <GUIContent>(); foreach (var @class in _classes) { var isSkinnableComponent = typeof(SkinnableComponent).IsAssignableFrom(@class); var isSkin = typeof(Skin).IsAssignableFrom(@class); var isSimpleComponent = !isSkinnableComponent && !isSkin; var texture = GuiComponentEvaluator.EvaluateComponentRowIcon(@class); if (_showComponents && isSimpleComponent || _showSkinnableComponents && isSkinnableComponent || _showSkins && isSkin) { contentList.Add(new GUIContent(" " + @class.FullName, texture)); } } _contents = contentList.ToArray(); //Debug.Log("_contents: " + _contents.Length); }
public static Type GetTypeByFullName(string name) { if (null == _allTypesDict) { _allTypesDict = new Dictionary <string, Type>(); //Type myType = Type.GetType(name); var allTypes = GuiReflector.GetAllLoadedTypes(); foreach (Type type in allTypes) { _allTypesDict[type.FullName] = type; } } if (_allTypesDict.ContainsKey(name)) { return(_allTypesDict[name]); } return(null); }
/// <summary> /// Looks for all descriptor classes in running assemblies via reflection /// </summary> public static void Initialize() { //Debug.Log("Initialize"); var toolbox = Toolbox.Instance; toolbox.Clear(); /** * 1. Get all types for all loaded assemblies * This is done only when componet tab expanded, so is no performance issue * */ List <Type> types = GuiReflector.GetAllLoadedTypes(); foreach (Type type in types) { if (type.IsClass) { if (type.IsSubclassOf(typeof(ComponentAdapter))) { string icon = string.Empty; string label = string.Empty; string groupName = string.Empty; string tooltip = string.Empty; //ToolboxAttribute[] toolboxAttributes = (ToolboxAttribute[])type.GetCustomAttributes(typeof(ToolboxAttribute), true); var toolboxAttributes = Core.Reflection.CoreReflector.GetClassAttributes <ToolboxAttribute>(type); if (toolboxAttributes.Count > 0) { var attr = toolboxAttributes[0]; label = attr.Label; icon = attr.Icon; tooltip = attr.Tooltip; groupName = attr.Group; } Texture iconTexture = null; if (!string.IsNullOrEmpty(icon)) { iconTexture = (Texture)Resources.Load(icon); } if (string.IsNullOrEmpty(label)) { label = type.Name.Replace("Adapter", string.Empty); } var desc = new ComponentTypeDesc(label, type, iconTexture, tooltip); if (type.IsAbstract) { continue; // skip abstract classes (SkinnableComponentAdapter etc.) } /** * 1. Stage * */ if (type == typeof(StageAdapter)) { Toolbox.Instance.StageContent = desc.GetContent(); continue; } /** * 2. Named group * */ if (!string.IsNullOrEmpty(groupName)) { desc.Group = groupName; toolbox.Add(desc); continue; } /** * 3. Group * */ //if (type == typeof (GroupAdapter) || type.IsSubclassOf(typeof (GroupAdapter))) if (typeof(GroupAdapter).IsAssignableFrom(type)) { desc.Group = "Containers"; toolbox.Add(desc); continue; } /** * 4. Component * */ desc.Group = "Components"; toolbox.Add(desc); } } } toolbox.Process(); }