No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

BindingTreeViewDataSourceGUI.cs 4.6KB

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