BindingTreeViewDataSourceGUI.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. using System.Linq;
  2. using UnityEditor.IMGUI.Controls;
  3. using UnityEditorInternal;
  4. using UnityEngine;
  5. using UnityEngine.Playables;
  6. using UnityEngine.Timeline;
  7. namespace UnityEditor.Timeline
  8. {
  9. class BindingTreeViewGUI : TreeViewGUI
  10. {
  11. static readonly float s_RowRightOffset = 10;
  12. static readonly float s_ColorIndicatorTopMargin = 3;
  13. static readonly Color s_KeyColorForNonCurves = new Color(0.7f, 0.7f, 0.7f, 0.5f);
  14. static readonly Color s_ChildrenCurveLabelColor = new Color(1.0f, 1.0f, 1.0f, 0.7f);
  15. static readonly Color s_PhantomPropertyLabelColor = new Color(0.0f, 0.8f, 0.8f, 1f);
  16. static readonly Texture2D s_DefaultScriptTexture = EditorGUIUtility.LoadIcon("cs Script Icon");
  17. static readonly Texture2D s_TrackDefault = EditorGUIUtility.LoadIcon("UnityEngine/ScriptableObject Icon");
  18. public BindingTreeViewGUI(TreeViewController treeView)
  19. : base(treeView, true)
  20. {
  21. k_IconWidth = 13.0f;
  22. iconOverlayGUI += OnItemIconOverlay;
  23. }
  24. public override void OnRowGUI(Rect rowRect, TreeViewItem node, int row, bool selected, bool focused)
  25. {
  26. Color originalColor = GUI.color;
  27. bool leafNode = node.parent != null && node.parent.id != BindingTreeViewDataSource.RootID && node.parent.id != BindingTreeViewDataSource.GroupID;
  28. GUI.color = Color.white;
  29. if (leafNode)
  30. {
  31. CurveTreeViewNode curveNode = node as CurveTreeViewNode;
  32. if (curveNode != null && curveNode.bindings.Any() && curveNode.bindings.First().isPhantom)
  33. GUI.color = s_PhantomPropertyLabelColor;
  34. else
  35. GUI.color = s_ChildrenCurveLabelColor;
  36. }
  37. base.OnRowGUI(rowRect, node, row, selected, focused);
  38. GUI.color = originalColor;
  39. DoCurveColorIndicator(rowRect, node as CurveTreeViewNode);
  40. }
  41. protected override bool IsRenaming(int id)
  42. {
  43. return false;
  44. }
  45. public override bool BeginRename(TreeViewItem item, float delay)
  46. {
  47. return false;
  48. }
  49. static void DoCurveColorIndicator(Rect rect, CurveTreeViewNode node)
  50. {
  51. if (node == null)
  52. return;
  53. if (Event.current.type != EventType.Repaint)
  54. return;
  55. Color originalColor = GUI.color;
  56. if (node.bindings.Length == 1 && !node.bindings[0].isPPtrCurve)
  57. GUI.color = CurveUtility.GetPropertyColor(node.bindings[0].propertyName);
  58. else
  59. GUI.color = s_KeyColorForNonCurves;
  60. Texture icon = CurveUtility.GetIconCurve();
  61. rect = new Rect(rect.xMax - s_RowRightOffset - (icon.width * 0.5f) - 5, rect.yMin + s_ColorIndicatorTopMargin, icon.width, icon.height);
  62. GUI.DrawTexture(rect, icon, ScaleMode.ScaleToFit, true, 1);
  63. GUI.color = originalColor;
  64. }
  65. protected override Texture GetIconForItem(TreeViewItem item)
  66. {
  67. var node = item as CurveTreeViewNode;
  68. if (node == null)
  69. return null;
  70. var type = node.iconType;
  71. if (type == null)
  72. return null;
  73. // track type icon
  74. if (typeof(TrackAsset).IsAssignableFrom(type))
  75. {
  76. var icon = TrackResourceCache.GetTrackIconForType(type);
  77. return icon == s_TrackDefault ? s_DefaultScriptTexture : icon;
  78. }
  79. // custom clip icons always use the script texture
  80. if (typeof(PlayableAsset).IsAssignableFrom(type))
  81. return s_DefaultScriptTexture;
  82. // this will return null for MonoBehaviours without a custom icon.
  83. // use the scripting icon instead
  84. return AssetPreview.GetMiniTypeThumbnail(type) ?? s_DefaultScriptTexture;
  85. }
  86. static void OnItemIconOverlay(TreeViewItem item, Rect rect)
  87. {
  88. var curveNodeItem = item as CurveTreeViewNode;
  89. if (curveNodeItem != null && curveNodeItem.iconOverlay != null)
  90. GUI.Label(rect, curveNodeItem.iconOverlay);
  91. }
  92. }
  93. }