public static GTimelineEditor CreateSequence()
        {
            // find new name & priority for sequence
            string sequenceNameFormat = "Sequence {0}";

            int sequenceId = 0;

            string sequenceName = string.Format(sequenceNameFormat, sequenceId.ToString("000"));

            GTimelineEditor[] sequences = FindObjectsOfType <GTimelineEditor>();
            for (int i = 0, limit = sequences.Length; i != limit; ++i)
            {
                if (sequences[i].name == sequenceName)
                {
                    // try new name
                    ++sequenceId;
                    sequenceName = string.Format(sequenceNameFormat, sequenceId.ToString("000"));
                    i            = -1;          // restart search
                }
            }

            GTimelineEditor sequence = GTimelineEditor.CreateSequence();

            sequence.name      = sequenceName;
            sequence.FrameRate = FUtility.FrameRate;
            sequence.Length    = sequence.FrameRate * GTimelineEditor.DEFAULT_LENGTH;

            Undo.RegisterCreatedObjectUndo(sequence.gameObject, "Create Sequence");

            return(sequence);
        }
Example #2
0
        protected override void Init(FObject obj)
        {
            base.Init(obj);

            if (_sequenceEditor == null)
            {
                _sequenceEditor = GTimelineEditor.CreateInstance <GTimelineEditor>();
                _sequenceEditor.Init((EditorWindow)null);                   // doesn't have a window
                _sequenceEditor.OpenSequence(_evt.Owner.GetComponent <GTimeline>());
            }
        }
        protected override void Init(FObject obj)
        {
            base.Init(obj);

            if (_sequenceEditor == null)
            {
                _sequenceEditor = GTimelineEditor.CreateInstance <GTimelineEditor>();
                _sequenceEditor.Init((Editor)null /*SequenceEditor*/);
                _sequenceEditor.OpenSequence(_track.Owner.GetComponent <GTimeline>());
            }
        }
Example #4
0
        public static void Rescale(GTimelineEditor sequence, int frameRate, bool confirm)
        {
            if (sequence.FrameRate == frameRate)
            {
                return;
            }

            if (!confirm || sequence.IsEmpty() || EditorUtility.DisplayDialog(CHANGE_FRAME_RATE_TITLE, string.Format(CHANGE_FRAME_RATE_MSG, sequence.FrameRate, frameRate), CHANGE_FRAME_RATE_OK, CHANGE_FRAME_RATE_CANCEL))
            {
                Rescale(sequence, frameRate);
            }
        }
Example #5
0
        public void Init(FObject obj, GTimelineEditor sequenceEditor)
        {
            //if (_sequenceEditor == sequenceEditor && obj == _timeline)
            //{
            //    Debug.LogError("´íÎóµÄÐòÁУº" + sequenceEditor.name);
            //    return;
            //}
            _sequenceEditor = sequenceEditor;
            Init(obj);
#if UNITY_4_6
            _offsetAnim.valueChanged.AddListener(_sequenceEditor.Repaint);
#endif
        }
Example #6
0
        public static void Show(Vector2 guiPos, GTimelineEditor sequence, UnityAction <GTimelineEditor, int, bool> callback)
        {
            FChangeFrameRateWindow window = CreateInstance <FChangeFrameRateWindow>();

            Rect r = new Rect();

            r.min    = EditorGUIUtility.GUIToScreenPoint(guiPos);
            r.width  = 0;
            r.height = 0;

            window._sequence  = sequence;
            window._frameRate = 25;
//			window.OnChange.AddListener( callback );
            window.OnChange = callback;

            window.ShowAsDropDown(r, new Vector2(200, 100));
        }
        private void RenderHeader(Rect rect)
        {
            GTimelineEditor sequence = _sequenceEditor.GetSequence();

            GUI.Label(rect, sequence.name);

            Rect r = rect;

            r.xMin = r.xMax - 100;

            EditorGUI.IntField(r, sequence.Length);

            GUIContent lengthLabel = new GUIContent("Length");

            r.x -= EditorStyles.label.CalcSize(lengthLabel).x + 5;

            EditorGUI.PrefixLabel(r, lengthLabel);

            r.x    -= 50;
            r.width = 40;

            EditorGUI.IntField(r, sequence.FrameRate);

            GUIContent framerateLabel = new GUIContent("Frame Rate");

            r.x -= EditorStyles.label.CalcSize(framerateLabel).x + 5;
            EditorGUI.PrefixLabel(r, framerateLabel);

            r.x    -= 110;
            r.width = 100;

            EditorGUI.EnumPopup(r, sequence.UpdateMode);

            GUIContent updateModeLabel = new GUIContent("Update Mode");

            Vector2 updateModeLabelSize = EditorStyles.label.CalcSize(updateModeLabel);

            r.x    -= updateModeLabelSize.x + 5;
            r.width = updateModeLabelSize.x;

            EditorGUI.PrefixLabel(r, updateModeLabel);
        }
Example #8
0
        public static void Rescale(GTimelineEditor sequence, int frameRate)
        {
            if (sequence.FrameRate == frameRate)
            {
                return;
            }

            float scaleFactor = (float)frameRate / sequence.FrameRate;

            Undo.RecordObject(sequence, "Change Frame Rate");

            sequence.Length    = Mathf.RoundToInt(sequence.Length * scaleFactor);
            sequence.FrameRate = frameRate;

            foreach (FTimeline timeline in sequence.GetTimelines())
            {
                Rescale(timeline, scaleFactor);
            }

            EditorUtility.SetDirty(sequence);
        }
        void Update()
        {
#if FLUX_PROFILE
            Profiler.BeginSample("flux Update");
#endif
            if (_sequenceEditor == null)
            {
                _sequenceEditor = GTimelineEditor.CreateInstance <GTimelineEditor>();
                _sequenceEditor.Init(this);
            }

            GTimelineEditor sequence = _sequenceEditor.GetSequence();

            if (EditorApplication.isCompiling)
            {
                _isEditorCompiling = true;
                _sequenceEditor.Stop();
            }
            else if (_isEditorCompiling)
            {
                _isEditorCompiling = false;
                _windowRect        = new Rect();          // clear window size so it rebuilds layout
                _sequenceEditor.Refresh();
            }

            if (Application.isPlaying && sequence != null)
            {
                Repaint();
            }

            _sequenceEditor.Update();

#if FLUX_PROFILE
            Profiler.EndSample();
#endif
        }
        public static void Open(GTimelineEditor sequence)
        {
            Open();

            instance._sequenceEditor.OpenSequence(sequence);
        }
        void OnGUI()
        {
#if FLUX_PROFILE
            Profiler.BeginSample("Flux OnGUI");
#endif
            if (_sequenceEditor == null)
            {
                return;
            }

            Rect currentWindowRect = position;
            currentWindowRect.x = 0;
            currentWindowRect.y = 0;

            if (currentWindowRect != _windowRect)
            {
                RebuildLayout();
            }

            if (Event.current.type == EventType.Ignore)
            {
                EditorGUIUtility.hotControl = 0;
            }

            GTimelineEditor sequence = _sequenceEditor.GetSequence();

            if (sequence == null)
            {
                ShowNotification(new GUIContent("Select Or Create Sequence"));
            }
            else if (Event.current.isKey)
            {
                if (Event.current.keyCode == KeyCode.Space)
                {
                    if (Event.current.type == EventType.KeyUp)
                    {
                        if (_sequenceEditor.IsPlaying)
                        {
                            if (Event.current.shift)
                            {
                                Stop();
                            }
                            else
                            {
                                Pause();
                            }
                        }
                        else
                        {
                            Play(Event.current.shift);
                        }


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

                if (Event.current.type == EventType.KeyDown && Event.current.keyCode == KeyCode.Return)
                {
                    EditorGUIUtility.keyboardControl = 0;
                    Event.current.Use();
                    Repaint();
                }
            }


            // header
            _windowHeader.OnGUI();

            if (sequence == null)
            {
                return;
            }

            // toolbar
            _toolbar.OnGUI();

            switch (Event.current.type)
            {
            case EventType.KeyDown:
                if (Event.current.keyCode == KeyCode.Backspace || Event.current.keyCode == KeyCode.Delete)
                {
                    _sequenceEditor.DestroyEvents(_sequenceEditor._selectedEvents);
                    Event.current.Use();
                }
                else if (Event.current.keyCode == KeyCode.K && _sequenceEditor.GetSequence().GetCurrentFrame() >= 0)
                {
                    _sequenceEditor.AddEvent(_sequenceEditor.GetSequence().GetCurrentFrame());
                    Event.current.Use();
                }
                break;

            case EventType.MouseDown:
                break;

            case EventType.MouseUp:
                break;
            }

            if (Event.current.type == EventType.ValidateCommand)
            {
                Repaint();
            }

            _sequenceEditor.OnGUI();


            // because of a bug with windows editor, we have to not catch right button
            // otherwise ContextClick doesn't get called
            if (Event.current.type == EventType.MouseUp && Event.current.button != 1)
            {
                Event.current.Use();
            }

            // handle drag & drop
            if (Event.current.type == EventType.DragUpdated)
            {
                if (_windowRect.Contains(Event.current.mousePosition))
                {
                    DragAndDrop.visualMode = DragAndDropVisualMode.Link;
                    Event.current.Use();
                }
            }
            else if (Event.current.type == EventType.DragPerform)
            {
                if (_windowRect.Contains(Event.current.mousePosition))
                {
                    foreach (UnityEngine.Object obj in DragAndDrop.objectReferences)
                    {
                        if (!(obj is GameObject))
                        {
                            continue;
                        }

                        PrefabType prefabType = PrefabUtility.GetPrefabType(obj);
                        if (prefabType == PrefabType.ModelPrefab || prefabType == PrefabType.Prefab)
                        {
                            continue;
                        }

                        Undo.IncrementCurrentGroup();
                        UnityEngine.Object[] objsToSave = new UnityEngine.Object[] { sequence, this };

                        Undo.RegisterCompleteObjectUndo(objsToSave, string.Empty);

                        GameObject timelineGO = new GameObject(obj.name);

                        FTimeline timeline = timelineGO.AddComponent <Flux.FTimeline>();
                        timeline.SetOwner(((GameObject)obj).transform);
                        sequence.Add(timeline);

                        Undo.RegisterCompleteObjectUndo(objsToSave, string.Empty);
                        Undo.RegisterCreatedObjectUndo(timeline.gameObject, "create Timeline");
                        Undo.CollapseUndoOperations(Undo.GetCurrentGroup());
                    }
                    RemoveNotification();
                    Event.current.Use();
                    DragAndDrop.AcceptDrag();
                    Refresh();
                    EditorGUIUtility.ExitGUI();
                }
            }

            if (Event.current.type == EventType.Repaint)
            {
                Handles.DrawLine(new Vector3(_windowHeaderRect.xMin, _windowHeaderRect.yMax, 0), new Vector3(_windowHeaderRect.xMax - GTimelineEditor.RIGHT_BORDER, _windowHeaderRect.yMax, 0));
            }
#if FLUX_PROFILE
            Profiler.EndSample();
#endif
        }
Example #12
0
        void OnEnable()
        {
            _sequence = (GTimelineEditor)target;

            _timelineContainer = serializedObject.FindProperty("_timelineContainer");
        }
Example #13
0
        public void OpenSequence(GTimelineEditor sequence)
        {
#if FLUX_DEBUG
            Debug.Log("Opening sequence: " + sequence);
#endif
            if (sequence == null)
            {
                Debug.LogError("sequence == null");
                if (!object.Equals(sequence, null))
                {
                    sequence = (GTimelineEditor)EditorUtility.InstanceIDToObject(sequence.GetInstanceID());
                }
            }

            bool sequenceChanged = _sequence != sequence && (object.Equals(_sequence, null) || object.Equals(sequence, null) || _sequence.GetInstanceID() != sequence.GetInstanceID());

//			Debug.Log ("selected sequence! Changed? " + sequenceChanged );

            if (sequenceChanged)
            {
                if (_sequence != null)
                {
                    Stop();
                }
                _editorCache.Clear();
                _selectedEvents.Clear();
                _selectedTracks.Clear();
            }
            else
            {
                _editorCache.Refresh();
            }


            if (sequence != null)
            {
//				_sequenceInstanceID = sequence.GetInstanceID();
                if (_viewRange.Length == 0)
                {
                    _viewRange = new FrameRange(0, sequence.Length);
                }

                if (!EditorApplication.isPlaying)
                {
                    sequence.Rebuild();
                }

                List <FTimeline> timelines = sequence.GetTimelines();

                _timelineEditors.Clear();

                for (int i = 0; i < timelines.Count; ++i)
                {
                    FTimeline       timeline       = timelines[i];
                    FTimelineEditor timelineEditor = GetEditor <FTimelineEditor>(timeline);
                    timelineEditor.Init(timeline, this);
                    _timelineEditors.Add(timelineEditor);
                }

                if (_viewRange.Length == 0)
                {
                    _viewRange = new FrameRange(0, sequence.Length);
                }
            }
            else
            {
//				_sequenceInstanceID = int.MinValue;
            }

            _sequence = sequence;

            Repaint();
        }
Example #14
0
        public void OnGUI()
        {
            GTimelineEditor sequence  = _window.GetSequenceEditor().GetSequence();
            FrameRange      viewRange = _window.GetSequenceEditor().GetViewRange();

            GUI.contentColor = FGUI.GetTextColor();

            bool goToFirst    = false;
            bool goToPrevious = false;
            bool goToNext     = false;
            bool goToLast     = false;

            if (Event.current.type == EventType.KeyDown)
            {
                if (Event.current.keyCode == KeyCode.Comma)
                {
                    goToFirst    = Event.current.shift;
                    goToPrevious = !goToFirst;
                    Event.current.Use();
                    _window.Repaint();
                }

                if (Event.current.keyCode == KeyCode.Period)
                {
                    goToLast = Event.current.shift;
                    goToNext = !goToLast;
                    Event.current.Use();
                    _window.Repaint();
                }
            }

            if (GUI.Button(_firstFrameButtonRect, _firstFrame, EditorStyles.miniButtonLeft) || goToFirst)
            {
                GoToFrame(viewRange.Start);
            }

            if (GUI.Button(_previousFrameButtonRect, _previousFrame, EditorStyles.miniButtonMid) || goToPrevious)
            {
                GoToFrame(viewRange.Cull(sequence.GetCurrentFrame() - 1));
            }

            GUIStyle numberFieldStyle = new GUIStyle(EditorStyles.numberField);

            numberFieldStyle.alignment = TextAnchor.MiddleCenter;

//			Debug.Log("hot control: " + EditorGUIUtility.hotControl + " keyboard control: " + EditorGUIUtility.keyboardControl );

            if (sequence != null)
            {
                if (sequence.GetCurrentFrame() < 0)
                {
                    EditorGUI.BeginChangeCheck();
                    string frameStr = EditorGUI.TextField(_currentFrameFieldRect, string.Empty, numberFieldStyle);
                    if (EditorGUI.EndChangeCheck())
                    {
                        int newCurrentFrame = 0;
                        int.TryParse(frameStr, out newCurrentFrame);
                        newCurrentFrame = Mathf.Clamp(newCurrentFrame, 0, sequence.Length);
                        _window.GetSequenceEditor().SetCurrentFrame(newCurrentFrame);
                    }
                }
                else
                {
                    EditorGUI.BeginChangeCheck();
                    int newCurrentFrame = Mathf.Clamp(EditorGUI.IntField(_currentFrameFieldRect, sequence.GetCurrentFrame(), numberFieldStyle), 0, sequence.Length);
                    if (EditorGUI.EndChangeCheck())
                    {
                        _window.GetSequenceEditor().SetCurrentFrame(newCurrentFrame);
                    }
                }
            }

            if (GUI.Button(_nextFrameButtonRect, _nextFrame, EditorStyles.miniButtonMid) || goToNext)
            {
                GoToFrame(viewRange.Cull(sequence.GetCurrentFrame() + 1));
            }

            if (GUI.Button(_lastFrameButtonRect, _lastFrame, EditorStyles.miniButtonRight) || goToLast)
            {
                GoToFrame(viewRange.End);
            }

//			if( GUI.Button( _playBackwardButtonRect, _window.IsPlaying ? "[] Stop" : "< Play", EditorStyles.miniButtonLeft) )
//			{
//				if( _window.IsPlaying )
//				{
//					_window.Stop();
//				}
//				else
//				{
//					_window.Play();
//				}
//			}

            if (GUI.Button(_stopButtonRect, _stop, EditorStyles.miniButtonLeft))
            {
                Stop();
            }

            if (GUI.Button(_playForwardButtonRect, _window.IsPlaying ? _pause : _playForward, EditorStyles.miniButtonRight))
            {
                if (_window.IsPlaying)
                {
                    Pause();
                }
                else
                {
                    Play();
                }
            }


            if (_showViewRange)
            {
                EditorGUI.PrefixLabel(_viewRangeLabelRect, _viewRangeLabel);

                EditorGUI.BeginChangeCheck();

                viewRange.Start = EditorGUI.IntField(_viewRangeStartRect, viewRange.Start, numberFieldStyle);

                EditorGUI.PrefixLabel(_viewRangeDashRect, _viewRangeDash);

                viewRange.End = EditorGUI.IntField(_viewRangeEndRect, viewRange.End, numberFieldStyle);

                if (EditorGUI.EndChangeCheck())
                {
                    _window.GetSequenceEditor().SetViewRange(viewRange);
                }
            }
        }
        public void OnGUI()
        {
            GTimelineEditor 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))
            {
                GTimelineEditor 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();
        }