private UTinyAssetTreeViewItem BuildItem(UTinyAssetInfo assetInfo, int depth) { var item = new UTinyAssetTreeViewItem(Model.Registry, Model.MainModule, Model.MainModule, assetInfo) { id = Model.GenerateId(assetInfo), Editable = assetInfo.ExplicitReferences.Contains(Model.MainModule), depth = depth }; if (assetInfo.Parent != null) { item.icon = EditorGUIUtility.ObjectContent(null, assetInfo.Object.GetType()).image as Texture2D; } foreach (var child in assetInfo.Children) { item.AddChild(BuildItem(child, depth + 1)); } return(item); }
private void CellGUI(Rect cellRect, UTinyAssetTreeViewItem item, ColumnType columnType, ref RowGUIArgs args) { // Center cell rect vertically (makes it easier to place controls, icons etc in the cells) CenterRectUsingSingleLineHeight(ref cellRect); var @object = item.AssetInfo.Object; var name = item.AssetInfo.Name; var isUnique = m_AssetNames.Count(s => string.Equals(s, name)) <= 1; using (new GUIColorScope(isUnique ? Color.white : Color.red)) using (new GUIEnabledScope(item.Editable)) { var content = EditorGUIUtility.ObjectContent(null, @object.GetType()); switch (columnType) { case ColumnType.Icon: { if (item.AssetInfo.Parent == null) { GUI.DrawTexture(cellRect, content.image, ScaleMode.ScaleToFit); } } break; case ColumnType.Name: { args.rowRect = cellRect; base.RowGUI(args); } break; case ColumnType.Path: { GUI.Label(cellRect, item.AssetInfo.AssetPath); } break; case ColumnType.Type: { GUI.Label(cellRect, @object.GetType().Name); } break; case ColumnType.Status: { var status = item.AssetInfo.IncludedExplicitly ? "Explicit" : "Implicit"; using (new GUIColorScope(item.AssetInfo.IncludedExplicitly ? Color.green : Color.white)) { GUI.Label(cellRect, status); } } break; case ColumnType.References: { GUI.Label(cellRect, item.AssetInfo.ImplicitReferences.Count.ToString()); } break; } } if (Event.current.type == EventType.MouseDrag && cellRect.Contains(Event.current.mousePosition)) { DragAndDrop.PrepareStartDrag(); DragAndDrop.objectReferences = new[] { item.AssetInfo.Object }; DragAndDrop.StartDrag("Dragging sprite"); Event.current.Use(); } }