A game about forced loneliness, made by TACStudios
at master 126 lines 4.7 kB view raw
1using System.Linq; 2using UnityEditor.IMGUI.Controls; 3using UnityEngine; 4using UnityEngine.Playables; 5using UnityEngine.Timeline; 6 7namespace UnityEditor.Timeline 8{ 9 class BindingTreeViewGUI : TreeViewGUI 10 { 11 const float k_RowRightOffset = 10; 12 const float k_CurveColorIndicatorIconSize = 11; 13 const float k_ColorIndicatorTopMargin = 3; 14 15 static readonly Color s_KeyColorForNonCurves = new Color(0.7f, 0.7f, 0.7f, 0.5f); 16 static readonly Color s_ChildrenCurveLabelColor = new Color(1.0f, 1.0f, 1.0f, 0.7f); 17 static readonly Color s_PhantomPropertyLabelColor = new Color(0.0f, 0.8f, 0.8f, 1f); 18 static readonly Texture2D s_DefaultScriptTexture = EditorGUIUtility.LoadIcon("cs Script Icon"); 19 static readonly Texture2D s_TrackDefault = EditorGUIUtility.LoadIcon("UnityEngine/ScriptableObject Icon"); 20 public float parentWidth { get; set; } 21 22 public BindingTreeViewGUI(TreeViewController treeView) 23 : base(treeView, true) 24 { 25 k_IconWidth = 13.0f; 26 iconOverlayGUI += OnItemIconOverlay; 27 } 28 29 public override void OnRowGUI(Rect rowRect, TreeViewItem node, int row, bool selected, bool focused) 30 { 31 Color originalColor = GUI.color; 32 bool leafNode = node.parent != null && node.parent.id != BindingTreeViewDataSource.RootID && node.parent.id != BindingTreeViewDataSource.GroupID; 33 GUI.color = Color.white; 34 if (leafNode) 35 { 36 CurveTreeViewNode curveNode = node as CurveTreeViewNode; 37 if (curveNode != null && curveNode.bindings.Any() && curveNode.bindings.First().isPhantom) 38 GUI.color = s_PhantomPropertyLabelColor; 39 else 40 GUI.color = s_ChildrenCurveLabelColor; 41 } 42 43 base.OnRowGUI(rowRect, node, row, selected, focused); 44 45 GUI.color = originalColor; 46 DoCurveColorIndicator(rowRect, node as CurveTreeViewNode); 47 } 48 49 protected override bool IsRenaming(int id) 50 { 51 return false; 52 } 53 54 public override bool BeginRename(TreeViewItem item, float delay) 55 { 56 return false; 57 } 58 59 static void DoCurveColorIndicator(Rect rect, CurveTreeViewNode node) 60 { 61 if (node == null) 62 return; 63 64 if (Event.current.type != EventType.Repaint) 65 return; 66 67 Color originalColor = GUI.color; 68 69 if (node.bindings.Length == 1 && !node.bindings[0].isPPtrCurve) 70 GUI.color = CurveUtility.GetPropertyColor(node.bindings[0].propertyName); 71 else 72 GUI.color = s_KeyColorForNonCurves; 73 74 Texture icon = CurveUtility.GetIconCurve(); 75 76 rect = new Rect(rect.xMax - k_RowRightOffset - (k_CurveColorIndicatorIconSize / 2) - 5, 77 rect.yMin + k_ColorIndicatorTopMargin + (rect.height - EditorGUIUtility.singleLineHeight) / 2, 78 k_CurveColorIndicatorIconSize, 79 k_CurveColorIndicatorIconSize); 80 81 GUI.DrawTexture(rect, icon, ScaleMode.ScaleToFit, true, 1); 82 83 GUI.color = originalColor; 84 } 85 86 protected override Texture GetIconForItem(TreeViewItem item) 87 { 88 var node = item as CurveTreeViewNode; 89 if (node == null) 90 return null; 91 92 var type = node.iconType; 93 if (type == null) 94 return null; 95 96 // track type icon 97 if (typeof(TrackAsset).IsAssignableFrom(type)) 98 { 99 var icon = TrackResourceCache.GetTrackIconForType(type); 100 return icon == s_TrackDefault ? s_DefaultScriptTexture : icon; 101 } 102 103 // custom clip icons always use the script texture 104 if (typeof(PlayableAsset).IsAssignableFrom(type)) 105 return s_DefaultScriptTexture; 106 107 // this will return null for MonoBehaviours without a custom icon. 108 // use the scripting icon instead 109 return AssetPreview.GetMiniTypeThumbnail(type) ?? s_DefaultScriptTexture; 110 } 111 112 static void OnItemIconOverlay(TreeViewItem item, Rect rect) 113 { 114 var curveNodeItem = item as CurveTreeViewNode; 115 if (curveNodeItem != null && curveNodeItem.iconOverlay != null) 116 GUI.Label(rect, curveNodeItem.iconOverlay); 117 } 118 119 public override Vector2 GetTotalSize() 120 { 121 var originalSize = base.GetTotalSize(); 122 originalSize.x = Mathf.Max(parentWidth, originalSize.x); 123 return originalSize; 124 } 125 } 126}