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(); } } }
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 = Flux.FUtility.IsAnimationEditable(AnimEvt._animationClip); if (isBlending) { transitionOffsetRect.xMin = Rect.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; AnimatorWindowProxy.OpenAnimatorWindowWithAnimatorController((AnimatorController)AnimTrack.AnimatorController); 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.Ignore: 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 - Rect.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 - Rect.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) { int animFrameLength = Mathf.RoundToInt(animationClipDragged.length * animationClipDragged.frameRate); FAnimationEventInspector.SetAnimationClip(AnimEvt, animationClipDragged); FrameRange maxRange = AnimEvt.GetMaxFrameRange(); SequenceEditor.MoveEvent(AnimEvt, new FrameRange(AnimEvt.Start, Mathf.Min(AnimEvt.Start + animFrameLength, maxRange.End))); 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); Color guiColor = GUI.color; Color c = new Color(1f, 1f, 1f, 0.3f); c.a *= guiColor.a; GUI.color = c; GUI.DrawTexture(r, t); if (Event.current.alt) { GUI.color = Color.white; } transitionOffsetStyle.Draw(transitionOffsetRect, false, false, false, false); GUI.color = guiColor; // Debug.Log ( transitionOffsetRect ); } // 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); } } }