protected override TreeViewItem BuildRoot() { ClearInstanceIds(); var root = new TreeViewItem { id = 0, depth = -1 }; var modules = Model.GetModules(); foreach (var reference in modules) { var item = new UTinyModuleTreeViewItem(Model.Registry, Model.MainModule, reference) { id = GenerateInstanceId(reference) }; var module = reference.Dereference(Model.Registry); if (null != module) { module.Refresh(); foreach (var component in module.Components) { item.AddChild(new TreeViewItem { id = GenerateInstanceId(component), displayName = component.Name, icon = UTinyIcons.Component, depth = 1 }); } foreach (var @struct in module.Structs) { item.AddChild(new TreeViewItem { id = GenerateInstanceId(@struct), displayName = @struct.Name, icon = UTinyIcons.Struct, depth = 1 }); } foreach (var script in module.Scripts) { item.AddChild(new TreeViewItem { id = GenerateInstanceId(script), displayName = script.Name, icon = UTinyIcons.Function, depth = 1 }); } } root.AddChild(item); } return(root); }
private void CellGUI(Rect cellRect, UTinyModuleTreeViewItem item, ColumnType columnType, ref RowGUIArgs args) { // Center cell rect vertically (makes it easier to place controls, icons etc in the cells) CenterRectUsingSingleLineHeight(ref cellRect); using (new GUIEnabledScope(item.Status != UTinyModuleTreeViewItem.StatusType.Self && (item.Status != UTinyModuleTreeViewItem.StatusType.IncludedRequired))) { var moduleReference = item.Module; var module = item.Module.Dereference(Model.Registry); switch (columnType) { case ColumnType.Icon: { GUI.DrawTexture(cellRect, null == module ? UTinyIcons.Warning : UTinyIcons.Module, ScaleMode.ScaleToFit); } break; case ColumnType.Name: { var toggleRect = cellRect; toggleRect.x += GetContentIndent(item); toggleRect.width = 18; EditorGUI.BeginChangeCheck(); item.Included = EditorGUI.Toggle(toggleRect, item.Included); if (EditorGUI.EndChangeCheck()) { ShowConfigurationInspector(); Reload(); } args.rowRect = cellRect; using (new GUIColorScope(null == module ? Color.red : Color.white)) { base.RowGUI(args); } } break; case ColumnType.Status: { string status; switch (item.Status) { case UTinyModuleTreeViewItem.StatusType.Self: status = ""; break; case UTinyModuleTreeViewItem.StatusType.Excluded: status = "Excluded"; break; case UTinyModuleTreeViewItem.StatusType.IncludedRequired: status = "Included (Required)"; break; case UTinyModuleTreeViewItem.StatusType.IncludedExplicit: status = "Included (Explicit)"; break; case UTinyModuleTreeViewItem.StatusType.IncludedImplicit: status = "Included (Implicit)"; break; default: throw new ArgumentOutOfRangeException(); } using (new GUIColorScope(item.Status != UTinyModuleTreeViewItem.StatusType.Excluded ? item.Status != UTinyModuleTreeViewItem.StatusType.IncludedImplicit ? Color.green : Color.cyan : Color.white)) { GUI.Label(cellRect, status); } } break; case ColumnType.Dependencies: { var @string = ""; if (module != null) { for (var i = 0; i < module.Dependencies.Count; i++) { var @ref = module.Dependencies[i]; var m = @ref.Dereference(Model.Registry); if (i > 0) { @string += ", "; } if (null == m) { @string += $"{@ref.Name} (missing)"; } else { @string += m.Name; } } } GUI.Label(cellRect, @string); } break; case ColumnType.ReferencedBy: { var modules = UTinyModule.GetExplicitDependantModules(Model.Registry, moduleReference).Where(m => !m.IsProjectModule); var @string = string.Join(", ", modules.Select(m => m.Name).ToArray()); GUI.Label(cellRect, @string); } break; case ColumnType.Description: { if (module != null) { EditorGUI.LabelField(cellRect, module.Documentation.Summary); } } break; } } }