Ejemplo n.º 1
0
        private void ShowAssemblies()
        {
            EditorGUILayout.BeginHorizontal();
            Block("Assemblies", () =>
            {
                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.LabelField("Preview", GUILayout.Width(60f));
                EditorGUILayout.LabelField("Binding", GUILayout.Width(100f));
                EditorGUILayout.LabelField("Assembly Name");
                EditorGUILayout.EndHorizontal();
                _sv = EditorGUILayout.BeginScrollView(_sv);
                for (var i = 0; i < _assemblies.Length; i++)
                {
                    var a       = _assemblies[i];
                    var name    = a.GetName().Name;
                    var pMethod = BindingGenMethod.None;
                    if (_prefs.implicitAssemblies.Contains(name))
                    {
                        pMethod = BindingGenMethod.Implicit;
                    }
                    else if (_prefs.explicitAssemblies.Contains(name))
                    {
                        pMethod = BindingGenMethod.Explicit;
                    }
                    EditorGUI.BeginDisabledGroup(a.IsDynamic);
                    EditorGUILayout.BeginHorizontal();
                    var tRect    = EditorGUILayout.GetControlRect(GUILayout.Width(60f));
                    tRect.xMin   = tRect.xMax - 20f;
                    var selected = EditorGUI.Toggle(tRect, _selectedIndex == i);
                    var rMethod  = (BindingGenMethod)EditorGUILayout.EnumPopup(pMethod, GUILayout.Width(100f));
                    if (selected)
                    {
                        if (_selectedIndex != i)
                        {
                            _selectedIndex = i;
                            FilterTypes();
                        }
                    }
                    EditorGUILayout.TextField(name);
                    if (rMethod != pMethod)
                    {
                        switch (rMethod)
                        {
                        case BindingGenMethod.None:
                            if (pMethod == BindingGenMethod.Implicit)
                            {
                                _prefs.implicitAssemblies.Remove(name);
                                MarkAsDirty();
                            }
                            else if (pMethod == BindingGenMethod.Explicit)
                            {
                                _prefs.explicitAssemblies.Remove(name);
                                MarkAsDirty();
                            }
                            break;

                        case BindingGenMethod.Implicit:
                            if (pMethod == BindingGenMethod.Explicit)
                            {
                                _prefs.explicitAssemblies.Remove(name);
                            }
                            _prefs.implicitAssemblies.Add(name);
                            MarkAsDirty();
                            break;

                        case BindingGenMethod.Explicit:
                            if (pMethod == BindingGenMethod.Implicit)
                            {
                                _prefs.implicitAssemblies.Remove(name);
                            }
                            _prefs.explicitAssemblies.Add(name);
                            MarkAsDirty();
                            break;
                        }
                    }
                    EditorGUILayout.EndHorizontal();
                    EditorGUI.EndDisabledGroup();
                }
                EditorGUILayout.EndScrollView();
            }, () =>
            {
                var color = GUI.color;
                GUI.color = Color.green;
                if (GUILayout.Button("R", GUILayout.Width(20f)))
                {
                    if (EditorUtility.DisplayDialog("Reload", $"Reload {Prefs.PATH}?", "ok", "cancel"))
                    {
                        Defer(() => _prefs = UnityHelper.LoadPrefs(out _filePath));
                    }
                }
                GUI.color = color;
            }, () =>
            {
                var color = GUI.color;
                GUI.color = Color.yellow;
                if (GUILayout.Button("G", GUILayout.Width(20f)))
                {
                    if (EditorUtility.DisplayDialog("Generate", "Generate all binding code?", "ok", "cancel"))
                    {
                        Defer(() => UnityHelper.GenerateBindingsAndTypeDefinition());
                    }
                }
                GUI.color = color;
            }, () =>
            {
                var color = GUI.color;
                GUI.color = Color.red;
                if (GUILayout.Button("C", GUILayout.Width(20f)))
                {
                    if (EditorUtility.DisplayDialog("Cleanup", "Cleanup generated binding code?", "ok", "cancel"))
                    {
                        Defer(() => UnityHelper.ClearBindings());
                    }
                }
                GUI.color = color;
            });
            EditorGUILayout.BeginVertical();
            Block("Assembly Info", () =>
            {
                if (_selectedIndex >= 0 && _selectedIndex < _assemblies.Length)
                {
                    var assembly = _assemblies[_selectedIndex];
                    EditorGUILayout.TextField("Full Name", assembly.FullName);
                    EditorGUILayout.TextField("Location", assembly.Location, GUILayout.MinWidth(500f));
                }
            });
            Block("Types", () =>
            {
                var count = _filteredTypes.Count;
                for (var i = 0; i < count; i++)
                {
                    var type = _filteredTypes[i];
                    EditorGUILayout.TextField(type.FullName);
                }
                if (count == 0)
                {
                    EditorGUILayout.HelpBox("No type to bindgen.", MessageType.Info);
                }
            });
            EditorGUILayout.EndVertical();
            EditorGUILayout.EndHorizontal();
        }