Ejemplo n.º 1
0
        public ClipViewInfo(ClipBehaviour clip, ClipBehaviour prev, ClipBehaviour next, Navigator navigator, float tolalFrame, Rect fullRect)
        {
            ContentMin = 0f;
            ContentMax = 0f;
            Min        = 0f;
            Max        = 0f;
            StopMin    = 0f;
            StopMax    = tolalFrame;
            StopMin2   = 0f;
            StopMax2   = tolalFrame;
            HasPrev    = prev != null;
            HasNext    = next != null;

            var value = Calculate(clip, navigator);

            Min        = value.min;
            Max        = value.max;
            ContentMin = Min;
            ContentMax = Max;

            if (prev != null)
            {
                var prevValue = Calculate(prev, navigator);
                if (prevValue.max > ContentMin)
                {
                    ContentMin = prevValue.max;
                }

                StopMin = ClipViewUtility.Adjust(navigator.ToFrame(prevValue.min), fullRect, navigator, 1);

                StopMax2 = ClipViewUtility.Adjust(navigator.ToFrame(prevValue.max), fullRect, navigator, 1);
            }

            if (next != null)
            {
                var nextValue = Calculate(next, navigator);
                if (nextValue.min < ContentMax)
                {
                    ContentMax = nextValue.min;
                }

                StopMax  = ClipViewUtility.Adjust(navigator.ToFrame(nextValue.max), fullRect, navigator, -1);
                StopMin2 = ClipViewUtility.Adjust(navigator.ToFrame(nextValue.min), fullRect, navigator, -1);
            }
        }
        public void Draw(Rect viewRect, ClipViewInfo info, Navigator navigator, float totalFrame, float currentFrame, IReadOnlyList <Blackboard> blackboards)
        {
            if (Asset == null)
            {
                return;
            }
            if (SerializedObject == null)
            {
                return;
            }

            m_BlackboardList = blackboards;

            var beginFrame = BeginFrame;
            var endFrame   = EndFrame;

            var fullRect = new Rect(info.Min, viewRect.y + 2f, info.Max - info.Min, viewRect.height - 4f);

            if (endFrame <= navigator.MinFrame || beginFrame >= navigator.MaxFrame)
            {
                return;
            }

            var edgeRect = Utility.CalculateEdgeRects(fullRect, 8f);

            EditorGUIUtility.AddCursorRect(edgeRect.left, MouseCursor.SplitResizeLeftRight);
            EditorGUIUtility.AddCursorRect(edgeRect.right, MouseCursor.SplitResizeLeftRight);

            var contentRect = new Rect(info.ContentMin + 2f, fullRect.y + 2f, info.ContentMax - info.ContentMin - 4f, fullRect.height - 4f);

            ClipViewUtility.DrawClip(fullRect, info, BackgroundColor);

            SerializedObject.Update();
            DrawContents(contentRect, SerializedObject);
            SerializedObject.ApplyModifiedProperties();

            var dragCtrlId = GUIUtility.GetControlID(FocusType.Passive);
            var e          = Event.current;

            switch (e.type)
            {
            case EventType.MouseDown:
            {
                if (edgeRect.left.Contains(e.mousePosition))
                {
                    m_DragType            = DragType.Min;
                    GUIUtility.hotControl = dragCtrlId;
                    e.Use();
                    break;
                }

                if (edgeRect.right.Contains(e.mousePosition))
                {
                    m_DragType            = DragType.Max;
                    GUIUtility.hotControl = dragCtrlId;
                    e.Use();
                    break;
                }

                if (contentRect.Contains(e.mousePosition) && e.button == 1)
                {
                    ShowContextMenu();
                    e.Use();
                    break;
                }

                if (contentRect.Contains(e.mousePosition))
                {
                    Selection.objects     = new Object[] { Asset };
                    m_DragType            = DragType.Range;
                    GUIUtility.hotControl = dragCtrlId;
                    e.Use();
                }
            }
            break;

            case EventType.MouseDrag:
                if (dragCtrlId == GUIUtility.hotControl)
                {
                    switch (m_DragType)
                    {
                    case DragType.Min:
                    {
                        var next = Utility.Remap(e.mousePosition.x, viewRect.xMin, viewRect.xMax, navigator.MinFrame, navigator.MaxFrame);
                        BeginFrame = ClipViewUtility.Adjust(next, viewRect, navigator);
                        BeginFrame = Mathf.Min(BeginFrame, EndFrame);
                        BeginFrame = Mathf.Max(BeginFrame, info.StopMin);
                    }
                    break;

                    case DragType.Max:
                    {
                        var next = Utility.Remap(e.mousePosition.x, viewRect.xMin, viewRect.xMax, navigator.MinFrame, navigator.MaxFrame);
                        EndFrame = ClipViewUtility.Adjust(next, viewRect, navigator);
                        EndFrame = Mathf.Max(BeginFrame, EndFrame);
                        EndFrame = Mathf.Min(EndFrame, info.StopMax);
                    }
                    break;

                    case DragType.Range:
                    {
                        var delta = Utility.Remap(e.delta.x, 0f, viewRect.width, 0f, navigator.Range);
                        if (0f > delta)
                        {
                            if (0f > BeginFrame + delta)
                            {
                                delta = -BeginFrame;
                            }
                        }
                        else
                        {
                            if (totalFrame < EndFrame + delta)
                            {
                                delta = totalFrame - EndFrame;
                            }
                        }
                        BeginFrame += delta;
                        EndFrame   += delta;

                        BeginFrame = Mathf.Max(BeginFrame, info.StopMin);
                        EndFrame   = Mathf.Min(EndFrame, info.StopMax);

                        if (info.HasPrev)
                        {
                            EndFrame = Mathf.Max(EndFrame, info.StopMax2);
                        }
                        if (info.HasNext)
                        {
                            BeginFrame = Mathf.Min(BeginFrame, info.StopMin2);
                        }
                    }
                    break;
                    }
                    e.Use();
                }
                break;

            case EventType.MouseUp:
            case EventType.Ignore:
                if (dragCtrlId == GUIUtility.hotControl)
                {
                    BeginFrame = ClipViewUtility.Adjust(BeginFrame, viewRect, navigator);
                    EndFrame   = ClipViewUtility.Adjust(EndFrame, viewRect, navigator);

                    m_DragType            = DragType.None;
                    GUIUtility.hotControl = 0;
                    e.Use();
                }
                break;
            }
        }