BindingTreeViewDataSourceGUI.cs 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. using UnityEditor;
  2. using UnityEditor.IMGUI.Controls;
  3. using UnityEngine;
  4. namespace UnityEditorInternal
  5. {
  6. class BindingTreeViewGUI : TreeViewGUI
  7. {
  8. static readonly float s_RowRightOffset = 10;
  9. static readonly float s_ColorIndicatorTopMargin = 3;
  10. static readonly Color s_KeyColorForNonCurves = new Color(0.7f, 0.7f, 0.7f, 0.5f);
  11. static readonly Color s_ChildrenCurveLabelColor = new Color(1.0f, 1.0f, 1.0f, 0.7f);
  12. public BindingTreeViewGUI(TreeViewController treeView)
  13. : base(treeView, true)
  14. {
  15. k_IconWidth = 13.0f;
  16. }
  17. public override void OnRowGUI(Rect rowRect, TreeViewItem node, int row, bool selected, bool focused)
  18. {
  19. Color originalColor = GUI.color;
  20. GUI.color = node.parent == null ||
  21. node.parent.id == BindingTreeViewDataSource.RootID ||
  22. node.parent.id == BindingTreeViewDataSource.GroupID ?
  23. Color.white :
  24. s_ChildrenCurveLabelColor;
  25. base.OnRowGUI(rowRect, node, row, selected, focused);
  26. GUI.color = originalColor;
  27. DoCurveColorIndicator(rowRect, node as CurveTreeViewNode);
  28. }
  29. protected override bool IsRenaming(int id)
  30. {
  31. return false;
  32. }
  33. public override bool BeginRename(TreeViewItem item, float delay)
  34. {
  35. return false;
  36. }
  37. void DoCurveColorIndicator(Rect rect, CurveTreeViewNode node)
  38. {
  39. if (node == null)
  40. return;
  41. if (Event.current.type != EventType.Repaint)
  42. return;
  43. Color originalColor = GUI.color;
  44. if (node.bindings.Length == 1 && !node.bindings[0].isPPtrCurve)
  45. GUI.color = CurveUtility.GetPropertyColor(node.bindings[0].propertyName);
  46. else
  47. GUI.color = s_KeyColorForNonCurves;
  48. Texture icon = CurveUtility.GetIconCurve();
  49. rect = new Rect(rect.xMax - s_RowRightOffset - (icon.width * 0.5f) - 5, rect.yMin + s_ColorIndicatorTopMargin, icon.width, icon.height);
  50. GUI.DrawTexture(rect, icon, ScaleMode.ScaleToFit, true, 1);
  51. GUI.color = originalColor;
  52. }
  53. protected override Texture GetIconForItem(TreeViewItem item)
  54. {
  55. var node = item as CurveTreeViewNode;
  56. if (node == null)
  57. return null;
  58. if (node.bindings == null || node.bindings.Length == 0)
  59. return null;
  60. return AssetPreview.GetMiniTypeThumbnail(node.bindings[0].type);
  61. }
  62. }
  63. }