Ejemplo n.º 1
0
        private void PreviewAnimationEvent(FAnimationEventEditor animEvtEditor, int frame)
        {
            FPlayAnimationEvent animEvt = (FPlayAnimationEvent)animEvtEditor._evt;

            if (animEvt._animationClip == null)
            {
                return;
            }

            bool isEditable = animEvt.IsAnimationEditable();

            // render path
            if (isEditable)
            {
                TransformCurves transformCurves = new TransformCurves(animEvt.Owner, animEvt._animationClip);

                RenderTransformPath(transformCurves, animEvt.LengthTime, 1f / animEvt.Sequence.FrameRate);

                float t = (float)(frame + animEvt._startOffset - animEvt.Start) / animEvt.Sequence.FrameRate;

                if (animEvt.FrameRange.Contains(frame))
                {
//					float t = (float)(frame + animEvt._startOffset - animEvt.Start) / animEvt.Sequence.FrameRate;
                    RenderTransformAnimation(transformCurves, t);
                }

//				AnimationClipCurveData[] allCurves = AnimationUtility.GetAllCurves( animEvt._animationClip, true );
//				foreach( AnimationClipCurveData curve in allCurves )
//				{
//
//				}
            }
            else if (animEvt.FrameRange.Contains(frame))
            {
                float t = (float)(frame + animEvt._startOffset - animEvt.Start) / animEvt.Sequence.FrameRate;

                bool wasInAnimationMode = AnimationMode.InAnimationMode();

                if (!AnimationMode.InAnimationMode())
                {
                    AnimationMode.StartAnimationMode();
                }
                AnimationMode.BeginSampling();
                AnimationMode.SampleAnimationClip(animEvt.Owner.gameObject, animEvt._animationClip, t);
                AnimationMode.EndSampling();

                if (!wasInAnimationMode)
                {
                    AnimationMode.StopAnimationMode();
                }
            }
        }
Ejemplo n.º 2
0
        public static void Resize(FEvent evt, FrameRange newFrameRange)
        {
            if (evt.FrameRange == newFrameRange || newFrameRange.Start > newFrameRange.End)
            {
                return;
            }

            if (newFrameRange.Length < evt.GetMinLength() || newFrameRange.Length > evt.GetMaxLength())
            {
                Debug.LogError(string.Format("Trying to resize an Event to [{0},{1}] (length: {2}) which isn't a valid length, should be between [{3},{4}]", newFrameRange.Start, newFrameRange.End, newFrameRange.Length, evt.GetMinLength(), evt.GetMaxLength()), evt);
                return;
            }

            bool changedLength = evt.Length != newFrameRange.Length;

            if (!evt.GetTrack().CanAdd(evt, newFrameRange))
            {
                return;
            }

            Undo.RecordObject(evt, changedLength ? "Resize Event" : "Move Event");

            evt.Start = newFrameRange.Start;
            evt.End   = newFrameRange.End;

            if (changedLength)
            {
                if (evt is FPlayAnimationEvent)
                {
                    FPlayAnimationEvent animEvt = (FPlayAnimationEvent)evt;

                    if (animEvt.IsAnimationEditable())
                    {
                        FAnimationEventInspector.ScaleAnimationClip(animEvt._animationClip, animEvt.FrameRange);
                    }
                }
                else if (evt is FTimescaleEvent)
                {
                    ResizeAnimationCurve((FTimescaleEvent)evt, newFrameRange);
                }
            }

            EditorUtility.SetDirty(evt);

            if (FSequenceEditorWindow.instance != null)
            {
                FSequenceEditorWindow.instance.Repaint();
            }
        }
Ejemplo n.º 3
0
        void OnSceneGUI(SceneView sceneView)
        {
            if (_track == null)
            {
                return;
            }

            for (int i = 0; i != _eventEditors.Count; ++i)
            {
                FAnimationEventEditor animEvtEditor = (FAnimationEventEditor)_eventEditors[i];
                FPlayAnimationEvent   animEvt       = (FPlayAnimationEvent)_eventEditors[i]._evt;
                if (animEvt._animationClip != null && animEvt.IsAnimationEditable() && _track.IsPreviewing)
                {
                    animEvtEditor.RenderTransformCurves(animEvt.Sequence.FrameRate);
                }
            }
        }
Ejemplo n.º 4
0
        public static void Rescale(FEvent evt, FrameRange newFrameRange)
        {
            if (evt.FrameRange == newFrameRange)
            {
                return;
            }

            Undo.RecordObject(evt, string.Empty);

            evt.Start = newFrameRange.Start;
            evt.End   = newFrameRange.End;

            if (evt is FPlayAnimationEvent)
            {
                FPlayAnimationEvent animEvt = (FPlayAnimationEvent)evt;

                if (animEvt._animationClip != null)
                {
                    if (animEvt.IsAnimationEditable())
                    {
                        animEvt._animationClip.frameRate = animEvt.Sequence.FrameRate;
                        EditorUtility.SetDirty(animEvt._animationClip);
                    }
                    else if (Mathf.RoundToInt(animEvt._animationClip.frameRate) != animEvt.Sequence.FrameRate)
                    {
                        Debug.LogError(string.Format("Removed AnimationClip '{0}' ({1} fps) from Animation Event '{2}'",
                                                     animEvt._animationClip.name,
                                                     animEvt._animationClip.frameRate,
                                                     animEvt.name), animEvt);

                        animEvt._animationClip = null;
                    }
                }
            }

            EditorUtility.SetDirty(evt);
        }
        public override void OnInspectorGUI()
        {
            base.OnInspectorGUI();

            serializedObject.Update();

            if (_animationClip.objectReferenceValue == null)
            {
                EditorGUILayout.HelpBox("There's no Animation Clip", MessageType.Warning);
                Rect helpBoxRect = GUILayoutUtility.GetLastRect();

                float yCenter = helpBoxRect.center.y;

                helpBoxRect.xMax  -= 3;
                helpBoxRect.xMin   = helpBoxRect.xMax - 50;
                helpBoxRect.yMin   = yCenter - 12.5f;
                helpBoxRect.height = 25f;

                if (GUI.Button(helpBoxRect, "Create"))
                {
                    CreateAnimationClip(_animEvent);
                }
            }

            EditorGUI.BeginChangeCheck();
            EditorGUILayout.PropertyField(_animationClip);

            Rect animationClipRect = GUILayoutUtility.GetLastRect();

            if (Event.current.type == EventType.DragUpdated && animationClipRect.Contains(Event.current.mousePosition))
            {
                int numAnimations = NumAnimationsDragAndDrop(_animEvent.Sequence.FrameRate);
                if (numAnimations > 0)
                {
                    DragAndDrop.visualMode = DragAndDropVisualMode.Link;
                }
            }
            else if (Event.current.type == EventType.DragPerform && animationClipRect.Contains(Event.current.mousePosition))
            {
                if (NumAnimationsDragAndDrop(_animEvent.Sequence.FrameRate) > 0)
                {
                    DragAndDrop.AcceptDrag();
                    AnimationClip clip = GetAnimationClipDragAndDrop(_animEvent.Sequence.FrameRate);
                    if (clip != null)
                    {
                        _animationClip.objectReferenceValue = clip;
                    }
                }
            }

            if (EditorGUI.EndChangeCheck())
            {
                AnimationClip clip = (AnimationClip)_animationClip.objectReferenceValue;
                if (clip)
                {
                    if (clip.frameRate != _animEvent.GetTrack().GetTimeline().Sequence.FrameRate)
                    {
                        Debug.LogError(string.Format("Can't add animation, it has a different frame rate from the sequence ({0} vs {1})",
                                                     clip.frameRate, _animEvent.GetTrack().GetTimeline().Sequence.FrameRate));

                        _animationClip.objectReferenceValue = null;
                    }
                    else
                    {
                        SerializedProperty frameRangeEnd = _frameRange.FindPropertyRelative("_end");
                        FrameRange         maxFrameRange = _animEvent.GetMaxFrameRange();
                        frameRangeEnd.intValue = Mathf.Min(_animEvent.FrameRange.Start + Mathf.RoundToInt(clip.length * clip.frameRate), maxFrameRange.End);
                    }
                }
            }

            if (!_animEvent.IsAnimationEditable())
            {
                EditorGUILayout.IntSlider(_startOffset, 0, _animEvent.GetMaxStartOffset());
            }

            serializedObject.ApplyModifiedProperties();
        }
Ejemplo n.º 6
0
        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 = _animEvt.IsAnimationEditable();

            if (isBlending)
            {
                transitionOffsetRect.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;

                        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.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) - _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) - _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)
                    {
//						animTrackEditor.ClearPreview();

                        int animFrameLength = Mathf.RoundToInt(animationClipDragged.length * animationClipDragged.frameRate);

                        FAnimationEventInspector.SetAnimationClip(_animEvt, animationClipDragged);
                        FUtility.Resize(_animEvt, new FrameRange(_animEvt.Start, _animEvt.Start + animFrameLength));

                        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);

                    GUI.color = new Color(1f, 1f, 1f, 0.3f);

                    GUI.DrawTexture(r, t);

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

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

//				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);
                }
            }
        }