Пример #1
0
        public bool SnapValid(float position)
        {
            if (m_SnappedTo == null)
            {
                return(false);
            }

            return((TimelineSnappingMouseManipulator.k_SnapTimeComparer.Equals(StartTime, m_SnappedTo.StartTime) ||
                    TimelineSnappingMouseManipulator.k_SnapTimeComparer.Equals(EndTime, m_SnappedTo.EndTime) ||
                    TimelineSnappingMouseManipulator.k_SnapTimeComparer.Equals(StartTime, m_SnappedTo.EndTime) ||
                    TimelineSnappingMouseManipulator.k_SnapTimeComparer.Equals(EndTime, m_SnappedTo.StartTime)) &&
                   Mathf.Abs(position - m_SnappedTo.GetSnapPosition(position)) < TimelineSnappingMouseManipulator.k_SnapMoveDelta);
        }
Пример #2
0
        SnappingElement FindSnapTarget(float dragPosition, MouseDirection direction)
        {
            SnappingElement snapTarget = SnapTo(m_Target, dragPosition);

            if (snapTarget != null)
            {
                float snapPosition = snapTarget.GetSnapPosition(dragPosition);
                if (snapPosition < dragPosition && direction == MouseDirection.Decreasing)
                {
                    return(snapTarget);
                }

                if (snapPosition > dragPosition && direction == MouseDirection.Increasing)
                {
                    return(snapTarget);
                }
            }

            return(null);
        }
Пример #3
0
        protected bool TryToSnap(float dragPosition, MouseDirection direction, float framerate, out float newTime,
                                 bool snapToClipStart = true, bool snapToClipDuration = true, bool snapToPlayhead = true)
        {
            Timeline timeline = m_Target.Timeline;

            if (SnappingEnabled)
            {
                m_Target.UnSnap();
                SnappingElement snapTarget = FindSnapTarget(dragPosition, direction);
                if (snapTarget != null)
                {
                    newTime = timeline.WorldPositionToTime(snapTarget.GetSnapPosition(dragPosition));
                    m_Target.SnapTo(snapTarget);
                    if (timeline.TimelineUnits == TimelineViewMode.frames)
                    {
                        newTime = (float)TimelineUtility.RoundToFrame(newTime, framerate);
                    }

                    timeline.ShowSnap(newTime);

                    return(true);
                }

                float zeroPos  = timeline.TimeToWorldPos(0f);
                float duration = m_Target.Track.Clip.DurationInSeconds;
                float endPos   = timeline.TimeToWorldPos(duration);

                if (snapToClipStart && Mathf.Abs(dragPosition - zeroPos) < k_SnapMoveDelta)
                {
                    timeline.ShowSnap(0f);
                    newTime = 0f;
                    return(true);
                }

                if (snapToClipDuration && Mathf.Abs(dragPosition - endPos) < k_SnapMoveDelta)
                {
                    newTime = duration;
                    timeline.ShowSnap(newTime);
                    return(true);
                }

                float activeTimePos = timeline.TimeToWorldPos(timeline.ActiveTime);
                if (snapToPlayhead && Mathf.Abs(dragPosition - activeTimePos) < k_SnapMoveDelta)
                {
                    newTime = timeline.ActiveTime;
                    timeline.ShowSnap(timeline.ActiveTime);
                    return(true);
                }
            }

            newTime = timeline.WorldPositionToTime(dragPosition);

            if (timeline.TimelineUnits == TimelineViewMode.frames)
            {
                newTime = (float)TimelineUtility.RoundToFrame(newTime, framerate);
            }

            m_Target.UnSnap();
            timeline.HideSnap();

            return(false);
        }