public static bool CanCrossBlend(this Clip directable, Clip other)
 {
     if (directable == null || other == null)
     {
         return(false);
     }
     if ((directable.canCrossBlend || other.canCrossBlend) && directable.GetType() == other.GetType())
     {
         return(true);
     }
     return(false);
 }
 public static void CopyClip(Clip action)
 {
     copyClip = ReflectionTools.Clone(action) as Clip;
     copyType = action.GetType();
 }
Beispiel #3
0
        public void OnClipGUI(bool useCurEvent = true)
        {
            if (useCurEvent)
            {
                e = Event.current;
            }
            overlapIn = previousClip != null?Mathf.Max(previousClip.endTime - action.startTime, 0) : 0;

            overlapOut = nextClip != null?Mathf.Max(action.endTime - nextClip.startTime, 0) : 0;

            blendInPosX  = (action.blendIn / action.length) * rect.width;
            blendOutPosX = ((action.length - action.blendOut) / action.length) * rect.width;

            pointerTime       = editor.PosToTime(editor.mousePosition.x);
            snapedPointerTime = editor.SnapTime(pointerTime);

            var lengthProp = action.GetType().GetProperty("length", BindingFlags.Instance | BindingFlags.Public);

            isScalable = lengthProp != null && lengthProp.DeclaringType != typeof(Clip) && lengthProp.CanWrite && action.length > 0;

            //...
            var localRect = new Rect(0, 0, rect.width, rect.height);

            if (action.isLocked)
            {
                if (e.isMouse && localRect.Contains(e.mousePosition))
                {
                    e.Use();
                }
            }

            action.ShowClipGUI(localRect);
            if (hasActiveParameters && action.length > 0)
            {
                ShowClipDopesheet(localRect);
            }
            //...


            //BLEND GRAPHICS
            if (action.blendIn > 0)
            {
                Handles.color = Color.black.WithAlpha(0.5f);
                Handles.DrawAAPolyLine(2, new Vector3[] { new Vector2(0, rect.height), new Vector2(blendInPosX, 0) });
                Handles.color = Color.black.WithAlpha(0.3f);
                Handles.DrawAAConvexPolygon(new Vector3[] { new Vector3(0, 0), new Vector3(0, rect.height), new Vector3(blendInPosX, 0) });
            }

            if (action.blendOut > 0 && overlapOut == 0)
            {
                Handles.color = Color.black.WithAlpha(0.5f);
                Handles.DrawAAPolyLine(2, new Vector3[] { new Vector2(blendOutPosX, 0), new Vector2(rect.width, rect.height) });
                Handles.color = Color.black.WithAlpha(0.3f);
                Handles.DrawAAConvexPolygon(new Vector3[] { new Vector3(rect.width, 0), new Vector2(blendOutPosX, 0), new Vector2(rect.width, rect.height) });
            }

            if (overlapIn > 0)
            {
                Handles.color = Color.black;
                Handles.DrawAAPolyLine(2, new Vector3[] { new Vector2(blendInPosX, 0), new Vector2(blendInPosX, rect.height) });
            }

            Handles.color = Color.white;

            //SCALING IN/OUT, DRAG RECTS
            var allowScaleIn = isScalable && rect.width > SCALE_RECT_WIDTH * 2;
            var dragRect     = new Rect((allowScaleIn ? SCALE_RECT_WIDTH : 0), 0, (isScalable ? rect.width - (allowScaleIn ? SCALE_RECT_WIDTH * 2 : SCALE_RECT_WIDTH) : rect.width), rect.height - (hasActiveParameters ? CLIP_DOPESHEET_HEIGHT : 0));

            editor.AddCursorRect(dragRect, MouseCursor.Link);

            var controlRectIn  = new Rect(0, 0, SCALE_RECT_WIDTH, rect.height - (hasActiveParameters ? CLIP_DOPESHEET_HEIGHT : 0));
            var controlRectOut = new Rect(rect.width - SCALE_RECT_WIDTH, 0, SCALE_RECT_WIDTH, rect.height - (hasActiveParameters ? CLIP_DOPESHEET_HEIGHT : 0));

            if (isScalable && action.parent.isActive)
            {
                GUI.color = new Color(0, 1, 1, 0.3f);
                if (overlapOut <= 0)
                {
                    editor.AddCursorRect(controlRectOut, MouseCursor.ResizeHorizontal);
                    if (e.type == EventType.MouseDown && e.button == 0 && !e.control)
                    {
                        if (controlRectOut.Contains(e.mousePosition))
                        {
                            isScalingEnd      = true;
                            preScaleStartTime = action.startTime;
                            preScaleEndTime   = action.endTime;
                            e.Use();
                        }
                    }
                }

                if (overlapIn <= 0 && allowScaleIn)
                {
                    editor.AddCursorRect(controlRectIn, MouseCursor.ResizeHorizontal);
                    if (e.type == EventType.MouseDown && e.button == 0 && !e.control)
                    {
                        if (controlRectIn.Contains(e.mousePosition))
                        {
                            isScalingStart    = true;
                            preScaleStartTime = action.startTime;
                            preScaleEndTime   = action.endTime;
                            e.Use();
                        }
                    }
                }
                GUI.color = Color.white;
            }

            //BLENDING IN/OUT
            if (e.type == EventType.MouseDown && e.button == 0 && e.control)
            {
                var blendInProp    = action.GetType().GetProperty("blendIn", BindingFlags.Instance | BindingFlags.Public);
                var isBlendableIn  = blendInProp != null && blendInProp.DeclaringType != typeof(Clip) && blendInProp.CanWrite;
                var blendOutProp   = action.GetType().GetProperty("blendOut", BindingFlags.Instance | BindingFlags.Public);
                var isBlendableOut = blendOutProp != null && blendOutProp.DeclaringType != typeof(Clip) && blendOutProp.CanWrite;
                if (isBlendableIn && controlRectIn.Contains(e.mousePosition))
                {
                    isControlBlendIn = true;
                    e.Use();
                }
                if (isBlendableOut && controlRectOut.Contains(e.mousePosition))
                {
                    isControlBlendOut = true;
                    e.Use();
                }
            }


            if (isControlBlendIn)
            {
                action.blendIn = Mathf.Clamp(pointerTime - action.startTime, 0, action.length - action.blendOut);
            }

            if (isControlBlendOut)
            {
                action.blendOut = Mathf.Clamp(action.endTime - pointerTime, 0, action.length - action.blendIn);
            }

            if (isScalingStart)
            {
                var prev = previousClip != null ? previousClip.endTime : 0;
                if (Prefs.magnetSnapping && !e.control)
                { //magnet snap
                    if (Mathf.Abs(snapedPointerTime - prev) <= editor.magnetSnapInterval)
                    {
                        snapedPointerTime = prev;
                    }
                }

                if (action.CanCrossBlend(previousClip))
                {
                    prev -= Mathf.Min(action.length / 2, previousClip.length / 2);
                }
                action.startTime = snapedPointerTime;
                action.startTime = Mathf.Clamp(action.startTime, prev, preScaleEndTime);
                action.endTime   = preScaleEndTime;
                editor.pendingGuides.Add(new TimelineWindowBase.GuideLine(action.startTime, Color.white.WithAlpha(0.05f)));
            }

            if (isScalingEnd)
            {
                var next = nextClip != null ? nextClip.startTime : editor.maxTime;
                if (Prefs.magnetSnapping && !e.control)
                { //magnet snap
                    if (Mathf.Abs(snapedPointerTime - next) <= editor.magnetSnapInterval)
                    {
                        snapedPointerTime = next;
                    }
                }

                if (action.CanCrossBlend(nextClip))
                {
                    next += Mathf.Min(action.length / 2, nextClip.length / 2);
                }
                action.endTime = snapedPointerTime;
                action.endTime = Mathf.Clamp(action.endTime, 0, next);
                editor.pendingGuides.Add(new TimelineWindowBase.GuideLine(action.endTime, Color.white.WithAlpha(0.05f)));
            }

            if (e.type == EventType.MouseDrag && e.button == 0 && dragRect.Contains(e.mousePosition))
            {
                editor.anyClipDragging = true;
            }

            if (e.type == EventType.MouseDown)
            {
                if (e.control)
                {
                    if (multiSelection == null)
                    {
                        multiSelection = new List <ClipWrapper>()
                        {
                            this
                        };
                    }
                    if (multiSelection.Contains(this))
                    {
                        multiSelection.Remove(this);
                    }
                    else
                    {
                        multiSelection.Add(this);
                    }
                }
                else
                {
                    CutsceneUtility.selectedObject = action;
                    if (multiSelection != null && !multiSelection.Select(cw => cw.action).Contains(action))
                    {
                        multiSelection = null;
                    }
                }
                if (e.clickCount == 2)
                {
                    editor.OnClipDoubleClick(rect, action);
                }
            }


            if (e.rawType == EventType.ContextClick)
            {
                DoClipContextMenu();
            }

            if (e.rawType == EventType.MouseUp)
            {
                ResetInteraction();
            }

            if (e.button == 0)
            {
                GUI.DragWindow(dragRect);
            }
            var doFrames = Prefs.timeStepMode == Prefs.TimeStepMode.Frames;

            //Draw info text if big enough
            if (rect.width > 40)
            {
                var r = new Rect(0, 0, rect.width, rect.height);
                if (overlapIn > 0)
                {
                    r.xMin = blendInPosX;
                }
                if (overlapOut > 0)
                {
                    r.xMax = blendOutPosX;
                }
                var label = string.Format("<size=10>{0} start:{1}\n{2}</size>",
                                          action.name, doFrames ? action.startFrame : action.startTime, action.externalInfo);
                GUI.color = action.color.grayscale >= 0.6 ? Color.black : Color.white;
                GUI.Label(r, label);
                GUI.color = Color.white;
            }
        }