protected override TreeViewItem BuildRoot() { ClearInstanceIds(); var root = new TreeViewItem { id = 0, depth = -1 }; var types = Model.GetTypes(); foreach (var typeReference in types) { var type = typeReference.Dereference(Model.Registry); var module = UTinyUtility.GetModules(Model.Registry, typeReference).FirstOrDefault(); var moduleReference = null != module ? (UTinyModule.Reference)module : UTinyModule.Reference.None; var editable = moduleReference.Id == Model.MainModule.Id; if (null != type) { if (type.TypeCode == UTinyTypeCode.Component && !State.FilterComponents) { continue; } if (type.TypeCode == UTinyTypeCode.Struct && !State.FilterStructs) { continue; } if (type.TypeCode == UTinyTypeCode.Enum && !State.FilterEnums) { continue; } if (!editable && State.FilterProjectOnly) { continue; } } var item = new UTinyTypeTreeViewItem(Model.Registry, Model.MainModule, moduleReference, (UTinyType.Reference)type) { id = GenerateInstanceId(typeReference), Editable = editable }; if (null != type) { foreach (var field in type.Fields) { item.AddChild(new UTinyFieldTreeViewItem(Model.Registry, Model.MainModule, moduleReference, field) { id = GenerateInstanceId(field), icon = UTinyIcons.Variable, depth = 1, Editable = editable }); } } root.AddChild(item); } return(root); }
private void CellGUI(Rect cellRect, UTinyTypeTreeViewItem item, ColumnType columnType, ref RowGUIArgs args) { CenterRectUsingSingleLineHeight(ref cellRect); var type = item.Type.Dereference(Model.Registry); using (new GUIEnabledScope(item.Editable)) { switch (columnType) { case ColumnType.Icon: { if (null == type) { GUI.DrawTexture(cellRect, UTinyIcons.Warning, ScaleMode.ScaleToFit); } else if (type.TypeCode == UTinyTypeCode.Component) { GUI.DrawTexture(cellRect, UTinyIcons.Component, ScaleMode.ScaleToFit); } else if (type.TypeCode == UTinyTypeCode.Struct) { GUI.DrawTexture(cellRect, UTinyIcons.Struct, ScaleMode.ScaleToFit); } else if (type.TypeCode == UTinyTypeCode.Enum) { GUI.DrawTexture(cellRect, UTinyIcons.Enum, ScaleMode.ScaleToFit); } } break; case ColumnType.Name: { args.rowRect = cellRect; using (new GUIColorScope(null == type ? Color.red : Color.white)) { base.RowGUI(args); } } break; case ColumnType.Type: { if (null != type) { GUI.Label(cellRect, $"{type.TypeCode}"); } } break; case ColumnType.Module: { GUI.Label(cellRect, item.Module.Name); } break; case ColumnType.Description: { if (type != null) { if (item.Editable) { type.Documentation.Summary = EditorGUI.TextField(cellRect, type.Documentation.Summary); } else { GUI.Label(cellRect, type.Documentation.Summary); } } } break; } } }