void OnGUI() { if (initializer == null) { var assmblies = AppDomain.CurrentDomain.GetAssemblies().Where(a => a.FullName.StartsWith("Unity") || a.FullName.StartsWith("Assembly-CSharp")); assmblies = assmblies.Concat(new[] { typeof(string).Assembly }).OrderBy(a => a.FullName); infos.Clear(); foreach (var item in assmblies) { infos.Add(new AssemblyInfo(item)); } EditorCoroutine.StartMultiple(LoadTypes(), SelectTypes(), FilterTypes()); initializer = new object(); } EditorGUI.BeginDisabledGroup(isBusy); EditorGUILayout.Space(); EditorGUILayout.LabelField("Libraries", EditorStyles.boldLabel); EditorGUI.indentLevel++; EditorGUI.BeginChangeCheck(); var w = position.size.x - 200; EditorGUIUtility.labelWidth += w; libraryScroll = EditorGUILayout.BeginScrollView(libraryScroll, GUILayout.Height(200)); foreach (var item in infos) { item.State = EditorGUILayout.Toggle(item.Name, item.State); } EditorGUILayout.EndScrollView(); EditorGUIUtility.labelWidth -= w; if (EditorGUI.EndChangeCheck()) { EditorCoroutine.StartMultiple(SelectTypes(), FilterTypes()); } EditorGUI.indentLevel--; EditorGUILayout.Space(); EditorGUILayout.LabelField("Filter", EditorStyles.boldLabel); EditorGUI.indentLevel++; EditorGUI.BeginChangeCheck(); EditorGUILayout.LabelField("Prefix with t: for a base type"); EditorGUILayout.LabelField("Example: t:Component"); EditorGUILayout.LabelField("Combined example: t:Component Collider"); typeFilter = EditorGUILayout.DelayedTextField(typeFilter); if (EditorGUI.EndChangeCheck()) { EditorCoroutine.Start(FilterTypes()); } EditorGUI.indentLevel--; EditorGUILayout.Space(); EditorGUILayout.LabelField("Types", EditorStyles.boldLabel); int pageOffset = page * 100; var rect = EditorGUILayout.GetControlRect(); EditorGUI.BeginDisabledGroup(page == 0); if (GUI.Button(new Rect(rect.x, rect.y, rect.width / 2, rect.height), "<")) { if (page > 0) { page--; typeScroll = Vector2.zero; } } EditorGUI.EndDisabledGroup(); EditorGUI.BeginDisabledGroup(pageOffset + 100 >= filteredTypes.Count); if (GUI.Button(new Rect(rect.x + (rect.width / 2), rect.y, rect.width / 2, rect.height), ">")) { page++; typeScroll = Vector2.zero; } EditorGUI.EndDisabledGroup(); if (GUILayout.Button("Toggle Page")) { for (int i = pageOffset; i < pageOffset + 100; i++) { if (i < filteredTypes.Count) { var t = filteredTypes[i]; if (!typeStates.ContainsKey(t)) { typeStates.Add(t, false); } typeStates[t] = !typeStates[t]; } else { break; } } } typeScroll = EditorGUILayout.BeginScrollView(typeScroll); EditorGUI.indentLevel++; for (int i = pageOffset; i < pageOffset + 100; i++) { if (i < filteredTypes.Count) { var t = filteredTypes[i]; if (!typeStates.ContainsKey(t)) { typeStates.Add(t, false); } typeStates[t] = EditorGUILayout.ToggleLeft(string.Format("{0} ({1})", t.Name, t.Assembly.GetName().Name), typeStates[t]); } else { break; } } EditorGUI.indentLevel--; EditorGUILayout.EndScrollView(); if (GUILayout.Button("Generate")) { var types = typeStates.Where(t => t.Value) .Select(t => t.Key).Select(t => new WizardData() { Type = t, Name = Utils.GetTypeName(t), Fields = new Dictionary <FieldInfo, bool>().AddRange(GetFields(t).Select(f => new KeyValuePair <FieldInfo, bool>(f, false))), Properties = new Dictionary <PropertyInfo, bool>().AddRange(GetProperties(t).Select(p => new KeyValuePair <PropertyInfo, bool>(p, false))), Methods = new Dictionary <MethodInfo, bool>().AddRange(GetMethods(t).Select(m => new KeyValuePair <MethodInfo, bool>(m, false))), }).ToList(); GeneratorWizard.Init(types); } if (GUILayout.Button("Generate All")) { var types = typeStates.Where(t => t.Value) .Select(t => t.Key).Select(t => new WizardData() { Type = t, Name = Utils.GetTypeName(t), Fields = new Dictionary <FieldInfo, bool>().AddRange(GetFields(t).Select(f => new KeyValuePair <FieldInfo, bool>(f, false))), Properties = new Dictionary <PropertyInfo, bool>().AddRange(GetProperties(t).Select(p => new KeyValuePair <PropertyInfo, bool>(p, false))), Methods = new Dictionary <MethodInfo, bool>().AddRange(GetMethods(t).Select(m => new KeyValuePair <MethodInfo, bool>(m, false))), }).ToList(); foreach (var item in types) { { var keys = item.Fields.Keys; for (int i = keys.Count() - 1; i >= 0; i--) { var key = keys.ElementAt(i); item.Fields[key] = true; } } { var keys = item.Properties.Keys; for (int i = keys.Count() - 1; i >= 0; i--) { var key = keys.ElementAt(i); item.Properties[key] = true; } } { var keys = item.Methods.Keys; for (int i = keys.Count() - 1; i >= 0; i--) { var key = keys.ElementAt(i); item.Methods[key] = true; } } } Generate(types.Select(d => new GenerationData() { Type = d.Type, Fields = d.Fields.Where(f => f.Value).Select(f => f.Key).ToList(), Properties = d.Properties.Where(p => p.Value).Select(f => f.Key).ToList(), Methods = d.Methods.Where(m => m.Value).Select(f => f.Key).ToList(), }).ToList()); } EditorGUI.EndDisabledGroup(); }
void OnGUI() { if (initializer == null) { EditorCoroutine.StartMultiple(LoadTypesAsync(), LoadNamesAsync(), SelectTypesAsync(), FilterTypesAsync()); initializer = new object(); } EditorGUI.BeginDisabledGroup(isBusy); EditorGUILayout.Space(); EditorGUILayout.LabelField("Libraries", EditorStyles.boldLabel); EditorGUI.indentLevel++; EditorGUI.BeginChangeCheck(); EditorGUIUtility.labelWidth += 30; includeAssemblyCSharp = EditorGUILayout.Toggle("Assembly-CSharp", includeAssemblyCSharp); includeAssemblyCSharpEditor = EditorGUILayout.Toggle("Assembly-CSharp-Editor", includeAssemblyCSharpEditor); includeMSCorlib = EditorGUILayout.Toggle("mscorlib", includeMSCorlib); includeUnityEditor = EditorGUILayout.Toggle("UnityEditor", includeUnityEditor); includeUnityEngine = EditorGUILayout.Toggle("UnityEngine", includeUnityEngine); EditorGUIUtility.labelWidth -= 30; if (EditorGUI.EndChangeCheck()) { EditorCoroutine.StartMultiple(SelectTypesAsync(), FilterTypesAsync()); } EditorGUI.indentLevel--; EditorGUILayout.Space(); EditorGUILayout.LabelField("Base Type", EditorStyles.boldLabel); EditorGUI.indentLevel++; EditorGUI.BeginChangeCheck(); EditorGUIUtility.labelWidth += 30; useBaseType = EditorGUILayout.Toggle("Enable", useBaseType); EditorGUIUtility.labelWidth -= 30; baseTypeIndex = EditorGUILayout.Popup(baseTypeIndex, typeNames); if (EditorGUI.EndChangeCheck()) { FilterTypes(); } EditorGUI.indentLevel--; EditorGUILayout.Space(); EditorGUILayout.LabelField("Search", EditorStyles.boldLabel); EditorGUI.BeginChangeCheck(); EditorGUI.indentLevel++; searchQuery = EditorGUILayout.TextField(searchQuery); EditorGUI.indentLevel--; if (EditorGUI.EndChangeCheck()) { FilterTypes(); } EditorGUILayout.Space(); EditorGUILayout.LabelField("Types", EditorStyles.boldLabel); scrollPosition = EditorGUILayout.BeginScrollView(scrollPosition); EditorGUI.indentLevel++; foreach (var item in filteredTypes) { var value = typesEnabled[item]; value = EditorGUILayout.ToggleLeft(GetTypeName(item), value); typesEnabled[item] = value; } EditorGUI.indentLevel--; EditorGUILayout.EndScrollView(); if (GUILayout.Button("Generate")) { var types = typesEnabled.Where(t => t.Value) .Select(t => t.Key).Select(t => new WizardData() { Type = t, Name = GetTypeName(t), Fields = new Dictionary <FieldInfo, bool>().AddRange(GetFields(t).Select(f => new KeyValuePair <FieldInfo, bool>(f, false))), Properties = new Dictionary <PropertyInfo, bool>().AddRange(GetProperties(t).Select(p => new KeyValuePair <PropertyInfo, bool>(p, false))), Methods = new Dictionary <MethodInfo, bool>().AddRange(GetMethods(t).Select(m => new KeyValuePair <MethodInfo, bool>(m, false))), }).ToList(); GeneratorWizard.Init(types); } EditorGUI.EndDisabledGroup(); }