Esempio n. 1
0
        public void OnGUI()
        {
            LayoutAreas();

            GUI.Box(FloatingArea, "", USEditorUtility.ContentBackground);
            GUI.Box(ScrubArea, "", USEditorUtility.ScrubBarBackground);

            var widthOfContent = ScrubArea.x + (CurrentSequence.Duration / ZoomInfo.meaningOfEveryMarker * ZoomInfo.currentXMarkerDist);

            if (Event.current.type == EventType.ScrollWheel && ScrubArea.Contains(Event.current.mousePosition))
            {
                var zoom = (Event.current.delta.y * USPreferenceWindow.ZoomFactor);
                if (Event.current.control)
                {
                    zoom *= 10.0f;
                }

                ZoomInfo.currentZoom += (zoom * (USPreferenceWindow.ZoomInvert == true ? -1.0f : 1.0f));
                if (ZoomInfo.currentZoom <= 1.0f)
                {
                    ZoomInfo.currentZoom = 1.0f;
                }

                ScrollInfo.currentScroll.x += Event.current.delta.x;
                ScrollInfo.currentScroll.x  = Mathf.Clamp(ScrollInfo.currentScroll.x, 0, widthOfContent);

                Event.current.Use();
                UpdateCachedMarkerInformation();

                var newWidthOfContent = ScrubArea.x + (CurrentSequence.Duration / ZoomInfo.meaningOfEveryMarker * ZoomInfo.currentXMarkerDist);
                var woc              = newWidthOfContent - FloatingWidth;
                var mxFromLeft       = (Event.current.mousePosition.x - FloatingWidth + ScrollInfo.currentScroll.x);
                var ratio            = mxFromLeft / woc;
                var contentWidthDiff = (newWidthOfContent - widthOfContent) * ratio;
                ScrollInfo.currentScroll.x += contentWidthDiff;

                UpdateCachedMarkerInformation();
            }

            using (new Shared.GUIBeginArea(ScrubArea))
            {
                foreach (var cachedMarker in cachedMarkerData)
                {
                    GUI.DrawTexture(cachedMarker.MarkerRenderRect, USEditorUtility.TimelineMarker);
                    if (cachedMarker.MarkerRenderLabel != string.Empty)
                    {
                        GUI.Label(cachedMarker.MarkerRenderLabelRect, cachedMarker.MarkerRenderLabel);
                    }
                }

                // Render our scrub Handle
                var currentScrubPosition = TimeToContentX(CurrentSequence.RunningTime);
                var halfScrubHandleWidth = 5.0f;
                var scrubHandleRect      = new Rect(currentScrubPosition - halfScrubHandleWidth, 0.0f, halfScrubHandleWidth * 2.0f, ScrubArea.height);
                using (new Shared.GUIChangeColor(new Color(1.0f, 0.1f, 0.1f, 0.65f)))
                    GUI.DrawTexture(scrubHandleRect, USEditorUtility.TimelineScrubHead);

                // Render the running time here
                scrubHandleRect.x    += scrubHandleRect.width;
                scrubHandleRect.width = 100.0f;
                GUI.Label(scrubHandleRect, CurrentSequence.RunningTime.ToString("#.####"));

                if (Event.current.type == EventType.MouseDown)
                {
                    ScrubHandleDrag = true;
                }
                if (Event.current.rawType == EventType.MouseUp)
                {
                    ScrubHandleDrag = false;
                }

                if (ScrubHandleDrag && Event.current.isMouse)
                {
                    var mousePosOnTimeline = ContentXToTime(FloatingWidth + Event.current.mousePosition.x);
                    sequenceWindow.SetRunningTime(mousePosOnTimeline);
                    Event.current.Use();
                }
            }

            UpdateGrabHandle();

            var height = USHierarchy.TotalArea.height;

            if (USHierarchy.TotalArea.height < HierarchyArea.height)
            {
                height = HierarchyArea.height;
            }

            ScrollInfo.currentScroll.y = GUI.VerticalScrollbar(VerticalScrollArea, ScrollInfo.currentScroll.y, HierarchyArea.height, 0.0f, height);
            ScrollInfo.currentScroll.x = GUI.HorizontalScrollbar(HorizontalScrollArea, ScrollInfo.currentScroll.x, HierarchyArea.width, 0.0f, widthOfContent);
            ScrollInfo.currentScroll.x = Mathf.Clamp(ScrollInfo.currentScroll.x, 0, widthOfContent);
            ScrollInfo.currentScroll.y = Mathf.Clamp(ScrollInfo.currentScroll.y, 0, USHierarchy.TotalArea.height);

            ContentGUI();

            // Render our red line
            var scrubMarkerRect = new Rect(ScrubArea.x + TimeToContentX(CurrentSequence.RunningTime), HierarchyArea.y, 1.0f, HierarchyArea.height);

            // Don't render an offscreen scrub line.
            if (scrubMarkerRect.x < HierarchyArea.x)
            {
                return;
            }

            using (new Shared.GUIChangeColor(new Color(1.0f, 0.1f, 0.1f, 0.65f)))
                GUI.DrawTexture(scrubMarkerRect, USEditorUtility.TimelineScrubTail);
        }
Esempio n. 2
0
        public void OnGUI()
        {
            LayoutAreas();
            if (CurrentSequence == null)
            {
                return;
            }
            ///标签区域
            GUI.Box(FloatingArea, "", USEditorUtility.ContentBackground);
            //右边标尺区域
            GUI.Box(ScrubArea, "", USEditorUtility.ScrubBarBackground);

            float widthOfContent = ScrubArea.x + (CurrentSequence.Duration / ZoomInfo.meaningOfEveryMarker * ZoomInfo.currentXMarkerDist);

            //鼠标放在标尺上 滚轮缩放
            if (UnityEngine.Event.current.type == EventType.ScrollWheel && ScrubArea.Contains(UnityEngine.Event.current.mousePosition))
            {
                float zoom = (UnityEngine.Event.current.delta.y * ZoomFactor);
                if (UnityEngine.Event.current.control)
                {
                    zoom *= 10.0f;
                }

                ZoomInfo.currentZoom += (zoom * (ZoomInvert == true ? -1.0f : 1.0f));
                if (ZoomInfo.currentZoom <= 1.0f)
                {
                    ZoomInfo.currentZoom = 1.0f;
                }

                ScrollInfo.currentScroll.x += UnityEngine.Event.current.delta.x;
                ScrollInfo.currentScroll.x  = Mathf.Clamp(ScrollInfo.currentScroll.x, 0, widthOfContent);
                UnityEngine.Event.current.Use();

                var newWidthOfContent = ScrubArea.x + (CurrentSequence.Duration / ZoomInfo.meaningOfEveryMarker * ZoomInfo.currentXMarkerDist);
                var woc              = newWidthOfContent - FloatingWidth;
                var mxFromLeft       = (UnityEngine.Event.current.mousePosition.x - FloatingWidth + ScrollInfo.currentScroll.x);
                var ratio            = mxFromLeft / woc;
                var contentWidthDiff = (newWidthOfContent - widthOfContent) * ratio;
                ScrollInfo.currentScroll.x += contentWidthDiff;
                UpdateCachedMarkerInformation();
            }
            //绘制 时间标尺 当前时间刻度
            GUILayout.BeginArea(ScrubArea);
            {
                foreach (var cachedMarker in cachedMarkerData)
                {
                    GUI.DrawTexture(cachedMarker.MarkerRenderRect, USEditorUtility.TimelineMarker);
                    if (cachedMarker.MarkerRenderLabel != string.Empty)
                    {
                        GUI.Label(cachedMarker.MarkerRenderLabelRect, cachedMarker.MarkerRenderLabel);
                    }
                }

                // Render our scrub Handle
                float currentScrubPosition = TimeToContentX(CurrentSequence.RunningTime);

                float halfScrubHandleWidth = 5.0f;
                Rect  scrubHandleRect      = new Rect(currentScrubPosition - halfScrubHandleWidth, 0.0f, halfScrubHandleWidth * 2.0f, ScrubArea.height);
                GUI.color = new Color(1.0f, 0.1f, 0.1f, 0.65f);
                GUI.DrawTexture(scrubHandleRect, USEditorUtility.TimelineScrubHead);
                GUI.color = Color.white;

                // Render the running time here
                scrubHandleRect.x    += scrubHandleRect.width;
                scrubHandleRect.width = 100.0f;
                GUI.Label(scrubHandleRect, CurrentSequence.RunningTime.ToString("#.####"));

                if (UnityEngine.Event.current.type == EventType.MouseDown)
                {
                    ScrubHandleDrag = true;
                }
                if (UnityEngine.Event.current.rawType == EventType.MouseUp)
                {
                    ScrubHandleDrag = false;
                }

                if (ScrubHandleDrag && UnityEngine.Event.current.isMouse)
                {
                    float mousePosOnTimeline = ContentXToTime(FloatingWidth + UnityEngine.Event.current.mousePosition.x);
                    sequenceWindow.SetRunningTime(mousePosOnTimeline);
                    UnityEngine.Event.current.Use();
                }
            }
            GUILayout.EndArea();

            UpdateGrabHandle();

            float height = TotalArea.height;

            if (TotalArea.height < HierarchyArea.height)
            {
                height = HierarchyArea.height;
            }
            float temp = ScrollInfo.currentScroll.x;

            ScrollInfo.currentScroll.y = GUI.VerticalScrollbar(VerticalScrollArea, ScrollInfo.currentScroll.y, HierarchyArea.height, 0.0f, height);
            ScrollInfo.currentScroll.x = GUI.HorizontalScrollbar(HorizontalScrollArea, ScrollInfo.currentScroll.x, FloatingWidth + HierarchyArea.width, 0.0f, widthOfContent);
            ScrollInfo.currentScroll.x = Mathf.Clamp(ScrollInfo.currentScroll.x, 0, widthOfContent);
            ScrollInfo.currentScroll.y = Mathf.Clamp(ScrollInfo.currentScroll.y, 0, TotalArea.height);
            if (temp != ScrollInfo.currentScroll.x)
            {
                UpdateCachedMarkerInformation();
            }
            ContentGUI();

            // Render our red line
            Rect scrubMarkerRect = new Rect(ScrubArea.x + TimeToContentX(CurrentSequence.RunningTime), HierarchyArea.y, 1.0f, HierarchyArea.height);

            // Don't render an offscreen scrub line.
            if (scrubMarkerRect.x < HierarchyArea.x)
            {
                return;
            }
            GUI.color = new Color(1.0f, 0.1f, 0.1f, 0.65f);
            GUI.DrawTexture(scrubMarkerRect, USEditorUtility.TimelineScrubTail);
            GUI.color = Color.white;
        }