Exemplo n.º 1
0
 public void GoToFrame(int frame)
 {
     _window.GetSequenceEditor().SetCurrentFrame(frame);
     if (_window.IsPlaying)
     {
         _window.Pause();
     }
     FUtility.RepaintGameView();
 }
Exemplo n.º 2
0
        public void Pause()
        {
//			Debug.Log ("Pause");
            _sequence.Pause();

            _isPlaying = false;

            FUtility.RepaintGameView();
        }
Exemplo n.º 3
0
        private static void Rescale(FEvent evt, float scaleFactor)
        {
            FrameRange newFrameRange = evt.FrameRange;

            newFrameRange.Start = Mathf.RoundToInt(newFrameRange.Start * scaleFactor);
            newFrameRange.End   = Mathf.RoundToInt(newFrameRange.End * scaleFactor);

            FUtility.Rescale(evt, newFrameRange);
        }
Exemplo n.º 4
0
        public FSequenceWindowToolbar(FSequenceEditorWindow window)
        {
            _window = window;


            _firstFrame    = new GUIContent(FUtility.GetFluxTexture("FirstFrame.png"), "First Frame");
            _previousFrame = new GUIContent(FUtility.GetFluxTexture("PreviousFrame.png"), "Previous Frame");
            _nextFrame     = new GUIContent(FUtility.GetFluxTexture("NextFrame.png"), "Next Frame");
            _lastFrame     = new GUIContent(FUtility.GetFluxTexture("LastFrame.png"), "Last Frame");

            _playForward = new GUIContent(FUtility.GetFluxTexture("Play.png"), "Play");
            _pause       = new GUIContent(FUtility.GetFluxTexture("Pause.png"), "Pause");
            _stop        = new GUIContent(FUtility.GetFluxTexture("Stop.png"), "Stop");

            _viewRangeLabel = new GUIContent("View Range");
            _viewRangeDash  = new GUIContent(" - ");
        }
Exemplo n.º 5
0
        public void ResizeEventsLeft(int delta)
        {
            int howMuchCanResize = int.MaxValue;

            // making them bigger?
            if (delta < 0)
            {
                for (int i = 0; i != _selectedEvents.Count; ++i)
                {
                    int evtId = _selectedEvents[i].GetRuntimeObject().GetId();
                    int howMuchCanEvtResize = _selectedEvents[i]._evt.Start;
                    if (evtId > 0)
                    {
                        howMuchCanEvtResize -= _selectedEvents[i]._evt.GetTrack().GetEvent(evtId - 1).End;
                    }

                    if (howMuchCanResize > howMuchCanEvtResize)
                    {
                        howMuchCanResize = howMuchCanEvtResize;
                    }
                }

                delta = Mathf.Clamp(delta, -howMuchCanResize, 0);
            }
            else             // making them smaller
            {
                for (int i = 0; i != _selectedEvents.Count; ++i)
                {
                    int howMuchCanEvtResize = _selectedEvents[i]._evt.Length - _selectedEvents[i]._evt.GetMinLength();
                    if (howMuchCanResize > howMuchCanEvtResize)
                    {
                        howMuchCanResize = howMuchCanEvtResize;
                    }
                }

                delta = Mathf.Clamp(delta, 0, howMuchCanResize);
            }

            for (int i = 0; i != _selectedEvents.Count; ++i)
            {
                FrameRange evtRange = _selectedEvents[i]._evt.FrameRange;
                evtRange.Start += delta;
                FUtility.Resize(_selectedEvents[i]._evt, evtRange);
            }
        }
Exemplo n.º 6
0
        public void Stop()
        {
            if (!object.Equals(_sequence, null))
            {
                if (!_sequence.IsStopped)
                {
                    _sequence.Stop(true);

                    for (int i = 0; i != _timelineEditors.Count; ++i)
                    {
                        _timelineEditors[i].OnStop();
                    }
                }
            }
            _isPlaying = false;

            FUtility.RepaintGameView();
        }
Exemplo n.º 7
0
        void OnEnable()
        {
            instance       = this;
            wantsMouseMove = true;

            minSize = new Vector2(450, 300);

            _windowHeader = new FSequenceWindowHeader(this);

            _toolbar = new FSequenceWindowToolbar(this);

            _windowRect = new Rect();

            FUtility.LoadPreferences();

            EditorApplication.playmodeStateChanged   += OnPlayModeChanged;
            EditorApplication.hierarchyWindowChanged += Refresh;
        }
Exemplo n.º 8
0
        public void SetCurrentFrame(int frame)
        {
            if (!_sequence.IsInit)
            {
                _sequence.Init();
            }

            _sequence.SetCurrentFrameEditor(frame);

            frame = _sequence.GetCurrentFrame();
            float time = frame * _sequence.InverseFrameRate;

            for (int i = 0; i != _timelineEditors.Count; ++i)
            {
                _timelineEditors[i].UpdateTracks(frame, time);
            }

            FUtility.RepaintGameView();
        }
Exemplo n.º 9
0
        public void Play(bool restart)
        {
            if (!_sequence.IsStopped && restart)
            {
                _sequence.Stop();
            }



            int frame = _viewRange.Cull(_sequence.GetCurrentFrame());

            _sequence.Play(frame);

            _timeStartedPlaying = EditorApplication.timeSinceStartup - (frame - _viewRange.Start) * _sequence.InverseFrameRate;

            SetCurrentFrame(frame);

            _isPlaying = true;

            FUtility.RepaintGameView();
        }
Exemplo n.º 10
0
        public void OnGUI()
        {
            FSequence sequence = _sequenceWindow.GetSequenceEditor().GetSequence();

            if (_selectedSequenceIndex < 0 && sequence != null)
            {
                for (int i = 0; i != _sequences.Length; ++i)
                {
                    if (_sequences[i] == sequence)
                    {
                        _selectedSequenceIndex = i;
                        break;
                    }
                }
            }


            GUI.contentColor = FGUI.GetTextColor();

            if (Event.current.type == EventType.MouseDown && Event.current.alt && _sequencePopupRect.Contains(Event.current.mousePosition))
            {
                Selection.activeObject = sequence;
                Event.current.Use();
            }

            EditorGUI.BeginChangeCheck();
            EditorGUI.PrefixLabel(_sequenceLabelRect, _sequenceLabel);
            int newSequenceIndex = EditorGUI.Popup(_sequencePopupRect, _selectedSequenceIndex, _sequenceNames);

            if (EditorGUI.EndChangeCheck())
            {
                _selectedSequenceIndex = newSequenceIndex;
                _sequenceWindow.GetSequenceEditor().OpenSequence(_sequences[_selectedSequenceIndex]);
                _sequenceWindow.RemoveNotification();
                EditorGUIUtility.keyboardControl = 0;                 // deselect it
                EditorGUIUtility.ExitGUI();
            }

            if (GUI.Button(_sequenceAddButtonRect, new GUIContent((Texture2D)AssetDatabase.LoadAssetAtPath(FUtility.GetFluxSkinPath() + "Plus.png", typeof(Texture2D)), "Create New Sequence.."), EditorStyles.label))
            {
                FSequence newSequence = FSequenceEditorWindow.CreateSequence();
                _sequenceWindow.GetSequenceEditor().OpenSequence(newSequence);
                EditorGUIUtility.ExitGUI();
            }

            if (sequence == null)
            {
                return;
            }

            if (_sequenceSO == null || _sequenceSO.targetObject != sequence)
            {
                _sequenceSO         = new SerializedObject(sequence);
                _sequenceUpdateMode = _sequenceSO.FindProperty("_updateMode");
                _sequenceLength     = _sequenceSO.FindProperty("_length");
            }

            _sequenceSO.Update();

            if (_showUpdadeMode)
            {
                EditorGUI.PrefixLabel(_updateModeLabelRect, _updateModeLabel);
                EditorGUI.PropertyField(_updateModeFieldRect, _sequenceUpdateMode, GUIContent.none);
            }

            if (_showFramerate)
            {
                EditorGUI.PrefixLabel(_framerateLabelRect, _framerateLabel);
                EditorGUI.BeginChangeCheck();
                int newFrameRate = FGUI.FrameRatePopup(_framerateFieldRect, sequence.FrameRate);
                if (EditorGUI.EndChangeCheck())
                {
                    if (newFrameRate == -1)
                    {
                        FChangeFrameRateWindow.Show(new Vector2(_framerateLabelRect.xMin, _framerateLabelRect.yMax), sequence, FSequenceInspector.Rescale);
                    }
                    else
                    {
                        FSequenceInspector.Rescale(sequence, newFrameRate, true);
                    }
                }
            }

            if (_showLength)
            {
                EditorGUI.PrefixLabel(_lengthLabelRect, _lengthLabel);
                _sequenceLength.intValue = EditorGUI.IntField(_lengthFieldRect, _sequenceLength.intValue, _numberFieldStyle);
            }

            _sequenceSO.ApplyModifiedProperties();
        }
Exemplo n.º 11
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);
            }
        }
Exemplo n.º 12
0
        public static int TimeScrubber(Rect rect, int t, int frameRate, FrameRange range)
        {
            //		Rect actualRect = rect;
            //		actualRect.xMax -= 20; // buffer on the right

            Rect clickRect = rect;

            clickRect.yMin = clickRect.yMax - TIMELINE_SCRUBBER_HEIGHT;

            int length = range.Length;

            int controlId = EditorGUIUtility.GetControlID(FocusType.Passive);

            switch (Event.current.type)
            {
            case EventType.Repaint:
                int frames = range.Start;

                float width = rect.width;

                int maxFramesBetweenSteps = Mathf.Max(1, Mathf.FloorToInt(width / MIN_PIXELS_BETWEEN_FRAMES));

                int numFramesPerStep = Mathf.Max(1, length / maxFramesBetweenSteps);

                // multiple of 60 fps?
                if (numFramesPerStep < 30)
                {
                    if (numFramesPerStep <= 12)
                    {
                        if (numFramesPerStep != 5)
                        {
                            if (12 % numFramesPerStep != 0)
                            {
                                numFramesPerStep = 12;
                            }
                        }
                    }
                    else
                    {
                        numFramesPerStep = 30;
                    }
                }
                else if (numFramesPerStep < 60)
                {
                    numFramesPerStep = 60;
                }
                else
                {
                    int multiplesOf60 = numFramesPerStep / 60;
                    numFramesPerStep = (multiplesOf60 + 1) * 60;
                }

                int numFramesIter = numFramesPerStep < 30 ? 1 : numFramesPerStep / 10;

                Vector3 pt = new Vector3(rect.x, rect.yMax - TIMELINE_SCRUBBER_TEXT_HEIGHT, 0);

                Rect backgroundRect = clickRect;
                backgroundRect.xMin  = 0;
                backgroundRect.xMax += FSequenceEditor.RIGHT_BORDER;

//				GUI.color = new Color( 0.15f, 0.15f, 0.15f, 1f );//FGUI.GetTimelineColor();
//				GUI.DrawTexture( backgroundRect, EditorGUIUtility.whiteTexture );
//				GUI.color = Color.white;
                GUI.color = GetTextColor();                 // a little darker than it is originally to stand out
                GUI.Label(backgroundRect, GUIContent.none, FGUI.GetTimeScrubberStyle());

                Handles.color = GetLineColor();

                //			int framesBetweenSteps = maxFramesBetweenSteps / (maxFramesBetweenSteps * 10 / MIN_PIXELS_BETWEEN_FRAMES);
                //			float pixelsBetweenSteps = minPixelsBetweenSteps / framesBetweenSteps;
                //
                //			Debug.Log ( maxFramesBetweenSteps + " " + minPixelsBetweenSteps + " vs " + framesBetweenSteps + " " + pixelsBetweenSteps );

                GUIStyle labelStyle = new GUIStyle(EditorStyles.boldLabel);
                labelStyle.normal.textColor = Color.white;
                labelStyle.alignment        = TextAnchor.UpperCenter;

                GUI.contentColor = FGUI.GetLineColor();

                frames = (frames / numFramesIter) * numFramesIter;
                while (frames <= range.End)
                {
                    pt.x = rect.x + (width * ((float)(frames - range.Start) / length));

                    if (pt.x >= rect.x)
                    {
                        if (frames % numFramesPerStep == 0)
                        {
                            Handles.DrawLine(pt, pt - new Vector3(0, rect.height - TIMELINE_SCRUBBER_TEXT_HEIGHT, 0));

                            GUI.Label(new Rect(pt.x - 30, pt.y, 60, TIMELINE_SCRUBBER_TEXT_HEIGHT), FUtility.GetTime(frames, frameRate), labelStyle);
                        }
                        else
                        {
                            Vector3 smallTickPt = pt;
                            smallTickPt.y -= TIMELINE_SCRUBBER_TICK_HEIGHT;
                            Handles.DrawLine(smallTickPt, smallTickPt - new Vector3(0, TIMELINE_SCRUBBER_TICK_HEIGHT, 0));
                        }
                    }

                    frames += numFramesIter;
                }

                if (t >= 0 && range.Contains(t))
                {
                    Vector3 tStart = new Vector3(rect.x + (width * ((float)(t - range.Start) / length)), rect.yMin, 0);
                    Vector3 tEnd   = tStart;
                    tEnd.y = rect.yMax - TIMELINE_SCRUBBER_TEXT_HEIGHT;

                    Handles.color = Color.red;
                    Handles.DrawLine(tStart, tEnd);

                    GUI.contentColor = Color.red;
                    GUI.Label(new Rect(tEnd.x - 30, tEnd.y, 60, TIMELINE_SCRUBBER_TEXT_HEIGHT), FUtility.GetTime(t, frameRate), labelStyle);
                    GUI.contentColor = FGUI.GetTextColor();
                }

                GUI.color        = Color.white;
                GUI.contentColor = Color.white;

                Handles.color = GetLineColor();

                Handles.DrawLine(new Vector3(rect.x, rect.yMin, 0), new Vector3(rect.x, rect.yMax - TIMELINE_SCRUBBER_HEIGHT, 0));

                break;

            case EventType.MouseDown:
                if (EditorGUIUtility.hotControl == 0 && clickRect.Contains(Event.current.mousePosition))
                {
                    EditorGUIUtility.hotControl = controlId;
                }
                goto case EventType.MouseDrag;

            case EventType.MouseDrag:
                if (EditorGUIUtility.hotControl == controlId)
                {
                    Rect touchRect = rect;
                    touchRect.yMin = touchRect.yMax - TIMELINE_SCRUBBER_HEIGHT;
                    //			if( touchRect.Contains( Event.current.mousePosition ) )
                    {
                        //				Debug.Log( (Event.current.mousePosition.x - touchRect.xMin /
                        t = Mathf.Clamp(range.Start + Mathf.RoundToInt(((Event.current.mousePosition.x - touchRect.xMin) / touchRect.width) * range.Length), range.Start, range.End);
                        Event.current.Use();
                    }
                }
                break;

            case EventType.MouseUp:
                if (EditorGUIUtility.hotControl == controlId)
                {
                    EditorGUIUtility.hotControl = 0;
                    Event.current.Use();
                }
                break;
            }
            rect.height = TIMELINE_SCRUBBER_HEIGHT;

            return(t);
        }
Exemplo n.º 13
0
        public override void OnInspectorGUI()
        {
            //		EditorGUILayout.PropertyField( _script );

            if (_allEventsSameType)
            {
                serializedObject.Update();
                EditorGUILayout.PropertyField(_triggerOnSkip);
            }
            else
            {
                bool triggerOnSkipMatch = true;

                for (int i = 0; i != targets.Length; ++i)
                {
                    if (((FEvent)targets[i]).TriggerOnSkip != _evt.TriggerOnSkip)
                    {
                        triggerOnSkipMatch = false;
                        break;
                    }
                }

                EditorGUI.BeginChangeCheck();
                bool triggerOnSkip = EditorGUILayout.Toggle("Trigger On Skip", _evt.TriggerOnSkip, triggerOnSkipMatch ? EditorStyles.toggle : "ToggleMixed");
                if (EditorGUI.EndChangeCheck())
                {
                    Undo.RecordObjects(targets, " Inspector");
                    for (int i = 0; i != targets.Length; ++i)
                    {
                        FEvent evt = (FEvent)targets[i];
                        evt.TriggerOnSkip = triggerOnSkip;
                    }
                }
            }

            //        EditorGUILayout.IntField( "Instance ID", _evt.GetInstanceID() );

            float startFrame = _evt.Start;
            float endFrame   = _evt.End;

            FrameRange validRange = _evt.GetTrack().GetValidRange(_evt);

            EditorGUI.BeginChangeCheck();

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.PrefixLabel("Range");
            GUILayout.Label("S:", EditorStyles.label);
            GUI.SetNextControlName(FRAMERANGE_START_FIELD_ID);
            startFrame = EditorGUILayout.IntField(_evt.Start);
            GUILayout.Label("E:", EditorStyles.label);
            endFrame = EditorGUILayout.IntField(_evt.End);
            EditorGUILayout.EndHorizontal();

            if (EditorGUI.EndChangeCheck())
            {
                bool changedStart = GUI.GetNameOfFocusedControl() == FRAMERANGE_START_FIELD_ID;

                for (int i = 0; i != targets.Length; ++i)
                {
                    FEvent evt = (FEvent)targets[i];

                    FrameRange newFrameRange = evt.FrameRange;
                    if (changedStart)
                    {
                        if (startFrame <= newFrameRange.End)
                        {
                            newFrameRange.Start = (int)startFrame;
                        }
                    }
                    else if (endFrame >= newFrameRange.Start)
                    {
                        newFrameRange.End = (int)endFrame;
                    }

                    if (newFrameRange.Length >= evt.GetMinLength() && newFrameRange.Length <= evt.GetMaxLength())
                    {
                        FUtility.Resize(evt, newFrameRange);
                    }
                }
            }

            if (targets.Length == 1)
            {
                EditorGUI.BeginChangeCheck();
                EditorGUILayout.BeginHorizontal();
                GUILayout.Space(EditorGUIUtility.labelWidth);
                float sliderStartFrame = startFrame;
                float sliderEndFrame   = endFrame;
                EditorGUILayout.MinMaxSlider(ref sliderStartFrame, ref sliderEndFrame, validRange.Start, validRange.End);
                EditorGUILayout.EndHorizontal();
                if (EditorGUI.EndChangeCheck())
                {
                    FrameRange newFrameRange = new FrameRange((int)sliderStartFrame, (int)sliderEndFrame);
                    if (newFrameRange.Length < _evt.GetMinLength())
                    {
                        if (sliderStartFrame != startFrame)                          // changed start
                        {
                            newFrameRange.Start = newFrameRange.End - _evt.GetMinLength();
                        }
                        else
                        {
                            newFrameRange.Length = _evt.GetMinLength();
                        }
                    }

                    FUtility.Resize(_evt, newFrameRange);
                }
            }


            if (_allEventsSameType)
            {
                serializedObject.ApplyModifiedProperties();
                base.OnInspectorGUI();
            }
        }
Exemplo n.º 14
0
        public void OnGUI()
        {
            if (_timelineEditors == null)
            {
                return;
            }

            if (_timelineEditors.Count == 0)
            {
                if (_renderingOnEditorWindow)
                {
                    _renderingOnEditorWindow.ShowNotification(new GUIContent("Drag GameObjects Here"));
                }
            }

            _pixelsPerFrame = (_sequenceRect.width - _timelineHeaderWidth) / _viewRange.Length;

            if (_timelineEditorIds.Length != _timelineEditors.Count)
            {
                _timelineEditorIds     = new int[_timelineEditors.Count];
                _timelineEditorHeights = new float[_timelineEditors.Count];
            }

            int timelineHeaderResizerId = EditorGUIUtility.GetControlID(FocusType.Passive);

            float sequenceViewHeight = 0;

            for (int i = 0; i != _timelineEditors.Count; ++i)
            {
                _timelineEditorIds[i]     = EditorGUIUtility.GetControlID(FocusType.Passive);
                _timelineEditorHeights[i] = _timelineEditors[i].GetHeight();
                sequenceViewHeight       += _timelineEditorHeights[i];

                _timelineEditors[i].ReserveTrackGuiIds();
            }

            _scrollPos.y = GUI.VerticalScrollbar(_verticalScrollerRect, _scrollPos.y, Mathf.Min(_sequenceRect.height, sequenceViewHeight), 0, sequenceViewHeight);

            Rect scrolledViewRect = _viewRect;

//			scrolledViewRect.yMin -= _scrollPos.y;

            GUI.BeginGroup(scrolledViewRect);

            Rect timelineRect = _sequenceRect;

            timelineRect.y      = -_scrollPos.y;
            timelineRect.height = 0;

            Rect timelineDraggedRect = new Rect();

//			Debug.Log( "sequence: " + _sequenceRect + " scrubber: " + _timeScrubberRect + " width: " + _timelineHeaderWidth );

            Handles.color = FGUI.GetLineColor();

            for (int i = 0; i != _timelineEditors.Count; ++i)
            {
                timelineRect.yMin   = timelineRect.yMax;
                timelineRect.height = _timelineEditors[i].GetHeight();

                if (_timelineDragged != null)
                {
                    if (_timelineDragged == _timelineEditors[i])
                    {
                        timelineDraggedRect = timelineRect;
                        continue;
                    }
                    else if (EditorGUIUtility.hotControl == _timelineEditorIds[_timelineDragged.GetRuntimeObject().GetId()])
                    {
                        if (i < _timelineDragged.GetRuntimeObject().GetId() && Event.current.mousePosition.y < timelineRect.yMax)
                        {
                            _timelineEditors[i].SetOffset(new Vector2(0, _timelineDragged.GetHeight()));
                        }
                        else if (i > _timelineDragged.GetRuntimeObject().GetId() && Event.current.mousePosition.y > timelineRect.yMin)
                        {
                            _timelineEditors[i].SetOffset(new Vector2(0, -_timelineDragged.GetHeight()));
                        }
                        else
                        {
                            _timelineEditors[i].SetOffset(Vector2.zero);
                        }
                    }
                }

                _timelineEditors[i].Render(_timelineEditorIds[i], timelineRect, _timelineHeaderWidth, _viewRange, _pixelsPerFrame);
            }

            if (_timelineDragged != null)
            {
                if (EditorGUIUtility.hotControl == _timelineEditorIds[_timelineDragged.GetRuntimeObject().GetId()])
                {
                    timelineDraggedRect.y = Event.current.mousePosition.y;
                }
//				timelineRect.yMin = Event.current.mousePosition.y;
//				timelineRect.height = _timelineDragged.GetHeight();
                _timelineDragged.Render(_timelineEditorIds[_timelineDragged.GetRuntimeObject().GetId()], timelineDraggedRect, _timelineHeaderWidth, _viewRange, _pixelsPerFrame);
            }

            switch (Event.current.type)
            {
            case EventType.MouseDown:

//				bool middleClick = Event.current.button == 2 || (Event.current.button == 0 && Event.current.alt);
//
//				if( middleClick ) // middle button
                if (Event.current.button == 0)
                {
                    StartDragSelecting(Event.current.mousePosition);
                    Event.current.Use();
                }
                break;

            case EventType.MouseUp:
                if (_isDragSelecting)
                {
                    StopDragSelecting(Event.current.mousePosition);
                    Event.current.Use();
                }
                break;

            case EventType.Ignore:
                if (_isDragSelecting)
                {
                    StopDragSelecting(Event.current.mousePosition);
                }
                break;

            case EventType.Repaint:
                if (_isDragSelecting)
                {
                    OnDragSelecting(Event.current.mousePosition);
                }

                break;
            }

            GUI.EndGroup();

            if (_viewRange.End > _sequence.Length)
            {
                _viewRange.Start = 0;
                _viewRange.End   = _sequence.Length;
            }

            int newT = FGUI.TimeScrubber(_timeScrubberRect, _sequence.GetCurrentFrame(), _sequence.FrameRate, _viewRange);

            if (newT != _sequence.GetCurrentFrame())
            {
//				_sequence.SetCurrentFrameEditor( newT );
                SetCurrentFrame(newT);

                if (Application.isPlaying)
                {
                    Play(false);
                    Pause();
                }
//				Repaint();
//				SceneView.RepaintAll();
//				UnityEditorInternal.InternalEditorUtility.RepaintAllViews();
//				FUtility.RepaintGameView();
            }

            _viewRange = FGUI.ViewRangeBar(_viewRangeRect, _viewRange, _sequence.Length);

            if (_timelineHeaderResizerRect.Contains(Event.current.mousePosition))
            {
                EditorGUIUtility.AddCursorRect(_timelineHeaderResizerRect, MouseCursor.ResizeHorizontal);
            }

            switch (Event.current.type)
            {
            case EventType.MouseDown:

                bool leftClick = Event.current.button == 0 && !Event.current.alt;
//				bool middleClick = Event.current.button == 2 || (Event.current.button == 0 && Event.current.alt);

                if (leftClick)                  // left button
                {
                    if (EditorGUIUtility.hotControl == 0 && _timelineHeaderResizerRect.Contains(Event.current.mousePosition))
                    {
                        EditorGUIUtility.hotControl = timelineHeaderResizerId;
                        Event.current.Use();
                    }
                    else if (_rect.Contains(Event.current.mousePosition))
                    {
                        DeselectAll();
                        Event.current.Use();
                    }
                }
//				else if( middleClick ) // middle button
//				{
//					StartDragSelecting( Event.current.mousePosition );
//					Event.current.Use();
//				}
                break;

            case EventType.MouseDrag:
                if (EditorGUIUtility.hotControl == timelineHeaderResizerId)
                {
                    _timelineHeaderWidth = (int)Mathf.Max(MINIMUM_HEADER_WIDTH, _timelineHeaderWidth + Event.current.delta.x);

                    RebuildLayout(_rect);
                    EditorWindow.GetWindow <FSequenceEditorWindow>().Repaint();
                    Event.current.Use();
                }

                if (_isDragSelecting)
                {
                    Repaint();
                }

                break;

            case EventType.MouseUp:
                if (EditorGUIUtility.hotControl == timelineHeaderResizerId)
                {
                    EditorGUIUtility.hotControl = 0;
                    Event.current.Use();
                }
//				if( _isDragSelecting )
//				{
//					StopDragSelecting( Event.current.mousePosition );
//					Event.current.Use();
//				}
                break;

            case EventType.Repaint:
                Rect dragArea = _timelineHeaderResizerRect;
                dragArea.xMax -= 10;
                dragArea.xMin  = dragArea.xMax - 16;
                GUIStyle dragStyle = FUtility.GetFluxSkin().GetStyle("HorizontalPanelSeparatorHandle");
                dragStyle.Draw(dragArea, GUIContent.none, 0);
//				GUI.DrawTexture( dragArea, EditorGUIUtility.whiteTexture );
                Handles.color = FGUI.GetLineColor();                // new Color(0.8f, 0.8f, 0.8f, 0.2f);
                Handles.DrawLine(new Vector3(_viewRect.xMin - 16, _sequenceRect.yMax, 0), new Vector3(_viewRect.xMax - RIGHT_BORDER, _sequenceRect.yMax, 0));
//				Handles.color = Color.black;
                break;

            case EventType.ScrollWheel:
                if (_viewRect.Contains(Event.current.mousePosition))
                {
                    _scrollPos.y += Event.current.delta.y * SCROLL_WHEEL_SPEED;
                    Event.current.Use();
                }
                break;
            }

#if FLUX_TRIAL
            GUIStyle watermarkLabel = new GUIStyle(GUI.skin.label);
            watermarkLabel.fontSize = 24;
            GUIContent watermark     = new GUIContent("..::FLUX TRIAL::..");
            Vector2    watermarkSize = watermarkLabel.CalcSize(watermark);
            Rect       watermarkRect = new Rect(_rect.width * 0.5f - watermarkSize.x * 0.5f, _rect.height * 0.5f - watermarkSize.y * 0.5f, watermarkSize.x, watermarkSize.y);

            GUI.color = new Color(1f, 1f, 1f, 0.4f);
            GUI.Label(watermarkRect, watermark, watermarkLabel);
#endif
        }
Exemplo n.º 15
0
        public virtual void Render(int id, Rect rect, int headerWidth, FrameRange viewRange, float pixelsPerFrame)
        {
            rect.y += _offsetAnim.value.y;

            _rect = rect;

            Rect viewRect = rect;

            viewRect.y     += _offsetAnim.value.y;
            viewRect.xMax   = headerWidth;
            viewRect.xMin   = viewRect.xMax - 16;
            viewRect.height = 16;

            if (_track.CanTogglePreview())
            {
                if (Event.current.type == EventType.MouseDown)
                {
                    if (viewRect.Contains(Event.current.mousePosition))
                    {
                        if (Event.current.button == 0)                          // left click?
                        {
                            _track.IsPreviewing = !_track.IsPreviewing;
                            FUtility.RepaintGameView();
                            Event.current.Use();
                        }
                    }
                }
            }

            Rect trackHeaderRect = rect;

            trackHeaderRect.xMax = headerWidth;

            bool selected = _isSelected;

            if (selected)
            {
                Color c = FGUI.GetSelectionColor();
                GUI.color = c;
                GUI.DrawTexture(trackHeaderRect, EditorGUIUtility.whiteTexture);
                GUI.color = FGUI.GetTextColor();

//				Debug.Log( GUI.color );
            }

            Rect trackLabelRect = trackHeaderRect;

            trackLabelRect.xMin += 10;

            GUI.Label(trackLabelRect, new GUIContent(_track.name), FGUI.GetTrackHeaderStyle());

            rect.xMin = trackHeaderRect.xMax;

            FrameRange validKeyframeRange = new FrameRange(0, SequenceEditor.GetSequence().Length);

            for (int i = 0; i != _eventEditors.Count; ++i)
            {
                if (i == 0)
                {
                    validKeyframeRange.Start = 0;
                }
                else
                {
                    validKeyframeRange.Start = _eventEditors[i - 1]._evt.End;
                }

                if (i == _eventEditors.Count - 1)
                {
                    validKeyframeRange.End = SequenceEditor.GetSequence().Length;
                }
                else
                {
                    validKeyframeRange.End = _eventEditors[i + 1]._evt.Start;
                }
                _eventEditors[i].Render(rect, viewRange, pixelsPerFrame, validKeyframeRange);
            }

            switch (Event.current.type)
            {
            case EventType.ContextClick:
                if (trackHeaderRect.Contains(Event.current.mousePosition))
                {
                    GenericMenu menu = new GenericMenu();
                    menu.AddItem(new GUIContent("Duplicate Track"), false, DuplicateTrack);
                    menu.AddItem(new GUIContent("Delete Track"), false, DeleteTrack);
                    menu.ShowAsContext();
                    Event.current.Use();
                }
                break;

            case EventType.MouseDown:
                if (EditorGUIUtility.hotControl == 0 && trackHeaderRect.Contains(Event.current.mousePosition))
                {
                    if (Event.current.button == 0)                      // selecting
                    {
                        if (Event.current.control)
                        {
                            if (IsSelected())
                            {
                                SequenceEditor.Deselect(this);
                            }
                            else
                            {
                                SequenceEditor.Select(this);
                            }
                        }
                        else if (Event.current.shift)
                        {
                            SequenceEditor.Select(this);
                        }
                        else
                        {
                            SequenceEditor.SelectExclusive(this);
                            _timelineEditor.StartTrackDrag(this);
                            _offsetAnim.value           = _offsetAnim.target = new Vector2(0, rect.yMin) - Event.current.mousePosition;
                            EditorGUIUtility.hotControl = id;
                        }
                        Event.current.Use();
                    }
                }
                break;

            case EventType.MouseUp:
                if (EditorGUIUtility.hotControl == id)
                {
                    EditorGUIUtility.hotControl = 0;
                    _offsetAnim.value           = _offsetAnim.target = Vector2.zero;

                    _timelineEditor.StopTrackDrag();

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

            case EventType.MouseDrag:
                if (EditorGUIUtility.hotControl == id)
                {
                    SequenceEditor.Repaint();
                    Event.current.Use();
                }
                break;
            }

            if (_track.CanTogglePreview())
            {
                GUI.color = FGUI.GetTextColor();

                if (!_track.IsPreviewing)
                {
                    Color c = GUI.color;
                    c.a       = 0.3f;
                    GUI.color = c;
                }

                GUI.DrawTexture(viewRect, _previewIcon);

                GUI.color = Color.white;
            }

#if UNITY_4_5
            if (_offsetAnim.isAnimating)
            {
                SequenceEditor.Repaint();
            }
#endif
        }
Exemplo n.º 16
0
        protected override void OnEnable()
        {
            base.OnEnable();

            _previewIcon = (Texture2D)AssetDatabase.LoadAssetAtPath(FUtility.GetFluxSkinPath() + "View.png", typeof(Texture2D));
        }
Exemplo n.º 17
0
        public void Render(int id, Rect rect, int hierarchyWidth, FrameRange viewRange, float pixelsPerFrame)
        {
            if (_timeline == null)
            {
                return;
            }

            rect.y += _offsetAnim.value.y;

            _rect = rect;

            float alpha = 1;

            if (EditorGUIUtility.hotControl == id)
            {
                rect.xMin += 5;
                rect.xMax -= 5;
                alpha      = 0.7f;
                Color c = GUI.color; c.a = alpha;
                GUI.color = c;
            }

            Rect hierarchyHeaderRect = rect; hierarchyHeaderRect.width = hierarchyWidth; hierarchyHeaderRect.height = HEADER_HEIGHT;

            Rect timelineHeaderRect = rect; timelineHeaderRect.height = HEADER_HEIGHT;

            Rect trackRect = timelineHeaderRect;

            trackRect.yMin   = timelineHeaderRect.yMax;
            trackRect.height = TRACK_HEIGHT;

            if (Event.current.type == EventType.Repaint)
            {
                GUI.color = FGUI.GetTimelineColor();
                GUI.DrawTexture(timelineHeaderRect, EditorGUIUtility.whiteTexture);
                GUI.color = new Color(1f, 1f, 1f, alpha);
            }

            if (_showTracks)
            {
                for (int i = 0; i != _trackEditors.Count; ++i)
                {
                    Vector3 upperLeft = trackRect.min;
                    Handles.color = FGUI.GetLineColor();

                    if (_trackDragged != null)
                    {
                        if (_trackDragged == _trackEditors[i])
                        {
                            Handles.DrawLine(upperLeft, upperLeft + new Vector3(trackRect.width, 0, 0));
                            trackRect.y += TRACK_HEIGHT;
                            continue;
                        }

                        if (i < _trackDragged.GetRuntimeObject().GetId() && Event.current.mousePosition.y < trackRect.yMax)
                        {
                            _trackEditors[i].SetOffset(new Vector2(0, TRACK_HEIGHT));
                        }
                        else if (i > _trackDragged.GetRuntimeObject().GetId() && Event.current.mousePosition.y > trackRect.yMin)
                        {
                            _trackEditors[i].SetOffset(new Vector2(0, -TRACK_HEIGHT));
                        }
                        else
                        {
                            _trackEditors[i].SetOffset(Vector2.zero);
                        }
                    }

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

                    GUI.color = new Color(1f, 1f, 1f, alpha);
                    _trackEditors[i].Render(_trackEditorIds[i], trackRect, hierarchyWidth, viewRange, pixelsPerFrame);

                    Handles.DrawLine(upperLeft, upperLeft + new Vector3(trackRect.width, 0, 0));

                    trackRect.y += TRACK_HEIGHT;
                }

                if (_trackDragged != null)
                {
                    Rect r = trackRect;
                    r.y = Event.current.mousePosition.y;
                    _trackDragged.Render(_trackEditorIds[_trackDragged.GetRuntimeObject().GetId()], r, hierarchyWidth, viewRange, pixelsPerFrame);
                }
            }

            Rect hierarchyLabelRect = hierarchyHeaderRect;

            hierarchyLabelRect.height = 20;
            hierarchyLabelRect.xMax   = hierarchyLabelRect.xMax - 23;

            Rect foldoutRect = hierarchyLabelRect;

            foldoutRect.width        = 16;
            hierarchyLabelRect.xMin += 16;

            string timelineHeaderName = _timeline.Owner != null ? _timeline.Owner.name : _timeline.name + " (Missing)";

            GUI.Label(hierarchyLabelRect, new GUIContent(timelineHeaderName), FGUI.GetTimelineHeaderStyle());

            _showTracks = EditorGUI.Foldout(foldoutRect, _showTracks, GUIContent.none);

            switch (Event.current.type)
            {
            case EventType.ContextClick:
                if (hierarchyHeaderRect.Contains(Event.current.mousePosition))
                {
                    GenericMenu menu = new GenericMenu();

                    if (Selection.activeGameObject == null || PrefabUtility.GetPrefabType(Selection.activeGameObject) == PrefabType.Prefab || PrefabUtility.GetPrefabType(Selection.activeGameObject) == PrefabType.ModelPrefab)
                    {
                        menu.AddDisabledItem(new GUIContent("Change Owner"));
                    }
                    else
                    {
                        menu.AddItem(new GUIContent("Change Owner to " + Selection.activeGameObject.name), false, ChangeOwner);
                    }

                    menu.AddItem(new GUIContent("Duplicate Timeline"), false, DuplicateTimeline);
                    menu.AddItem(new GUIContent("Delete Timeline"), false, DeleteTimeline);
                    menu.AddItem(new GUIContent("Add Timeline"), false, AddTimeline);

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

            case EventType.MouseDrag:
                if (EditorGUIUtility.hotControl == id)
                {
                    SequenceEditor.Repaint();
                    Event.current.Use();
                }
                break;

            case EventType.MouseUp:
                if (EditorGUIUtility.hotControl == id)
                {
                    EditorGUIUtility.hotControl = 0;
                    _offsetAnim.value           = _offsetAnim.target = Vector2.zero;
                    SequenceEditor.Repaint();

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

            case EventType.Repaint:
                Handles.color = FGUI.GetLineColor();
                Handles.DrawLine(new Vector3(rect.xMin, rect.yMax, 0), new Vector3(rect.xMax, rect.yMax, 0));
                break;

            case EventType.KeyDown:
                if (EditorGUIUtility.hotControl == id && Event.current.keyCode == KeyCode.Escape)
                {
                    EditorGUIUtility.hotControl = 0;
                    Event.current.Use();
                }
                break;
            }

            Rect timelineOptionsRect = hierarchyHeaderRect;

            timelineOptionsRect.xMin   = hierarchyHeaderRect.xMax - 20;
            timelineOptionsRect.yMin   = hierarchyHeaderRect.yMin;
            timelineOptionsRect.width  = 14;
            timelineOptionsRect.height = 14;

            if (Event.current.type == EventType.MouseDown && timelineOptionsRect.Contains(Event.current.mousePosition))
            {
                Event.current.Use();

                GenericMenu menu  = new GenericMenu();
                Type[]      types = typeof(FEvent).Assembly.GetTypes();
                List <KeyValuePair <Type, FEventAttribute> > validTypeList = new List <KeyValuePair <Type, FEventAttribute> >();

                foreach (Type t in types)
                {
                    if (!typeof(FEvent).IsAssignableFrom(t))
                    {
                        continue;
                    }

                    object[] attributes = t.GetCustomAttributes(typeof(FEventAttribute), false);
                    if (attributes.Length == 0)
                    {
                        continue;
                    }

                    validTypeList.Add(new KeyValuePair <Type, FEventAttribute>(t, (FEventAttribute)attributes[0]));
                }

                validTypeList.Sort(delegate(KeyValuePair <Type, FEventAttribute> x, KeyValuePair <Type, FEventAttribute> y)
                {
                    return(x.Value.menu.CompareTo(y.Value.menu));
                });

                foreach (KeyValuePair <Type, FEventAttribute> kvp in validTypeList)
                {
                    menu.AddItem(new GUIContent(kvp.Value.menu), false, AddTrackMenu, kvp);
                }

                menu.ShowAsContext();
            }

            GUI.color = FGUI.GetTextColor();

            GUI.DrawTexture(timelineOptionsRect, (Texture2D)AssetDatabase.LoadAssetAtPath(FUtility.GetFluxSkinPath() + "Plus.png", typeof(Texture2D)));

            if (Event.current.type == EventType.MouseDown && hierarchyHeaderRect.Contains(Event.current.mousePosition))
            {
                if (Event.current.button == 0)                  // dragging
                {
                    EditorGUIUtility.hotControl = id;

                    _offsetAnim.value = _offsetAnim.target = new Vector2(0, hierarchyHeaderRect.yMin) - Event.current.mousePosition;

                    SequenceEditor.StartTimelineDrag(this);

                    Event.current.Use();
                }
            }

#if UNITY_4_5
            if (_offsetAnim.isAnimating)
            {
                _sequenceEditor.Repaint();
            }
#endif
        }
Exemplo n.º 18
0
        protected virtual void RenderEvent(FrameRange viewRange, FrameRange validKeyframeRange)
        {
            int leftHandleId  = EditorGUIUtility.GetControlID(FocusType.Passive);
            int evtHandleId   = EditorGUIUtility.GetControlID(FocusType.Passive);
            int rightHandleId = EditorGUIUtility.GetControlID(FocusType.Passive);

            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, leftHandleId);
            }

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

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

                GUISkin  skin       = FUtility.GetFluxSkin();
                GUIStyle eventStyle = skin.GetStyle("Event");

                GUI.color = GetColor();

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

                GUI.color = Color.white;

                break;

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

                    if (rightHandleVisible && rightHandleRect.Contains(mousePos))
                    {
                        EditorGUIUtility.hotControl = rightHandleId;
//						keyframeOnSelect = evt.Start;
                        Event.current.Use();
                    }
                    else if (leftHandleVisible && leftHandleRect.Contains(mousePos))
                    {
                        EditorGUIUtility.hotControl = leftHandleId;
//						keyframeOnSelect = evt.End;
                        Event.current.Use();
                    }
                    else if (_eventRect.Contains(mousePos))
                    {
                        EditorGUIUtility.hotControl = evtHandleId;
                        _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();
                    }
                }
                break;

            case EventType.MouseUp:
                if (EditorGUIUtility.hotControl != 0)
                {
                    if (EditorGUIUtility.hotControl == evtHandleId ||
                        EditorGUIUtility.hotControl == leftHandleId ||
                        EditorGUIUtility.hotControl == rightHandleId)
                    {
                        EditorGUIUtility.hotControl = 0;
                        Event.current.Use();
                        SequenceEditor.Repaint();
                    }
                }
                break;

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

                        int delta = t - _evt.Start;

                        SequenceEditor.MoveEvents(delta);

                        Event.current.Use();
                    }
                    else if (EditorGUIUtility.hotControl == leftHandleId || EditorGUIUtility.hotControl == rightHandleId)
                    {
                        int leftLimit  = 0;
                        int rightLimit = 0;

                        bool draggingStart = EditorGUIUtility.hotControl == leftHandleId;

                        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;
            }
        }
Exemplo n.º 19
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);
                }
            }
        }