A game about forced loneliness, made by TACStudios
at master 81 lines 2.7 kB view raw
1using System; 2using UnityEngine; 3using UnityEngine.Timeline; 4using UnityEngine.Playables; 5 6namespace UnityEditor.Timeline 7{ 8 partial class TimelineWindow 9 { 10 TimeAreaItem m_PlayHead; 11 12 void TimeCursorGUI(TimelineItemArea area) 13 { 14 DrawTimeOnSlider(); 15 if (!CanDrawTimeCursor(area)) 16 return; 17 18 if (m_PlayHead == null || m_PlayHead.style != styles.timeCursor) 19 { 20 m_PlayHead = new TimeAreaItem(styles.timeCursor, OnTrackHeadDrag); 21 m_PlayHead.AddManipulator(new PlayheadContextMenu(m_PlayHead)); 22 } 23 24 var headerMode = area == TimelineItemArea.Header; 25 DrawTimeCursor(headerMode, !headerMode); 26 } 27 28 bool CanDrawTimeCursor(TimelineItemArea area) 29 { 30 if (!currentMode.ShouldShowTimeCursor(state)) 31 return false; 32 33 if (treeView == null || state.editSequence.asset == null || (state.editSequence.asset != null && state.IsEditingAnEmptyTimeline())) 34 return false; 35 36 if (area == TimelineItemArea.Lines && !state.TimeIsInRange((float)state.editSequence.time)) 37 return false; 38 39 return true; 40 } 41 42 void DrawTimeOnSlider() 43 { 44 if (currentMode.ShouldShowTimeCursor(state)) 45 { 46 var colorDimFactor = EditorGUIUtility.isProSkin ? 0.7f : 0.9f; 47 var c = styles.timeCursor.normal.textColor * colorDimFactor; 48 49 float time = Mathf.Max((float)state.editSequence.time, 0); 50 float duration = (float)state.editSequence.duration; 51 52 m_TimeArea.DrawTimeOnSlider(time, c, duration, DirectorStyles.kDurationGuiThickness); 53 } 54 } 55 56 void DrawTimeCursor(bool drawHead, bool drawline) 57 { 58 m_PlayHead.HandleManipulatorsEvents(state); 59 60 if (Event.current.type == EventType.MouseDown && Event.current.button == 0) 61 { 62 if (state.timeAreaRect.Contains(Event.current.mousePosition)) 63 { 64 state.SetPlaying(false); 65 m_PlayHead.HandleManipulatorsEvents(state); 66 state.editSequence.time = Math.Max(0.0, state.GetSnappedTimeAtMousePosition(Event.current.mousePosition)); 67 } 68 } 69 70 m_PlayHead.drawLine = drawline; 71 m_PlayHead.drawHead = drawHead; 72 m_PlayHead.Draw(sequenceContentRect, state, state.editSequence.time); 73 } 74 75 void OnTrackHeadDrag(double newTime) 76 { 77 state.editSequence.time = Math.Max(0.0, newTime); 78 m_PlayHead.showTooltip = true; 79 } 80 } 81}