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 }
public void OnGUI() { FSequence 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 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); }
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(); }
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 }