private static GeneratorTreeGenerator AddGeneratorToTree(List <GeneratorTreeItem> generatorTree, System.Type generatorType, GeneratorAttribute attribute) { var path = attribute.path; int depth = 0; int categoryCount = path.Length - 1; GeneratorTreeCategory parent = null; var items = generatorTree; while (depth < categoryCount) { var category = items.Find((GeneratorTreeItem item) => { return(item.content.text == path[depth] && item is GeneratorTreeCategory); }); if (category == null) { break; } parent = (GeneratorTreeCategory)category; items = parent.items; ++depth; } while (depth < categoryCount) { var category = new GeneratorTreeCategory(path[depth], parent); items.Add(category); parent = category; items = parent.items; ++depth; } var creatorMethod = FindCreatorMethod(generatorType); if (creatorMethod != null) { var item = new GeneratorTreeGenerator(path[depth], parent, (GeneratorExecutive collection, int insertionIndex) => { var generator = (Generator)creatorMethod.Invoke(null, new object[2] { collection, attribute.name }); collection.Insert(insertionIndex, generator); }); items.Add(item); return(item); } else { var item = new GeneratorTreeGenerator(new GUIContent(path[depth], "A generator of this type cannot be created because no valid creation function was found."), parent, null); items.Add(item); return(item); } }
public override void OnGUI(Rect rect) { InitializeStyles(); List <GeneratorTreeItem> items; var selectedCategory = _openCategory; if (_openCategory == null) { items = _generatorTree; GUILayout.Label(GUIContent.none, _titleStyle, GUILayout.ExpandWidth(true)); var titleRect = GUILayoutUtility.GetLastRect(); var titleTextRect = titleRect; titleTextRect.yMin += 4; GUI.Label(titleTextRect, "Generator", _titleTextStyle); } else { items = _openCategory.items; GUILayout.Label(GUIContent.none, _titleStyle, GUILayout.ExpandWidth(true)); var titleRect = GUILayoutUtility.GetLastRect(); if (GUI.Button(titleRect, GUIContent.none, GUIStyle.none)) { selectedCategory = selectedCategory.parent; } var titleTextRect = titleRect; titleTextRect.yMin += 4; GUI.Label(titleTextRect, _openCategory.content, _subtitleTextStyle); GUI.DrawTexture( new Rect( 5f, titleRect.yMin + (titleRect.height - _leftArrowTexture.height) / 2f + 1f, _leftArrowTexture.width, _leftArrowTexture.height), _leftArrowTexture, ScaleMode.ScaleAndCrop, true); } _scrollPosition = GUILayout.BeginScrollView(_scrollPosition, false, false); foreach (var item in items) { if (item is GeneratorTreeCategory) { var category = (GeneratorTreeCategory)item; GUIExtensions.PushEnable(category.items.Count > 0); if (GUILayout.Button(category.content, _categoryStyle)) { selectedCategory = category; } GUIExtensions.PopEnable(); var categoryRect = GUILayoutUtility.GetLastRect(); GUI.DrawTexture( new Rect( categoryRect.xMax - _rightArrowTexture.width - 1f, categoryRect.yMin + (categoryRect.height - _rightArrowTexture.height) / 2f, _rightArrowTexture.width, _rightArrowTexture.height), _rightArrowTexture, ScaleMode.ScaleAndCrop, true); } else if (item is GeneratorTreeGenerator) { var generator = (GeneratorTreeGenerator)item; GUIExtensions.PushEnable(generator.onSelect != null); if (GUILayout.Button(generator.content, _generatorStyle)) { generator.onSelect(_executive, _executive.generators.Count); editorWindow.Close(); } GUIExtensions.PopEnable(); } } GUILayout.EndScrollView(); editorWindow.Repaint(); _openCategory = selectedCategory; }
public GeneratorTreeCategory(GUIContent content, GeneratorTreeCategory parent) : base(content, parent) { items = new List <GeneratorTreeItem>(); }
public GeneratorTreeCategory(string name, GeneratorTreeCategory parent) : base(name, parent) { items = new List <GeneratorTreeItem>(); }
public GeneratorTreeGenerator(GUIContent content, GeneratorTreeCategory parent, System.Action <GeneratorExecutive, int> onSelect) : base(content, parent) { this.onSelect = onSelect; }
public GeneratorTreeGenerator(string name, GeneratorTreeCategory parent, System.Action <GeneratorExecutive, int> onSelect) : base(name, parent) { this.onSelect = onSelect; }
public GeneratorTreeItem(GUIContent content, GeneratorTreeCategory parent) { this.content = content; this.parent = parent; }
public GeneratorTreeItem(string name, GeneratorTreeCategory parent) { content = new GUIContent(name); this.parent = parent; }