Пример #1
0
        protected virtual void OnBodyContextClick()
        {
            int t = SequenceEditor.GetFrameForX(Event.current.mousePosition.x - _headerWidth);

            GUIContent selectAllEvents = new GUIContent("Select All Events");
            GUIContent addEventAtFrame = new GUIContent("Add Event At Frame");
            GUIContent addEventFillGap = new GUIContent("Add Event Fill Gap");

            GenericMenu menu = new GenericMenu();

            menu.AddItem(selectAllEvents, false, SelectAllEvents);
            if (Track.CanAddAt(t))
            {
                menu.AddItem(addEventAtFrame, false, AddEventAtPoint, t);
                menu.AddItem(addEventFillGap, false, AddEventFillGap, t);
            }
            else
            {
                menu.AddDisabledItem(addEventAtFrame);
                menu.AddDisabledItem(addEventFillGap);
            }

            menu.ShowAsContext();
            Event.current.Use();
        }
//		public override void OnTogglePreview ()
//		{
////			int currentFrame = Track.Sequence.GetCurrentFrame();
//
//			base.OnTogglePreview();
//
////			if( currentFrame >= 0 )
////				SequenceEditor.SetCurrentFrame( currentFrame );
//		}

        public override void Render(Rect rect, float headerWidth)
        {
//			bool isPreviewing = _track.IsPreviewing;

            base.Render(rect, headerWidth);

//			if( isPreviewing != _track.IsPreviewing )
//			{
//				if( Event.current.alt )
//					SyncWithAnimationWindow = true;
//			}

            switch (Event.current.type)
            {
            case EventType.DragUpdated:
                if (rect.Contains(Event.current.mousePosition))
                {
                    int numAnimationsDragged = FAnimationEventInspector.NumAnimationsDragAndDrop(Track.Sequence.FrameRate);
                    int frame = SequenceEditor.GetFrameForX(Event.current.mousePosition.x);

                    DragAndDrop.visualMode = numAnimationsDragged > 0 && Track.CanAddAt(frame) ? DragAndDropVisualMode.Copy : DragAndDropVisualMode.Rejected;
                    Event.current.Use();
                }
                break;

            case EventType.DragPerform:
                if (rect.Contains(Event.current.mousePosition))
                {
                    AnimationClip animClip = FAnimationEventInspector.GetAnimationClipDragAndDrop(Track.Sequence.FrameRate);

                    if (animClip && Mathf.Approximately(animClip.frameRate, Track.Sequence.FrameRate))
                    {
                        int frame = SequenceEditor.GetFrameForX(Event.current.mousePosition.x);
                        int maxLength;

                        if (Track.CanAddAt(frame, out maxLength))
                        {
                            FPlayAnimationEvent animEvt = FEvent.Create <FPlayAnimationEvent>(new FrameRange(frame, frame + Mathf.Min(maxLength, Mathf.RoundToInt(animClip.length * animClip.frameRate))));
                            Track.Add(animEvt);
                            FAnimationEventInspector.SetAnimationClip(animEvt, animClip);
                            DragAndDrop.AcceptDrag();
                        }
                    }

                    Event.current.Use();
                }
                break;
            }

//			if( _wasPreviewing != _track.IsPreviewing )
//			{
//				if( _wasPreviewing )
//					SequenceEditor.OnUpdateEvent.RemoveListener( OnUpdate );
//				else
//					SequenceEditor.OnUpdateEvent.AddListener( OnUpdate );
//
//				_wasPreviewing = _track.IsPreviewing;
//			}
        }
Пример #3
0
        protected virtual void OnBodyContextClick()
        {
            int t = SequenceEditor.GetFrameForX(Event.current.mousePosition.x - HeaderWidth);

            GUIContent selectAllEvents = new GUIContent("选择所有事件");
            GUIContent addEventAtFrame = new GUIContent("在当前帧添加事件");
            GUIContent addEventFillGap = new GUIContent("添加事件填充剩余空隙");

            GUIContent pasteEvent = new GUIContent("粘贴事件");

            GenericMenu menu = new GenericMenu();

            menu.AddItem(selectAllEvents, false, SelectAllEvents);
            if (Track.CanAddAt(t))
            {
                menu.AddItem(addEventAtFrame, false, AddEventAtPoint, t);
                menu.AddItem(addEventFillGap, false, AddEventFillGap, t);
            }
            else
            {
                menu.AddDisabledItem(addEventAtFrame);
                menu.AddDisabledItem(addEventFillGap);
            }

            if (FSequenceEditor.CopyObject != null)
            {
                FEvent copyEvt = FSequenceEditor.CopyObject as FEvent;

                if (copyEvt != null)
                {
                    if (FSequenceEditor.CopyObject.GetType() != Track.GetEventType())
                    {
                        menu.AddDisabledItem(pasteEvent);
                    }
                    else
                    {
                        FEvent eventBefore = Track.GetEventBefore(t);
                        FEvent eventAfter  = Track.GetEventAfter(t);

                        FrameRange validRange = new FrameRange(eventBefore == null ? 0 : eventBefore.End, eventAfter == null ? SequenceEditor.Sequence.Length : eventAfter.Start);

                        if (validRange.Length >= copyEvt.Length)
                        {
                            menu.AddItem(pasteEvent, false, PasteEvent, t);
                        }
                        else
                        {
                            menu.AddDisabledItem(pasteEvent);
                        }
                    }
                }
            }

            menu.ShowAsContext();
            Event.current.Use();
        }
Пример #4
0
        public override void Render(Rect rect, float headerWidth)
        {
            base.Render(rect, headerWidth);

            switch (Event.current.type)
            {
            case EventType.DragUpdated:
                if (rect.Contains(Event.current.mousePosition))
                {
                    int numAnimationsDragged = FAnimationEventInspector.NumAnimationsDragAndDrop(Track.Sequence.FrameRate);
                    int frame = SequenceEditor.GetFrameForX(Event.current.mousePosition.x);

                    DragAndDrop.visualMode = numAnimationsDragged > 0 && Track.CanAddAt(frame) ? DragAndDropVisualMode.Copy : DragAndDropVisualMode.Rejected;
                    Event.current.Use();
                }
                break;

            case EventType.DragPerform:
                if (rect.Contains(Event.current.mousePosition))
                {
                    AnimationClip animClip = FAnimationEventInspector.GetAnimationClipDragAndDrop(Track.Sequence.FrameRate);

                    if (animClip && Mathf.Approximately(animClip.frameRate, Track.Sequence.FrameRate))
                    {
                        int frame = SequenceEditor.GetFrameForX(Event.current.mousePosition.x);
                        int maxLength;

                        if (Track.CanAddAt(frame, out maxLength))
                        {
                            FPlayAnimationEvent animEvt = FEvent.Create <FPlayAnimationEvent>(new FrameRange(frame, frame + Mathf.Min(maxLength, Mathf.RoundToInt(animClip.length * animClip.frameRate))));
                            Track.Add(animEvt);
                            FAnimationEventInspector.SetAnimationClip(animEvt, animClip);
                            DragAndDrop.AcceptDrag();
                        }
                    }

                    Event.current.Use();
                }
                break;
            }
        }
Пример #5
0
        protected virtual void RenderEvent(FrameRange viewRange, FrameRange validKeyframeRange)
        {
            bool leftHandleVisible  = viewRange.Contains(Evt.Start);
            bool rightHandleVisible = viewRange.Contains(Evt.End);

            Rect leftHandleRect  = _eventRect; leftHandleRect.width = 4;
            Rect rightHandleRect = _eventRect; rightHandleRect.xMin = rightHandleRect.xMax - 4;

            if (leftHandleVisible && IsSelected)
            {
                EditorGUIUtility.AddCursorRect(leftHandleRect, MouseCursor.ResizeHorizontal, _leftHandleGuiId);
            }

            if (rightHandleVisible && IsSelected)
            {
                EditorGUIUtility.AddCursorRect(rightHandleRect, MouseCursor.ResizeHorizontal, _rightHandleGuiId);
            }

            switch (Event.current.type)
            {
            case EventType.Repaint:
                if (!viewRange.Overlaps(Evt.FrameRange))
                {
                    break;
                }

                GUIStyle evtStyle = GetEventStyle();

                GUI.backgroundColor = GetColor();

                evtStyle.Draw(_eventRect, _isSelected, _isSelected, false, false);

                string text = Evt.Text;
                if (text != null)
                {
                    var style = GetTextStyle();
                    //style.alignment = TextAnchor.MiddleCenter;
                    GUI.Label(_eventRect, text, style);
                }

                /*
                 * var leftRect = _eventRect;
                 * leftRect.xMax = leftRect.xMin + 16;
                 * GUI.Label(leftRect, Evt.Start.ToString(), GetTextStyle());
                 * var rightRect = _eventRect;
                 * rightRect.xMin = rightRect.xMax - 16;
                 * GUI.Label(rightRect, Evt.End.ToString(), GetTextStyle());
                 */
                break;

            case EventType.MouseDown:
                if (EditorGUIUtility.hotControl == 0 && IsSelected && !Event.current.control && !Event.current.shift)
                {
                    Vector2 mousePos = Event.current.mousePosition;

                    if (Event.current.button == 0)     // left click?
                    {
                        if (rightHandleVisible && rightHandleRect.Contains(mousePos))
                        {
                            EditorGUIUtility.hotControl = _rightHandleGuiId;
                            //						keyframeOnSelect = evt.Start;
                            Event.current.Use();
                        }
                        else if (leftHandleVisible && leftHandleRect.Contains(mousePos))
                        {
                            EditorGUIUtility.hotControl = _leftHandleGuiId;
                            //						keyframeOnSelect = evt.End;
                            Event.current.Use();
                        }
                        else if (_eventRect.Contains(mousePos))
                        {
                            EditorGUIUtility.hotControl = GuiId;
                            _mouseOffsetFrames          = SequenceEditor.GetFrameForX(mousePos.x) - Evt.Start;

                            if (IsSelected)
                            {
                                if (Event.current.control)
                                {
                                    SequenceEditor.Deselect(this);
                                }
                            }
                            else
                            {
                                if (Event.current.shift)
                                {
                                    SequenceEditor.Select(this);
                                }
                                else if (!Event.current.control)
                                {
                                    SequenceEditor.SelectExclusive(this);
                                }
                            }
                            Event.current.Use();
                        }
                    }
                    else if (Event.current.button == 1 && _eventRect.Contains(Event.current.mousePosition))     // right click?
                    {
                        CreateEventContextMenu().ShowAsContext();
                        Event.current.Use();
                    }
                }
                break;

            case EventType.MouseUp:
                if (EditorGUIUtility.hotControl != 0)
                {
                    if (EditorGUIUtility.hotControl == GuiId ||
                        EditorGUIUtility.hotControl == _leftHandleGuiId ||
                        EditorGUIUtility.hotControl == _rightHandleGuiId)
                    {
                        EditorGUIUtility.hotControl = 0;
                        Event.current.Use();
                        SequenceEditor.Repaint();
                        FinishMovingEventEditors();
                    }
                }
                break;

            case EventType.MouseDrag:
                if (EditorGUIUtility.hotControl != 0)
                {
                    if (EditorGUIUtility.hotControl == GuiId)
                    {
                        int t     = SequenceEditor.GetFrameForX(Event.current.mousePosition.x) - _mouseOffsetFrames;
                        int delta = t - Evt.Start;
                        SequenceEditor.MoveEvents(delta);
                        Event.current.Use();
                    }
                    else if (EditorGUIUtility.hotControl == _leftHandleGuiId || EditorGUIUtility.hotControl == _rightHandleGuiId)
                    {
                        int leftLimit  = 0;
                        int rightLimit = 0;

                        bool draggingStart = EditorGUIUtility.hotControl == _leftHandleGuiId;

                        if (draggingStart)
                        {
                            leftLimit  = validKeyframeRange.Start;
                            rightLimit = Evt.End - 1;
                        }
                        else
                        {
                            leftLimit  = Evt.Start + 1;
                            rightLimit = validKeyframeRange.End;
                        }


                        int t = SequenceEditor.GetFrameForX(Event.current.mousePosition.x);

                        t = Mathf.Clamp(t, leftLimit, rightLimit);

                        int delta = t - (draggingStart ? Evt.Start : Evt.End);

                        if (draggingStart)
                        {
                            int newLength = Evt.Length - delta;
                            if (newLength < Evt.GetMinLength())
                            {
                                delta += newLength - Evt.GetMinLength();
                            }
                            if (newLength > Evt.GetMaxLength())
                            {
                                delta += newLength - Evt.GetMaxLength();
                            }
                        }
                        else
                        {
                            int newLength = Evt.Length + delta;
                            if (newLength < Evt.GetMinLength())
                            {
                                delta -= newLength - Evt.GetMinLength();
                            }
                            if (newLength > Evt.GetMaxLength())
                            {
                                delta -= newLength - Evt.GetMaxLength();
                            }
                        }

                        if (delta != 0)
                        {
                            if (draggingStart)
                            {
                                SequenceEditor.ResizeEventsLeft(delta);
                            }
                            else
                            {
                                SequenceEditor.ResizeEventsRight(delta);
                            }
                        }

                        Event.current.Use();
                    }
                }
                break;

            case EventType.Ignore:
                if (EditorGUIUtility.hotControl == GuiId ||
                    EditorGUIUtility.hotControl == _leftHandleGuiId ||
                    EditorGUIUtility.hotControl == _rightHandleGuiId)
                {
                    EditorGUIUtility.hotControl = 0;
                    SequenceEditor.Repaint();
                    FinishMovingEventEditors();
                }
                break;
            }
        }
Пример #6
0
        protected override void RenderEvent(FrameRange viewRange, FrameRange validKeyframeRange)
        {
            int startOffsetHandleId = EditorGUIUtility.GetControlID(FocusType.Passive);

            switch (Event.current.type)
            {
            case EventType.MouseDown:
                if (Event.current.alt && EditorGUIUtility.hotControl == 0 && _eventRect.Contains(Event.current.mousePosition))
                {
                    EditorGUIUtility.hotControl = startOffsetHandleId;
                    _frameMouseDown             = SequenceEditor.GetFrameForX(Event.current.mousePosition.x) - _playAudioEvt.Start;
                    Event.current.Use();
                }
                break;

            case EventType.MouseDrag:
                if (EditorGUIUtility.hotControl == startOffsetHandleId)
                {
                    int mouseCurrentFrame = Mathf.Clamp(SequenceEditor.GetFrameForX(Event.current.mousePosition.x) - _playAudioEvt.Start, 0, _playAudioEvt.Length);

                    int mouseDelta = _frameMouseDown - mouseCurrentFrame;

                    if (mouseDelta != 0)
                    {
                        _frameMouseDown = mouseCurrentFrame;
                        _startOffset.serializedObject.Update();
                        _startOffset.intValue = Mathf.Clamp(_startOffset.intValue + mouseDelta, 0, _playAudioEvt.GetMaxStartOffset());
                        _startOffset.serializedObject.ApplyModifiedProperties();
                    }
                    Event.current.Use();
                }
                break;

            case EventType.MouseUp:
                if (EditorGUIUtility.hotControl == startOffsetHandleId)
                {
                    EditorGUIUtility.hotControl = 0;
                    Event.current.Use();
                }
                break;
            }

            int frameRangeLength = _playAudioEvt.Length;

            base.RenderEvent(viewRange, validKeyframeRange);

            if (frameRangeLength != _playAudioEvt.Length)
            {
                _startOffset.serializedObject.Update();
                _startOffset.intValue = Mathf.Clamp(_startOffset.intValue, 0, _playAudioEvt.GetMaxStartOffset());
                _startOffset.serializedObject.ApplyModifiedProperties();
            }

            if (_currentClip != _playAudioEvt.AudioClip)
            {
                _waveformTexture = FUtility.GetAudioClipTexture(_playAudioEvt.AudioClip, _rect.width, 64);
                _currentClip     = _playAudioEvt.AudioClip;
            }

            if (Event.current.type == EventType.Repaint && _waveformTexture != null)
            {
                float border = 2;

                Rect waveformRect = _eventRect;
                waveformRect.xMin += border;
                waveformRect.xMax -= border;

                FrameRange visibleEvtRange = _playAudioEvt.FrameRange;
                float      startOffset     = _playAudioEvt.StartOffset;
                if (viewRange.Start > visibleEvtRange.Start)
                {
                    startOffset          += viewRange.Start - visibleEvtRange.Start;
                    visibleEvtRange.Start = viewRange.Start;
                }

                if (viewRange.End < visibleEvtRange.End)
                {
                    visibleEvtRange.End = viewRange.End;
                }

                float uvLength = (visibleEvtRange.Length * _playAudioEvt.Sequence.InverseFrameRate) / _playAudioEvt.AudioClip.length;

                Rect  waveformUVRect = new Rect((startOffset / _playAudioEvt.FrameRange.Length) * ((_playAudioEvt.FrameRange.Length * _playAudioEvt.Sequence.InverseFrameRate) / _playAudioEvt.AudioClip.length), 0, uvLength, 1f);
                float uvPerPixel     = uvLength / waveformRect.width;

                float borderUVs = border * uvPerPixel;

                waveformUVRect.xMin += borderUVs;
                waveformUVRect.xMax -= borderUVs;

                if (_currentClip.channels == 1)
                {
                    waveformUVRect.yMin = 0.3f;
                    waveformUVRect.yMax = 0.7f;
                }
                GUI.DrawTextureWithTexCoords(waveformRect, _waveformTexture, waveformUVRect);
            }
        }
        protected override void RenderEvent(FrameRange viewRange, FrameRange validKeyframeRange)
        {
            if (_animEvtSO == null)
            {
                _animEvtSO   = new SerializedObject(AnimEvt);
                _blendLength = _animEvtSO.FindProperty("_blendLength");
                _startOffset = _animEvtSO.FindProperty("_startOffset");
            }

            UpdateEventFromController();

            _animEvtSO.Update();

            FAnimationTrackEditor animTrackEditor = (FAnimationTrackEditor)TrackEditor;

            Rect transitionOffsetRect = _eventRect;

            int startOffsetHandleId = EditorGUIUtility.GetControlID(FocusType.Passive);
            int transitionHandleId  = EditorGUIUtility.GetControlID(FocusType.Passive);

            bool isBlending     = AnimEvt.IsBlending();
            bool isAnimEditable = Flux.FUtility.IsAnimationEditable(AnimEvt._animationClip);

            if (isBlending)
            {
                transitionOffsetRect.xMin  = Rect.xMin + SequenceEditor.GetXForFrame(AnimEvt.Start + AnimEvt._blendLength) - 3;
                transitionOffsetRect.width = 6;
                transitionOffsetRect.yMin  = transitionOffsetRect.yMax - 8;
            }

            switch (Event.current.type)
            {
            case EventType.MouseDown:
                if (EditorGUIUtility.hotControl == 0 && Event.current.alt && !isAnimEditable)
                {
                    if (isBlending && transitionOffsetRect.Contains(Event.current.mousePosition))
                    {
                        EditorGUIUtility.hotControl = transitionHandleId;

                        AnimatorWindowProxy.OpenAnimatorWindowWithAnimatorController((AnimatorController)AnimTrack.AnimatorController);

                        if (Selection.activeObject != _transitionToState)
                        {
                            Selection.activeObject = _transitionToState;
                        }

                        Event.current.Use();
                    }
                    else if (_eventRect.Contains(Event.current.mousePosition))
                    {
                        _mouseDown = SequenceEditor.GetFrameForX(Event.current.mousePosition.x) - AnimEvt.Start;

                        EditorGUIUtility.hotControl = startOffsetHandleId;

                        Event.current.Use();
                    }
                }
                break;

            case EventType.Ignore:
            case EventType.MouseUp:
                if (EditorGUIUtility.hotControl == transitionHandleId ||
                    EditorGUIUtility.hotControl == startOffsetHandleId)
                {
                    EditorGUIUtility.hotControl = 0;
                    Event.current.Use();
                }
                break;

            case EventType.MouseDrag:
                if (EditorGUIUtility.hotControl == transitionHandleId)
                {
                    int mouseDragPos = Mathf.Clamp(SequenceEditor.GetFrameForX(Event.current.mousePosition.x - Rect.x) - AnimEvt.Start, 0, AnimEvt.Length);

                    if (_blendLength.intValue != mouseDragPos)
                    {
                        _blendLength.intValue = mouseDragPos;

                        FPlayAnimationEvent prevAnimEvt = (FPlayAnimationEvent)animTrackEditor.Track.GetEvent(AnimEvt.GetId() - 1);

                        if (_transitionDuration != null)
                        {
                            _transitionDuration.floatValue = (_blendLength.intValue / prevAnimEvt._animationClip.frameRate) / prevAnimEvt._animationClip.length;
                        }

                        Undo.RecordObject(this, "Animation Blending");
                    }
                    Event.current.Use();
                }
                else if (EditorGUIUtility.hotControl == startOffsetHandleId)
                {
                    int mouseDragPos = Mathf.Clamp(SequenceEditor.GetFrameForX(Event.current.mousePosition.x - Rect.x) - AnimEvt.Start, 0, AnimEvt.Length);

                    int delta = _mouseDown - mouseDragPos;

                    _mouseDown = mouseDragPos;

                    _startOffset.intValue = Mathf.Clamp(_startOffset.intValue + delta, 0, AnimEvt._animationClip.isLooping ? AnimEvt.Length : Mathf.RoundToInt(AnimEvt._animationClip.length * AnimEvt._animationClip.frameRate) - AnimEvt.Length);

                    if (_transitionOffset != null)
                    {
                        _transitionOffset.floatValue = (_startOffset.intValue / AnimEvt._animationClip.frameRate) / AnimEvt._animationClip.length;
                    }

                    Undo.RecordObject(this, "Animation Offset");

                    Event.current.Use();
                }
                break;
            }

            _animEvtSO.ApplyModifiedProperties();
            if (_transitionSO != null)
            {
                _transitionSO.ApplyModifiedProperties();
            }


            switch (Event.current.type)
            {
            case EventType.DragUpdated:
                if (_eventRect.Contains(Event.current.mousePosition))
                {
                    int numAnimationsDragged = FAnimationEventInspector.NumAnimationsDragAndDrop(Evt.Sequence.FrameRate);
                    DragAndDrop.visualMode = numAnimationsDragged > 0 ? DragAndDropVisualMode.Link : DragAndDropVisualMode.Rejected;
                    Event.current.Use();
                }
                break;

            case EventType.DragPerform:
                if (_eventRect.Contains(Event.current.mousePosition))
                {
                    AnimationClip animationClipDragged = FAnimationEventInspector.GetAnimationClipDragAndDrop(Evt.Sequence.FrameRate);
                    if (animationClipDragged)
                    {
                        int animFrameLength = Mathf.RoundToInt(animationClipDragged.length * animationClipDragged.frameRate);

                        FAnimationEventInspector.SetAnimationClip(AnimEvt, animationClipDragged);

                        FrameRange maxRange = AnimEvt.GetMaxFrameRange();

                        SequenceEditor.MoveEvent(AnimEvt, new FrameRange(AnimEvt.Start, Mathf.Min(AnimEvt.Start + animFrameLength, maxRange.End)));

                        DragAndDrop.AcceptDrag();
                        Event.current.Use();
                    }
                    else
                    {
                        Event.current.Use();
                    }
                }
                break;
            }

//            FrameRange currentRange = Evt.FrameRange;

            base.RenderEvent(viewRange, validKeyframeRange);

//            if( isAnimEditable && currentRange.Length != Evt.FrameRange.Length )
//            {
//                FAnimationEventInspector.ScaleAnimationClip( AnimEvt._animationClip, Evt.FrameRange );
//            }

            if (Event.current.type == EventType.Repaint)
            {
                if (isBlending && !isAnimEditable && viewRange.Contains(AnimEvt.Start + AnimEvt._blendLength))
                {
                    GUISkin skin = FUtility.GetFluxSkin();

                    GUIStyle transitionOffsetStyle = skin.GetStyle("BlendOffset");

                    Texture2D t = FUtility.GetFluxTexture("EventBlend.png");

                    Rect r = new Rect(_eventRect.xMin, _eventRect.yMin + 1, transitionOffsetRect.center.x - _eventRect.xMin, _eventRect.height - 2);

                    Color guiColor = GUI.color;

                    Color c = new Color(1f, 1f, 1f, 0.3f);
                    c.a      *= guiColor.a;
                    GUI.color = c;

                    GUI.DrawTexture(r, t);

                    if (Event.current.alt)
                    {
                        GUI.color = Color.white;
                    }

                    transitionOffsetStyle.Draw(transitionOffsetRect, false, false, false, false);

                    GUI.color = guiColor;

//					Debug.Log ( transitionOffsetRect );
                }

//				GUI.color = Color.red;

                if (EditorGUIUtility.hotControl == transitionHandleId)
                {
                    Rect transitionOffsetTextRect = transitionOffsetRect;
                    transitionOffsetTextRect.y     -= 16;
                    transitionOffsetTextRect.height = 20;
                    transitionOffsetTextRect.width += 50;
                    GUI.Label(transitionOffsetTextRect, AnimEvt._blendLength.ToString(), EditorStyles.label);
                }

                if (EditorGUIUtility.hotControl == startOffsetHandleId)
                {
                    Rect startOffsetTextRect = _eventRect;
                    GUI.Label(startOffsetTextRect, AnimEvt._startOffset.ToString(), EditorStyles.label);
                }
            }
        }
Пример #8
0
        protected override void RenderEvent(FrameRange viewRange, FrameRange validKeyframeRange)
        {
            int startOffsetHandleId = EditorGUIUtility.GetControlID(FocusType.Passive);

            switch (Event.current.type)
            {
            case EventType.MouseDown:
                if (Event.current.alt && EditorGUIUtility.hotControl == 0 && _eventRect.Contains(Event.current.mousePosition))
                {
                    EditorGUIUtility.hotControl = startOffsetHandleId;
                    _frameMouseDown             = SequenceEditor.GetFrameForX(Event.current.mousePosition.x) - _playAudioEvt.Start;
                    Event.current.Use();
                }
                break;

            case EventType.MouseDrag:
                if (EditorGUIUtility.hotControl == startOffsetHandleId)
                {
                    int mouseCurrentFrame = Mathf.Clamp(SequenceEditor.GetFrameForX(Event.current.mousePosition.x) - _playAudioEvt.Start, 0, _playAudioEvt.Length);

                    int mouseDelta = _frameMouseDown - mouseCurrentFrame;

                    if (mouseDelta != 0)
                    {
                        _frameMouseDown = mouseCurrentFrame;
                        _startOffset.serializedObject.Update();
                        _startOffset.intValue = Mathf.Clamp(_startOffset.intValue + mouseDelta, 0, _playAudioEvt.GetMaxStartOffset());
                        _startOffset.serializedObject.ApplyModifiedProperties();
                    }
                    Event.current.Use();
                }
                break;

            case EventType.MouseUp:
                if (EditorGUIUtility.hotControl == startOffsetHandleId)
                {
                    EditorGUIUtility.hotControl = 0;
                    Event.current.Use();
                }
                break;
            }

            int frameRangeLength = _playAudioEvt.Length;

            base.RenderEvent(viewRange, validKeyframeRange);

            if (frameRangeLength != _playAudioEvt.Length)
            {
                _startOffset.serializedObject.Update();
                _startOffset.intValue = Mathf.Clamp(_startOffset.intValue, 0, _playAudioEvt.GetMaxStartOffset());
                _startOffset.serializedObject.ApplyModifiedProperties();
            }
            if (_currentClip != _playAudioEvt.AudioClip || _clipMinMaxData == null)
            {
                _clipMinMaxData = FUtility.GetAudioMinMaxData(_playAudioEvt.AudioClip);
                _currentClip    = _playAudioEvt.AudioClip;
            }

            //--波形图绘制
            //if (Event.current.type == EventType.Repaint && _clipMinMaxData != null && _currentClip != null)
            //{
            //    float border = 2;

            //    Rect waveformRect = _eventRect;
            //    waveformRect.xMin += border;
            //    waveformRect.xMax -= border;

            //    FrameRange visibleEvtRange = _playAudioEvt.FrameRange;
            //    float startOffset = _playAudioEvt.StartOffset;
            //    if (viewRange.Start > visibleEvtRange.Start)
            //    {
            //        startOffset += viewRange.Start - visibleEvtRange.Start;
            //        visibleEvtRange.Start = viewRange.Start;
            //    }

            //    if (viewRange.End < visibleEvtRange.End)
            //    {
            //        visibleEvtRange.End = viewRange.End;
            //    }

            //    int numChannels = _currentClip.channels;
            //    int numSamples = _clipMinMaxData.Length / (2 * numChannels);

            //    Rect fullWaveformRect = _eventRect;

            //    fullWaveformRect.width = SequenceEditor.PixelsPerFrame * _currentClip.length * SequenceEditor.Sequence.FrameRate;

            //    GUI.BeginClip(waveformRect);

            //    fullWaveformRect.yMin -= 5;
            //    fullWaveformRect.yMax += 15;
            //    fullWaveformRect.x = -startOffset * SequenceEditor.PixelsPerFrame;

            //    AudioCurveRendering.DrawMinMaxFilledCurve(fullWaveformRect, delegate (float x, out Color col, out float minValue, out float maxValue)
            //    {
            //        col = new Color(1f, 0.55f, 0f, 1f);
            //        float p = Mathf.Clamp(x * (numSamples - 2), 0.0f, numSamples - 2);
            //        int i = (int)Mathf.Floor(p);

            //        minValue = 10;
            //        maxValue = -10;

            //        for (int channel = 0; channel != numChannels; ++channel)
            //        {
            //            int offset1 = (i * numChannels + channel) * 2;
            //            int offset2 = offset1 + numChannels * 2;
            //            minValue = Mathf.Min(minValue, _clipMinMaxData[offset1 + 1], _clipMinMaxData[offset2 + 1]);
            //            maxValue = Mathf.Max(maxValue, _clipMinMaxData[offset1 + 0], _clipMinMaxData[offset2 + 0]);
            //            if (minValue > maxValue)
            //            {
            //                float tmp = minValue;
            //                minValue = maxValue;
            //                maxValue = tmp;
            //            }
            //        }
            //    });
            //    GUI.EndClip();
            //}
        }
Пример #9
0
        private void SingleFrameRender(FrameRange viewRange, FrameRange validKeyframeRange)
        {
            Rect rect = _eventRect;

            rect.width = 15;
            rect.x     = SequenceEditor.PixelsPerFrame * Evt.Start;
            FrameRange range = Evt.FrameRange;

            range.Start    = SequenceEditor.GetFrameForX(rect.x);
            range.End      = range.Start + 1 + _mouseOffsetFrames + SequenceEditor.GetFrameForX(rect.width);
            Evt.FrameRange = range;
            switch (Event.current.type)
            {
            case EventType.Repaint:
            {
                if (!viewRange.Overlaps(Evt.FrameRange))
                {
                    break;
                }

                _mouseOffsetFrames = 0;

                GUIStyle evtStyle = _singleFrameStyle;
                GUI.backgroundColor = Color.white;
                Rect renderRect = rect;
                renderRect.x -= 2.5f;
                evtStyle.Draw(renderRect, _isSelected, _isSelected, false, false);

                string text = Evt.Text;
                if (text != null)
                {
                    GUIStyle style = GetTextStyle();
                    Vector2  size  = style.CalcSize(new GUIContent(text));
                    rect.size = size;
                    GUI.Label(rect, text, GetTextStyle());
                }
                break;
            }

            case EventType.MouseDown:
                if (EditorGUIUtility.hotControl == 0 && IsSelected && !Event.current.control && !Event.current.shift)
                {
                    Vector2 mousePos = Event.current.mousePosition;
                    if (Event.current.button == 0)
                    {
                        if (rect.Contains(mousePos))
                        {
                            EditorGUIUtility.hotControl = GuiId;
                            _mouseOffsetFrames          = SequenceEditor.GetFrameForX(mousePos.x) - Evt.Start;

                            if (IsSelected)
                            {
                                if (Event.current.control)
                                {
                                    SequenceEditor.Deselect(this);
                                }
                            }
                            else
                            {
                                if (Event.current.shift)
                                {
                                    SequenceEditor.Select(this);
                                }
                                else if (!Event.current.control)
                                {
                                    SequenceEditor.SelectExclusive(this);
                                }
                            }
                            Event.current.Use();
                        }
                    }
                    else if (Event.current.button == 1 && rect.Contains(Event.current.mousePosition))     // right click?
                    {
                        CreateEventContextMenu().ShowAsContext();
                        Event.current.Use();
                    }
                }
                break;

            case EventType.MouseUp:
                if (EditorGUIUtility.hotControl == GuiId)
                {
                    EditorGUIUtility.hotControl = 0;
                    Event.current.Use();
                    SequenceEditor.Repaint();
                    FinishMovingEventEditors();
                }
                break;

            case EventType.MouseDrag:
                if (EditorGUIUtility.hotControl == GuiId)
                {
                    int t = SequenceEditor.GetFrameForX(Event.current.mousePosition.x) - _mouseOffsetFrames;

                    int delta = t - Evt.Start;
                    if (t < viewRange.Start)
                    {
                        t = viewRange.Start;
                    }
                    else if (t > viewRange.End - 1)
                    {
                        t = viewRange.End - 1;
                    }
                    Evt.SingleFrame = t + 1;

                    SequenceEditor.MoveEvents(delta);
                    Event.current.Use();
                }
                break;

            case EventType.Ignore:
                if (EditorGUIUtility.hotControl == GuiId)
                {
                    EditorGUIUtility.hotControl = 0;
                    SequenceEditor.Repaint();
                    FinishMovingEventEditors();
                }
                break;
            }
        }