private void DrawTrack(Rect rect, Color color, Timeline.TrackEntry trackEntry, float leftTime, float rightTime, float currentTime) { //Get the items to draw trackEntry.Track.GetItems(itemCache); //Draw background GUI.color = new Color(.3f, .3f, .3f, 1f); GUI.DrawTexture(rect, Texture2D.whiteTexture); //Draw content GUI.color = color; for (int i = 0; i < itemCache.Count; i++) { TimelineItem item = itemCache[i]; var itemStartTime = item.StartTime; var itemStopTime = item.Running ? currentTime : item.StopTime; bool inView = MathUtils.DoesRangeOverlap(itemStartTime, itemStopTime, leftTime, rightTime); if (inView) { //Convert to progress in the view var p1 = Mathf.InverseLerp(leftTime, rightTime, itemStartTime); var p2 = Mathf.InverseLerp(leftTime, rightTime, itemStopTime); Rect itemRect = new Rect(rect.x + p1 * rect.width, rect.y, (p2 - p1) * rect.width, rect.height); GUI.DrawTexture(itemRect, Texture2D.whiteTexture); } } }
private void DrawTrack(Rect rect, Timeline.TrackEntry trackEntry, float currentTime) { //Get the items to draw trackEntry.Track.GetItems(itemCache); //Draw background GUI.color = new Color(.3f, .3f, .3f, 1f); GUI.DrawTexture(rect, Texture2D.whiteTexture); //Draw info float averageDuration = GetAverageDuration(itemCache); GUI.color = Color.white; GUI.Label(rect, "Avg: (ms) " + (averageDuration * 1000f)); if (linesMat != null) { linesMat.SetPass(0); } GL.Begin(GL.LINES); { float lastXProg = -1f; float lastYProg = -1f; for (int i = 0; i < itemCache.Count; i++) { float xProg = i == 0 ? 0 : (float)i / (itemCache.Count - 1); float duration = (itemCache[i].Running ? currentTime : itemCache[i].StopTime) - itemCache[i].StartTime; float yProg = Mathf.InverseLerp(maxDuration, minDuration, duration); if (i != 0) { GL.Vertex(new Vector2(rect.x + rect.width * lastXProg, rect.y + rect.height * lastYProg)); GL.Vertex(new Vector2(rect.x + rect.width * xProg, rect.y + rect.height * yProg)); } lastXProg = xProg; lastYProg = yProg; } } GL.End(); }