[MenuItem(itemName: "Assets/Create/Atoms Search &1", isValidateFunction: false, priority: -1)] // Adds to the project window's create menu public static void AtomsSearchMenu() { StringTree <Type> typeTree = new StringTree <Type>(); foreach (var type in TypeCache.GetTypesWithAttribute <CreateAssetMenuAttribute>() .Where(t => t.GetCustomAttribute <AtomsSearchable>(true) != null)) { var name = type.GetCustomAttribute <CreateAssetMenuAttribute>().menuName; var i = name.LastIndexOf('/'); name = (i == -1) ? name : name.Substring(0, i + 1) + type.Name; typeTree.Insert(name, type, 1); } var projectBrowserType = typeof(UnityEditor.Editor).Assembly.GetType("UnityEditor.ProjectBrowser"); var projectBrowser = EditorWindow.GetWindow(projectBrowserType); Vector2 xy = new Vector2(projectBrowser.position.x + 10, projectBrowser.position.y + 60); var dropdown = new SearchTypeDropdown(new AdvancedDropdownState(), typeTree, (s) => { EditorApplication.ExecuteMenuItem("Assets/Create/" + s.GetCustomAttribute <CreateAssetMenuAttribute>().menuName); }) { MinimumSize = new Vector2(projectBrowser.position.width - 20, projectBrowser.position.height - 80) }; var rect = new Rect(xy.x, xy.y, projectBrowser.position.width - 20, projectBrowser.position.height); dropdown.Show(new Rect()); // don't use this to position the var window = typeof(SearchTypeDropdown).GetField("m_WindowInstance", BindingFlags.Instance | BindingFlags.NonPublic)?.GetValue(dropdown) as EditorWindow; window.position = rect; }
public override void OnInspectorGUI() { var rect = GUILayoutUtility.GetRect(new GUIContent("Show"), EditorStyles.toolbarButton); if (GUILayout.Button("Select Type")) { var dropdown = new SearchTypeDropdown(new AdvancedDropdownState(), _types, (s) => { serializedObject.FindProperty("Namespace").stringValue = s.Split(':')[0]; serializedObject.FindProperty("BaseType").stringValue = s.Split(':')[1]; var type = _types.First(grouping => grouping.Key == serializedObject.FindProperty("Namespace").stringValue) .First(t => t.Name == serializedObject.FindProperty("BaseType").stringValue); serializedObject.FindProperty("FullQualifiedName").stringValue = type.AssemblyQualifiedName; }); dropdown.Show(rect); } EditorGUILayout.PropertyField(serializedObject.FindProperty("FullQualifiedName")); var options = serializedObject.FindProperty("GenerationOptions").intValue; var scripts = (target as AtomGenerator)?.Scripts; for (var index = 0; index < AtomTypes.ALL_ATOM_TYPES.Count; index++) { var option = AtomTypes.ALL_ATOM_TYPES[index]; EditorGUILayout.BeginHorizontal(); bool b = (options & (1 << index)) == (1 << index); EditorGUI.BeginChangeCheck(); b = EditorGUILayout.Toggle(AtomTypes.ALL_ATOM_TYPES[index].DisplayName, b); if (EditorGUI.EndChangeCheck()) { if (b) { options |= (1 << index); // add all dependencies: if (AtomTypes.DEPENDENCY_GRAPH.TryGetValue(option, out var list)) { list.ForEach(dep => options |= (1 << AtomTypes.ALL_ATOM_TYPES.IndexOf(dep))); } } else { options &= ~(1 << index); // remove all depending: foreach (var keyValuePair in AtomTypes.DEPENDENCY_GRAPH.Where(kv => kv.Value.Contains(option))) { options &= ~(1 << AtomTypes.ALL_ATOM_TYPES.IndexOf(keyValuePair.Key)); } } } if (scripts != null && index < scripts.Count && scripts[index] != null) { EditorGUILayout.ObjectField(scripts[index], typeof(MonoScript), false, GUILayout.Width(200)); } else { EditorGUILayout.LabelField(GUIContent.none, GUILayout.Width(200)); } EditorGUILayout.EndHorizontal(); } serializedObject.FindProperty("GenerationOptions").intValue = options; serializedObject.ApplyModifiedProperties(); if (GUILayout.Button("(Re)Generate")) { (target as AtomGenerator)?.Generate(); AssetDatabase.SaveAssets(); } }