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