Ejemplo n.º 1
0
        public TypeMeta Resolve(AssemblyMeta assemblyMeta, TypeReference typeRef)
        {
            if (typeRef.Namespace.EndsWith(this.Name) == false)
            {
                throw new Exception("Mismatch namespace \"" + typeRef.Namespace + "\".");
            }

            for (int i = 0, max = this.Types.Count; i < max; ++i)
            {
                TypeMeta type = this.Types[i];

                if (type.Name == typeRef.Name)
                {
                    if (type.IsPublic == true || assemblyMeta.IsFriend(typeRef.Module.Assembly.Name.Name) == true)
                    {
                        return(type);
                    }
                    break;
                }
            }

            return(null);
        }
        protected virtual void  OnGUI()
        {
            EditorGUILayout.HelpBox("Meta assemblies are libraries (or DLL) converted, compacted & saved to be reused offline.\nAllowing to verify compatibility with a Unity version without installing it.", MessageType.Info);

            if (this.metaLabel == null || this.metaLabel.Length != this.meta.Length)
            {
                this.metaLabel = new string[this.meta.Length];

                for (int i = 0, max = this.metaLabel.Length; i < max; ++i)
                {
                    this.metaLabel[i] = (i + 1) + " - " + Path.GetFileNameWithoutExtension(this.meta[i].AssemblyPath);
                }
            }

            using (LabelWidthRestorer.Get(100F))
            {
                EditorGUI.BeginChangeCheck();
                this.selectedMeta = EditorGUILayout.Popup("Meta Assembly", this.selectedMeta, this.metaLabel);
                if (EditorGUI.EndChangeCheck() == true)
                {
                    this.typesLabel = null;
                }
            }

            if (this.selectedMeta >= 0 && this.selectedMeta < this.meta.Length)
            {
                using (var scroll = new EditorGUILayout.ScrollViewScope(this.scrollPosition))
                {
                    this.scrollPosition = scroll.scrollPosition;

                    AssemblyMeta assemblyMeta = this.meta[this.selectedMeta];

                    using (LabelWidthRestorer.Get(60F))
                    {
                        EditorGUILayout.LabelField("Location", assemblyMeta.AssemblyPath);

                        using (new EditorGUILayout.HorizontalScope(EditorStyles.toolbar))
                        {
                            this.displayFriends = EditorGUILayout.Foldout(this.displayFriends, "Friends (" + assemblyMeta.FriendAssemblies.Length + " assemblies)", true);
                        }
                    }

                    if (this.displayFriends == true)
                    {
                        ++EditorGUI.indentLevel;
                        for (int i = 0, max = assemblyMeta.FriendAssemblies.Length; i < max; ++i)
                        {
                            EditorGUILayout.LabelField(assemblyMeta.FriendAssemblies[i]);
                        }
                        --EditorGUI.indentLevel;
                    }

                    GUILayout.Space(10F);

                    using (new EditorGUILayout.HorizontalScope(EditorStyles.toolbar))
                    {
                        EditorGUILayout.LabelField(this.displayNamespaces == true ? "Namespaces" : "Types (" + assemblyMeta.Types.Length + ")");

                        GUILayout.FlexibleSpace();

                        if (GUILayout.Button(this.displayNamespaces == true ? "Display Type" : "Display Namespace", EditorStyles.toolbarButton) == true)
                        {
                            this.displayNamespaces = !this.displayNamespaces;
                        }
                    }

                    if (this.displayNamespaces == true)
                    {
                        for (int i = 0, max = assemblyMeta.GlobalNamespace.Namespaces.Count; i < max; ++i)
                        {
                            this.DrawNamespace(assemblyMeta.GlobalNamespace.Namespaces[i]);
                        }
                    }
                    else
                    {
                        if (this.typesLabel == null || this.typesLabel.Length != assemblyMeta.Types.Length)
                        {
                            this.typesLabel = new string[assemblyMeta.Types.Length];

                            StringBuilder buffer = Utility.GetBuffer();

                            for (int i = 0, max = assemblyMeta.Types.Length; i < max; ++i)
                            {
                                TypeMeta typeMeta = assemblyMeta.Types[i];

                                buffer.Length = 0;

                                buffer.Append(typeMeta.FullName);
                                //buffer.Append(" (");

                                if (typeMeta.Events.Length > 0)
                                {
                                    buffer.Append(" - ");
                                    buffer.Append(typeMeta.Events.Length);
                                    buffer.Append(" events");
                                }

                                if (typeMeta.Fields.Length > 0)
                                {
                                    buffer.Append(" - ");
                                    buffer.Append(typeMeta.Fields.Length);
                                    buffer.Append(" fields");
                                }

                                if (typeMeta.Properties.Length > 0)
                                {
                                    buffer.Append(" - ");
                                    buffer.Append(typeMeta.Properties.Length);
                                    buffer.Append(" properties");
                                }

                                if (typeMeta.Methods.Length > 0)
                                {
                                    buffer.Append(" - ");
                                    buffer.Append(typeMeta.Methods.Length);
                                    buffer.Append(" methods");
                                }

                                //buffer.Append(')');

                                this.typesLabel[i] = buffer.ToString();
                            }

                            Utility.RestoreBuffer(buffer);
                        }

                        Event eventCurrent = Event.current;

                        if (eventCurrent.type == EventType.MouseMove)
                        {
                            this.Repaint();
                        }

                        for (int i = 0, max = assemblyMeta.Types.Length; i < max; ++i)
                        {
                            EditorGUILayout.LabelField(this.typesLabel[i]);

                            Rect r = GUILayoutUtility.GetLastRect();

                            if (r.Contains(eventCurrent.mousePosition) == true)
                            {
                                r.xMin = r.xMax - 100F;

                                if (GUI.Button(r, "Inspect") == true)
                                {
                                    Utility.OpenWindow <TypeMetaWindow>(true, TypeMetaWindow.Title, true, null, w => w.typeMeta = assemblyMeta.Types[i]);
                                    return;
                                }
                            }
                        }
                    }
                }
            }
        }
        public TypeDatabase(DatabaseMeta database)
        {
            Dictionary <string, Type> types = new Dictionary <string, Type>();

            for (int i = 0, max = database.UnityMeta.Length; i < max; ++i)
            {
                UnityMeta unityMeta = database.UnityMeta[i];

                for (int j = 0, max2 = unityMeta.AssembliesMeta.Length; j < max2; ++j)
                {
                    AssemblyMeta assemblyMeta = unityMeta.AssembliesMeta[j];

                    for (int k = 0, max3 = assemblyMeta.Types.Length; k < max3; ++k)
                    {
                        TypeMeta typeMeta = assemblyMeta.Types[k];
                        Type     type;

                        if (types.TryGetValue(typeMeta.FullName, out type) == false)
                        {
                            type = new Type()
                            {
                                isPublic = typeMeta.IsPublic,
                                name     = typeMeta.FullName,
                                members  = new Member[0],
                                versions = new byte[] { (byte)i }
                            };
                            types.Add(typeMeta.FullName, type);
                        }
                        else
                        {
                            int l    = 0;
                            int max4 = type.versions.Length;

                            for (; l < max4; ++l)
                            {
                                if (type.versions[l] == i)
                                {
                                    break;
                                }
                            }

                            if (l == max4)
                            {
                                Array.Resize(ref type.versions, type.versions.Length + 1);
                                type.versions[type.versions.Length - 1] = (byte)i;
                            }
                        }

                        for (int l = 0, max4 = typeMeta.Events.Length; l < max4; ++l)
                        {
                            type.Aggregate(MemberTypes.Event, typeMeta.Events[l].Name, i);
                        }

                        for (int l = 0, max4 = typeMeta.Properties.Length; l < max4; ++l)
                        {
                            type.Aggregate(MemberTypes.Property, typeMeta.Properties[l].Name, i);
                        }

                        for (int l = 0, max4 = typeMeta.Fields.Length; l < max4; ++l)
                        {
                            type.Aggregate(MemberTypes.Field, typeMeta.Fields[l].Name, i);
                        }

                        for (int l = 0, max4 = typeMeta.Methods.Length; l < max4; ++l)
                        {
                            type.Aggregate(MemberTypes.Method, typeMeta.Methods[l].Name, i);
                        }
                    }
                }
            }

            this.versions = new string[database.UnityMeta.Length];
            for (int i = 0, max = database.UnityMeta.Length; i < max; ++i)
            {
                this.versions[i] = database.UnityMeta[i].Version;
            }

            this.types = new List <Type>(types.Values).ToArray();
        }
Ejemplo n.º 4
0
 public int      RegisterAssembly(AssemblyMeta meta)
 {
     return(this.assemblyTable.Register(meta));
 }