Exemplo n.º 1
0
        ///----------------------------------------------------------------------------------------------

        //Find nodes of type (T) having the [DropReferenceType] attribute pointing to target unity object type
        public static IEnumerable <System.Type> GetDropedReferenceNodeTypes <T>(UnityEngine.Object obj) where T : IGraphElement
        {
            var targetType = obj.GetType();

            foreach (var type in ReflectionTools.GetImplementationsOf(typeof(T)))
            {
                var att = type.RTGetAttribute <DropReferenceType>(true);
                if (att != null && att.type == targetType)
                {
                    yield return(type);
                }
            }
        }
        ///Returns whether there is a CustomObjectWrapper implemented for target type
        public static System.Type[] FindCustomObjectWrappersForType(System.Type targetType)
        {
            var results = new List <System.Type>();

            foreach (var type in ReflectionTools.GetImplementationsOf(typeof(CustomObjectWrapper)))
            {
                var args = type.BaseType.GetGenericArguments();
                if (args.Length == 1 && args[0] == targetType)
                {
                    results.Add(type);
                }
            }
            return(results.ToArray());
        }
Exemplo n.º 3
0
        ///Return an object drawer instance of target inspected type
        public static IObjectDrawer GetObjectDrawer(Type objectType)
        {
            IObjectDrawer result = null;

            if (objectDrawers.TryGetValue(objectType, out result))
            {
                return(result);
            }

            // look for specific drawer first
            Type fallbackDrawerType = null;

            foreach (var drawerType in ReflectionTools.GetImplementationsOf(typeof(IObjectDrawer)))
            {
                if (drawerType != typeof(DefaultObjectDrawer))
                {
                    var args = drawerType.BaseType.RTGetGenericArguments();
                    if (args.Length == 1)
                    {
                        if (args[0].IsEquivalentTo(objectType))
                        {
                            return(objectDrawers[objectType] = Activator.CreateInstance(drawerType) as IObjectDrawer);
                        }
                        if (args[0].IsAssignableFrom(objectType))
                        {
                            fallbackDrawerType = drawerType;
                        }
                    }
                }
            }

            if (fallbackDrawerType != null)
            {
                return(objectDrawers[objectType] = Activator.CreateInstance(fallbackDrawerType) as IObjectDrawer);
            }


            // foreach ( var drawerType in ReflectionTools.GetImplementationsOf(typeof(IObjectDrawer)) ) {
            //     if ( drawerType != typeof(DefaultObjectDrawer) ) {
            //         var args = drawerType.BaseType.RTGetGenericArguments();
            //         if ( args.Length == 1 && args[0].IsAssignableFrom(objectType) ) {
            //             return objectDrawers[objectType] = Activator.CreateInstance(drawerType) as IObjectDrawer;
            //         }
            //     }
            // }

            return(objectDrawers[objectType] = new DefaultObjectDrawer(objectType));
        }
Exemplo n.º 4
0
        public static Type GetExtractorType(Type type)
        {
            if (_extractors == null)
            {
                _extractors = new Dictionary <Type, Type>();
                var extractorTypes = ReflectionTools.GetImplementationsOf(typeof(ExtractorNode)).Where(t => !t.IsGenericTypeDefinition);
                foreach (var extractorType in extractorTypes)
                {
                    var invokeMethod = extractorType.RTGetMethod("Invoke");
                    var targetType   = invokeMethod.GetParameters()[0].ParameterType;
                    _extractors[targetType] = extractorType;
                }
            }
            Type result = null;

            _extractors.TryGetValue(type, out result);
            return(result);
        }
Exemplo n.º 5
0
        ///Return an attribute drawer instance of target attribute type
        public static IAttributeDrawer GetAttributeDrawer(Type attributeType)
        {
            IAttributeDrawer result = null;

            if (attributeDrawers.TryGetValue(attributeType, out result))
            {
                return(result);
            }

            foreach (var drawerType in ReflectionTools.GetImplementationsOf(typeof(IAttributeDrawer)))
            {
                if (drawerType != typeof(DefaultAttributeDrawer))
                {
                    var args = drawerType.BaseType.GetGenericArguments();
                    if (args.Length == 1 && args[0].IsAssignableFrom(attributeType))
                    {
                        return(attributeDrawers[attributeType] = Activator.CreateInstance(drawerType) as IAttributeDrawer);
                    }
                }
            }

            return(attributeDrawers[attributeType] = new DefaultAttributeDrawer(attributeType));
        }
        public static List <ScriptInfo> GetScriptInfosOfType(Type baseType)
        {
            if (cachedInfos == null)
            {
                cachedInfos = new Dictionary <Type, List <ScriptInfo> >();
            }

            List <ScriptInfo> infosResult;

            if (cachedInfos.TryGetValue(baseType, out infosResult))
            {
                return(infosResult.ToList());
            }

            infosResult = new List <ScriptInfo>();

            var subTypes = ReflectionTools.GetImplementationsOf(baseType);

            if (baseType.IsGenericTypeDefinition)
            {
                subTypes = new Type[] { baseType };
            }

            foreach (var subType in subTypes)
            {
                if (subType.IsAbstract || subType.IsDefined(typeof(DoNotListAttribute), true) || subType.IsDefined(typeof(ObsoleteAttribute), true))
                {
                    continue;
                }

                var isGeneric      = subType.IsGenericTypeDefinition && subType.GetGenericArguments().Length == 1;
                var scriptName     = subType.FriendlyName().SplitCamelCase();
                var scriptCategory = string.Empty;
                var scriptPriority = 0;

                var nameAttribute = subType.RTGetAttribute <NameAttribute>(true);
                if (nameAttribute != null)
                {
                    scriptPriority = nameAttribute.priority;
                    scriptName     = nameAttribute.name;
                    if (isGeneric && !scriptName.EndsWith("<T>"))
                    {
                        scriptName += " (T)";
                    }
                }

                var categoryAttribute = subType.RTGetAttribute <CategoryAttribute>(true);
                if (categoryAttribute != null)
                {
                    scriptCategory = categoryAttribute.category;
                }

                var info = new ScriptInfo(subType, scriptName, scriptCategory, scriptPriority);
                info.originalType     = subType;
                info.originalName     = scriptName;
                info.originalCategory = scriptCategory;

                //add the generic types based on constrains and prefered types list
                if (isGeneric)
                {
                    var exposeAsBaseDefinition = subType.RTIsDefined <ExposeAsDefinitionAttribute>(true);
                    if (!exposeAsBaseDefinition)
                    {
                        var typesToWrap = TypePrefs.GetPreferedTypesList(true);
                        foreach (var t in typesToWrap)
                        {
                            infosResult.Add(info.MakeGenericInfo(t, string.Format("/{0}/{1}", info.name, t.NamespaceToPath())));
                            infosResult.Add(info.MakeGenericInfo(typeof(List <>).MakeGenericType(t), string.Format("/{0}/{1}{2}", info.name, TypePrefs.LIST_MENU_STRING, t.NamespaceToPath()), -1));
                            infosResult.Add(info.MakeGenericInfo(typeof(Dictionary <,>).MakeGenericType(typeof(string), t), string.Format("/{0}/{1}{2}", info.name, TypePrefs.DICT_MENU_STRING, t.NamespaceToPath()), -2));
                        }
                        continue;
                    }
                }

                infosResult.Add(info);
            }

            infosResult = infosResult
                          .Where(s => s != null)
                          .OrderBy(s => s.GetBaseInfo().name)
                          .OrderBy(s => s.GetBaseInfo().priority * -1)
                          .OrderBy(s => s.GetBaseInfo().category)
                          .ToList();
            cachedInfos[baseType] = infosResult;
            return(infosResult);
        }
Exemplo n.º 7
0
 static fsSerializer()
 {
     _directConverterTypes = ReflectionTools.GetImplementationsOf(typeof(fsDirectConverter));
 }