public void RenderTransformCurves(int samplesPerSecond) { if (_transformCurves == null || _transformCurves.clip == null) { CreateTransformCurves(); } else { _transformCurves.RefreshCurves(); } float totalTime = AnimEvt.LengthTime; float timePerSample = totalTime / samplesPerSecond; int numSamples = Mathf.RoundToInt(totalTime / timePerSample) + 1; Vector3[] pts = new Vector3[numSamples]; float t = 0; for (int i = 0; i < numSamples; ++i) { pts[i] = _transformCurves.GetWorldPosition(t); t += timePerSample; } Handles.DrawPolyLine(pts); FAnimationTrackEditor animTrackEditor = (FAnimationTrackEditor)TrackEditor; // if( _transformCurves.clip.name.Contains("1") ) // Debug.Log( _transformCurves.xRot.keys[0].tangentMode + " " + _transformCurves.yRot[0].tangentMode + " " + _transformCurves.zRot[0].tangentMode + " " + _transformCurves.wRot[0].tangentMode ); if (animTrackEditor.ShowKeyframes || animTrackEditor.ShowKeyframeTimes) { int animFramerate = Mathf.RoundToInt(_transformCurves.clip.frameRate); Keyframe[] keyframes = _transformCurves.GetPositionKeyframes(); for (int i = 0; i != keyframes.Length; ++i) { Keyframe keyframe = keyframes[i]; Vector3 pos = _transformCurves.GetPosition(keyframe.time); Quaternion rot = _transformCurves.GetRotation(keyframe.time); Quaternion toolRot = rot; bool isGlobalRotation = Tools.pivotRotation == PivotRotation.Global; if (isGlobalRotation) { toolRot = _globalRotation; //Quaternion.identity; } // Handles.color = Color.gray; // Vector3 newPos = Handles.FreeMoveHandle(pos, rot, 1, Vector3.one*0.2f, Handles.SphereCap);//Handles.PositionHandle( pos, rot ); if (animTrackEditor.ShowKeyframes) { if (Tools.current == Tool.Move) { Vector3 newPos = Handles.DoPositionHandle(pos, toolRot); //Handles.PositionHandle( pos, rot ); if (newPos != pos) { Undo.RecordObject(_transformCurves.clip, "Change Keyframe"); _transformCurves.SetPosition(newPos, keyframe.time); } } else if (Tools.current == Tool.Rotate) { Quaternion newRot = Handles.DoRotationHandle(toolRot, pos); if (newRot != toolRot) { Undo.RecordObject(_transformCurves.clip, "Change Keyframe"); _transformCurves.SetRotation(isGlobalRotation ? (newRot * Quaternion.Inverse(toolRot)) * rot : newRot, keyframe.time); if (isGlobalRotation) { _globalRotation = newRot; } } } } if (Event.current.type == EventType.MouseUp || Event.current.type == EventType.Ignore) { _globalRotation = Quaternion.identity; } if (animTrackEditor.ShowKeyframeTimes) { int frame = Mathf.RoundToInt(keyframe.time * animFramerate); Handles.Label(pos + new Vector3(0, .25f, 0), FUtility.GetTime(AnimEvt.Start + frame, animFramerate), EditorStyles.toolbarButton); } // Handles.BeginGUI(); // Vector3 screenPos = SceneView.currentDrawingSceneView.camera.WorldToScreenPoint( pos ); // GUI.Label( new Rect( screenPos.x-10, SceneView.currentDrawingSceneView.position.height-screenPos.y-50, 20, 20 ), keyframe.time.ToString() ); // Handles.EndGUI(); } } }
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); }