Ejemplo n.º 1
0
        /// <summary>
        /// Find command pin menu.
        /// </summary>
        /// <returns></returns>
        public static List <ControlFieldAttribute> FindControlsField()
        {
            if (_controlsField == null)
            {
                _controlsField = new List <ControlFieldAttribute>();

                foreach (System.Reflection.Assembly assembly in EditorReflectionUtility.GetAssemblies())
                {
                    foreach (System.Type type in EditorReflectionUtility.GetAssemblyTypes(assembly))
                    {
                        var atts = type.GetCustomAttributes(typeof(ControlFieldAttribute), true);
                        if (atts.Length > 0)
                        {
                            foreach (var a in atts)
                            {
                                var control = a as ControlFieldAttribute;
                                control.classType = type;
                                _controlsField.Add(control);
                            }
                        }
                    }
                }
                _controlsField.Sort((x, y) => Comparer <int> .Default.Compare(x.order, y.order));
            }
            return(_controlsField);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Get the actual node view type.
        /// </summary>
        /// <param name="nodeType"></param>
        /// <returns></returns>
        public static Type GetNodeViewTypeFromType(Type nodeType)
        {
            if (nodeViewPerType == null)
            {
                nodeViewPerType = new Dictionary <Type, Type>();
                foreach (var asm in EditorReflectionUtility.GetAssemblies())
                {
                    foreach (var type in EditorReflectionUtility.GetAssemblyTypes(asm))
                    {
                        if (type.IsClass && !type.IsAbstract)
                        {
                            if (type.IsSubclassOf(typeof(UNodeView)))
                            {
                                if (type.GetCustomAttributes(typeof(NodeCustomEditor), true) is NodeCustomEditor[] attrs && attrs.Length > 0)
                                {
                                    for (int i = 0; i < attrs.Length; i++)
                                    {
                                        Type nType = attrs[i].nodeType;
                                        nodeViewPerType[nType] = type;
                                    }
                                }
                            }
                        }
                    }
                }
            }
            Type oriType = nodeType;
            Type view    = null;

            while (nodeType != typeof(UNodeView) && nodeType != typeof(object) && nodeType != typeof(BaseNodeView))
            {
                if (nodeViewPerType.TryGetValue(nodeType, out view))
                {
                    if (oriType != nodeType)
                    {
                        nodeViewPerType[oriType] = view;
                    }
                    return(view);
                }
                else
                {
                    nodeType = nodeType.BaseType;
                }
            }
            return(view);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Find all available graph converters
 /// </summary>
 /// <returns></returns>
 public static List <GraphConverter> FindGraphConverters()
 {
     if (_graphConverters == null)
     {
         _graphConverters = new List <GraphConverter>();
         foreach (var assembly in EditorReflectionUtility.GetAssemblies())
         {
             try {
                 foreach (System.Type type in EditorReflectionUtility.GetAssemblyTypes(assembly))
                 {
                     if (!type.IsAbstract && type.IsSubclassOf(typeof(GraphConverter)))
                     {
                         var converter = System.Activator.CreateInstance(type, true);
                         _graphConverters.Add(converter as GraphConverter);
                     }
                 }
             }
             catch { continue; }
         }
         _graphConverters.Sort((x, y) => Comparer <int> .Default.Compare(x.order, y.order));
     }
     return(_graphConverters);
 }
Ejemplo n.º 4
0
 public static List <FieldDecorator> FindDecorators()
 {
     if (_fieldDecorators == null)
     {
         _fieldDecorators = new List <FieldDecorator>();
         foreach (var assembly in EditorReflectionUtility.GetAssemblies())
         {
             try {
                 foreach (System.Type type in EditorReflectionUtility.GetAssemblyTypes(assembly))
                 {
                     if (type.IsSubclassOf(typeof(FieldDecorator)) && ReflectionUtils.CanCreateInstance(type))
                     {
                         var control = ReflectionUtils.CreateInstance(type) as FieldDecorator;
                         _fieldDecorators.Add(control);
                     }
                 }
             }
             catch { continue; }
         }
         _fieldDecorators.Sort((x, y) => CompareUtility.Compare(x.order, y.order));
     }
     return(_fieldDecorators);
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Find all graph system attributes.
 /// </summary>
 /// <returns></returns>
 public static List <GraphSystemAttribute> FindGraphSystemAttributes()
 {
     if (_graphSystems == null)
     {
         _graphSystems = new List <GraphSystemAttribute>();
         foreach (var assembly in EditorReflectionUtility.GetAssemblies())
         {
             try {
                 foreach (System.Type type in EditorReflectionUtility.GetAssemblyTypes(assembly))
                 {
                     if (type.IsDefined(typeof(GraphSystemAttribute), false))
                     {
                         var menuItem = (GraphSystemAttribute)type.GetCustomAttributes(typeof(GraphSystemAttribute), false)[0];
                         menuItem.type = type;
                         _graphSystems.Add(menuItem);
                     }
                 }
             }
             catch { continue; }
         }
         _graphSystems.Sort((x, y) => CompareUtility.Compare(x.menu, x.order, y.menu, y.order));
     }
     return(_graphSystems);
 }
Ejemplo n.º 6
0
        public void Init()
        {
            //int typeCount = 0;
            Dictionary <string, List <Type> > typeMaps = new Dictionary <string, List <Type> >();
            var namespaces    = uNodePreference.GetBrowserNamespaceList();
            var excludedNS    = uNodePreference.GetExcludedNamespace();
            var excludedTypes = uNodePreference.GetExcludedTypes();

            foreach (var assembly in EditorReflectionUtility.GetAssemblies())
            {
                string assemblyName = assembly.GetName().Name;
                foreach (var type in EditorReflectionUtility.GetAssemblyTypes(assembly))
                {
                    if (type.IsNotPublic ||
                        !type.IsVisible ||
                        type.IsEnum ||
                        type.IsInterface ||
                        type.IsCOMObject ||
                        type.IsAutoClass ||
                        type.IsGenericType ||
                        type.Name.StartsWith("<") ||
                        type.IsCastableTo(typeof(Delegate)) ||
                        type.IsDefined(typeof(ObsoleteAttribute), true) ||
                        excludedTypes.Contains(type.FullName))
                    {
                        continue;
                    }
                    string ns = type.Namespace;
                    //if(ns.StartsWith("Unity.") || ns.Contains("Experimental") || ns.Contains("Internal")) {
                    //	continue;
                    //}
                    if (string.IsNullOrEmpty(ns))
                    {
                        ns = "global";
                    }
                    else if (!namespaces.Contains(ns))
                    {
                        continue;
                    }
                    if (excludedNS.Contains(ns))
                    {
                        continue;
                    }
                    List <Type> types;
                    if (!typeMaps.TryGetValue(ns, out types))
                    {
                        types        = new List <Type>();
                        typeMaps[ns] = types;
                    }
                    types.Add(type);
                    //typeCount++;
                }
            }
            //this.typeCount = typeCount;
            typeList = typeMaps.ToList();
            foreach (var list in typeList)
            {
                list.Value.Sort((x, y) => string.Compare(x.Name, y.Name));
            }
            typeList.Sort((x, y) => {
                if (x.Key == "global")
                {
                    if (y.Key == "global")
                    {
                        return(0);
                    }
                    return(-1);
                }
                else if (y.Key == "global")
                {
                    return(1);
                }
                if (x.Key.StartsWith("Unity"))
                {
                    if (y.Key.StartsWith("Unity"))
                    {
                        return(string.Compare(x.Key, y.Key));
                    }
                    return(-1);
                }
                else if (y.Key.StartsWith("Unity"))
                {
                    return(1);
                }
                return(string.Compare(x.Key, y.Key));
            });
        }