Beispiel #1
0
        //================================================= Static
        //thanks to Bunny83
        public static Type[] GetAllSubTypes(Type targetType, Type excludeAttributeType)
        {
            var result     = new List <Type>();
            var assemblies = AppDomain.CurrentDomain.GetAssemblies();

            foreach (var assembly in assemblies)
            {
                result.AddRange(from type in assembly.GetTypes()
                                where type.IsClass
                                where !type.IsAbstract
                                where type.IsSubclassOf(targetType)
                                where excludeAttributeType == null || BGReflectionAdapter.GetCustomAttributes(type, excludeAttributeType, true).Length == 0
                                select type);
            }

            return(result.ToArray());
        }
Beispiel #2
0
        //================================================= Static
        //thanks to Bunny83
        public static Type[] GetAllSubTypes(Type targetType, Type excludeAttributeType)
        {
            var result     = new List <Type>();
            var assemblies = AppDomain.CurrentDomain.GetAssemblies();

            foreach (var assembly in assemblies)
            {
                try
                {
                    result.AddRange(from type in assembly.GetTypes()
                                    where type.IsClass
                                    where !type.IsAbstract
                                    where type.IsSubclassOf(targetType)
                                    where excludeAttributeType == null || BGReflectionAdapter.GetCustomAttributes(type, excludeAttributeType, true).Length == 0
                                    select type);
                }
                catch (Exception e)
                {
                    Debug.LogWarning($"{assembly.FullName} threw ReflectionTypeLoadException\r\n{e}");
                }
            }

            return(result.ToArray());
        }
            public void Refresh(BGCc[] components = null, bool force = false)
            {
                if (components == null)
                {
                    components = Curve.GetComponents <BGCc>();
                }

                //it should be enough
                if (count == components.Length && !force)
                {
                    return;
                }

                SetHideFlag(components, customEditorsOn ? HideFlags.HideInInspector : HideFlags.None);

                //Recalc
                var instanceId2Collapsed = new Dictionary <int, bool>();

                //try to preserve expanded/collapsed state
                if (Roots.Count > 0)
                {
                    foreach (var root in Roots)
                    {
                        root.FillState(instanceId2Collapsed);
                    }
                }

                OnDestroy();
                Roots.Clear();
                type2NodeList.Clear();


                if (!customEditorsOn)
                {
                    return;
                }


                try
                {
                    InitException = null;

                    //try to init custom tree view for components
                    count = components.Length;
                    foreach (var cc in components)
                    {
                        if (BGReflectionAdapter.GetCustomAttributes(cc.GetType(), typeof(BGCc.CcExcludeFromMenu), true).Length > 0)
                        {
                            continue;
                        }

                        var node = new CcNode(this, cc);

                        if (instanceId2Collapsed.ContainsKey(cc.GetInstanceID()))
                        {
                            node.Collapsed = true;
                        }

                        var type = cc.GetType();

                        if (!type2NodeList.ContainsKey(type))
                        {
                            type2NodeList[type] = new List <CcNode>();
                        }

                        type2NodeList[type].Add(node);
                    }

                    foreach (var list in type2NodeList.Values)
                    {
                        foreach (var node in list)
                        {
                            if (!node.Processed)
                            {
                                node.ProcessStructure();
                            }
                        }
                    }
                }
                catch (BGCc.CcException e)
                {
                    InitException = e;
                    //fallback (show default stuff)
                    SetHideFlag(components, HideFlags.None);
                }
            }