示例#1
0
        private void BuildExposedTypeList()
        {
            if (exposedTypes != null)
            {
                return;
            }

            try
            {
                ResolverContext resolver = new ResolverContext();

                Assembly[] assemblies = System.AppDomain.CurrentDomain.GetAssemblies();

                HashSet <System.Type> exposedTypeSet = new HashSet <System.Type>();

                for (int i = 0; i < assemblies.Length; ++i)
                {
                    EditorUtility.DisplayProgressBar("Processing methods and types...", $"Assembly {i + 1}/{assemblies.Length} {assemblies[i].GetName().Name}", i / (float)assemblies.Length);

                    Assembly assembly = assemblies[i];

                    if (assembly.FullName.Contains("UdonSharp") ||
                        assembly.FullName.Contains("CodeAnalysis"))
                    {
                        continue;
                    }

                    System.Type[] assemblyTypes = assembly.GetTypes();

                    List <System.Type> types = new List <System.Type>();

                    foreach (System.Type assemblyType in assemblyTypes)
                    {
                        types.Add(assemblyType);
                        types.AddRange(GetNestedTypes(assemblyType));
                    }

                    types = types.Distinct().ToList();

                    foreach (System.Type type in types)
                    {
                        if (type.IsByRef)
                        {
                            continue;
                        }

                        string typeName = resolver.GetUdonTypeName(type);
                        if (resolver.ValidateUdonTypeName(typeName, UdonReferenceType.Type) ||
                            resolver.ValidateUdonTypeName(typeName, UdonReferenceType.Variable) ||
                            UdonEditorManager.Instance.GetTypeFromTypeString(typeName) != null)
                        {
                            exposedTypeSet.Add(type);

                            if (!type.IsGenericType && !type.IsGenericTypeDefinition)
                            {
                                exposedTypeSet.Add(type.MakeArrayType());
                            }
                        }

                        MethodInfo[] methods = type.GetMethods(BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static);

                        foreach (MethodInfo method in methods)
                        {
                            if (resolver.IsValidUdonMethod(resolver.GetUdonMethodName(method, false)))
                            {
                                exposedTypeSet.Add(method.DeclaringType);


                                // We also want to highlight types that can be returned or taken as parameters
                                if (method.ReturnType != null &&
                                    method.ReturnType != typeof(void) &&
                                    method.ReturnType.Name != "T" &&
                                    method.ReturnType.Name != "T[]")
                                {
                                    exposedTypeSet.Add(method.ReturnType);

                                    if (!method.ReturnType.IsArray && !method.ReturnType.IsGenericType && !method.ReturnType.IsGenericTypeDefinition)
                                    {
                                        exposedTypeSet.Add(method.ReturnType.MakeArrayType());
                                    }
                                }

                                foreach (ParameterInfo parameterInfo in method.GetParameters())
                                {
                                    if (!parameterInfo.ParameterType.IsByRef)
                                    {
                                        exposedTypeSet.Add(parameterInfo.ParameterType);

                                        if (!parameterInfo.ParameterType.IsArray)
                                        {
                                            exposedTypeSet.Add(parameterInfo.ParameterType.MakeArrayType());
                                        }
                                    }
                                }
                            }
                        }

                        foreach (PropertyInfo property in type.GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static))
                        {
                            MethodInfo propertyGetter = property.GetGetMethod();
                            if (propertyGetter == null)
                            {
                                continue;
                            }

                            if (resolver.IsValidUdonMethod(resolver.GetUdonMethodName(propertyGetter, false)))
                            {
                                System.Type returnType = propertyGetter.ReturnType;

                                exposedTypeSet.Add(property.DeclaringType);

                                if (returnType != null &&
                                    returnType != typeof(void) &&
                                    returnType.Name != "T" &&
                                    returnType.Name != "T[]")
                                {
                                    exposedTypeSet.Add(returnType);

                                    if (!returnType.IsArray && !returnType.IsGenericType && !returnType.IsGenericTypeDefinition)
                                    {
                                        exposedTypeSet.Add(returnType.MakeArrayType());
                                    }
                                }
                            }
                        }

                        foreach (FieldInfo field in type.GetFields(BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static))
                        {
                            if (resolver.IsValidUdonMethod(resolver.GetUdonFieldAccessorName(field, FieldAccessorType.Get, false)))
                            {
                                System.Type returnType = field.FieldType;

                                exposedTypeSet.Add(field.DeclaringType);

                                if (returnType != null &&
                                    returnType != typeof(void) &&
                                    returnType.Name != "T" &&
                                    returnType.Name != "T[]")
                                {
                                    exposedTypeSet.Add(returnType);

                                    if (!returnType.IsArray && !returnType.IsGenericType && !returnType.IsGenericTypeDefinition)
                                    {
                                        exposedTypeSet.Add(returnType.MakeArrayType());
                                    }
                                }
                            }
                        }
                    }
                }

                exposedTypes = exposedTypeSet.ToList();
            }
            finally
            {
                EditorUtility.ClearProgressBar();
            }

            EditorUtility.ClearProgressBar();
        }
示例#2
0
        private string GetMemberUdonName(TreeViewItem item, ExposureLookupType lookupType = ExposureLookupType.All)
        {
            TypeItemMetadata itemData = itemMetadatas[item];

            MemberInfo member = itemData.member;

            if (member != null)
            {
                if (lookupType == ExposureLookupType.Exposed && !itemData.exposed)
                {
                    return("");
                }
                else if (lookupType == ExposureLookupType.Unexposed && itemData.exposed)
                {
                    return("");
                }

                if (member.MemberType == MemberTypes.Constructor || member.MemberType == MemberTypes.Method)
                {
                    return(resolver.GetUdonMethodName((MethodBase)member, false));
                }
                else if (member.MemberType == MemberTypes.Property)
                {
                    string udonNames = "";

                    if (((PropertyInfo)member).GetGetMethod() != null)
                    {
                        udonNames = resolver.GetUdonMethodName(((PropertyInfo)member).GetGetMethod(), false);
                    }
                    if (((PropertyInfo)member).GetSetMethod() != null)
                    {
                        udonNames += "\n" + resolver.GetUdonMethodName(((PropertyInfo)member).GetSetMethod(), false);
                    }

                    return(udonNames);
                }
                else if (member.MemberType == MemberTypes.Field)
                {
                    return(resolver.GetUdonFieldAccessorName((FieldInfo)member, FieldAccessorType.Get, false) + "\n" + resolver.GetUdonFieldAccessorName((FieldInfo)member, FieldAccessorType.Set, false));
                }
            }
            else
            {
                string childStringData = "";

                if (item.children != null)
                {
                    foreach (TreeViewItem childItem in item.children)
                    {
                        string childString = GetMemberUdonName(childItem, lookupType);

                        if (childString.Length > 0)
                        {
                            childStringData += childString + '\n';
                        }
                    }
                }

                return(childStringData);
            }

            return("");
        }