public FEvent TryAddEvent(int t) { FEvent newEvt = null; if (_track.CanAddAt(t)) { FEvent evtAfterT = _track.GetEventAfter(t); int newEventEndT; if (evtAfterT == null) { newEventEndT = SequenceEditor.GetSequence().Length; } else { newEventEndT = evtAfterT.Start; } newEvt = FEvent.Create(_track.GetEventType(), new FrameRange(t, newEventEndT)); Undo.RecordObject(_track, string.Empty); Undo.RegisterCreatedObjectUndo(newEvt.gameObject, "create Event"); _track.Add(newEvt); } return(newEvt); }
// public override void OnTogglePreview () // { //// int currentFrame = Track.Sequence.GetCurrentFrame(); // // base.OnTogglePreview(); // //// if( currentFrame >= 0 ) //// SequenceEditor.SetCurrentFrame( currentFrame ); // } public override void Render(Rect rect, float headerWidth) { // bool isPreviewing = _track.IsPreviewing; base.Render(rect, headerWidth); // if( isPreviewing != _track.IsPreviewing ) // { // if( Event.current.alt ) // SyncWithAnimationWindow = true; // } switch (Event.current.type) { case EventType.DragUpdated: if (rect.Contains(Event.current.mousePosition)) { int numAnimationsDragged = FAnimationEventInspector.NumAnimationsDragAndDrop(Track.Sequence.FrameRate); int frame = SequenceEditor.GetFrameForX(Event.current.mousePosition.x); DragAndDrop.visualMode = numAnimationsDragged > 0 && Track.CanAddAt(frame) ? DragAndDropVisualMode.Copy : DragAndDropVisualMode.Rejected; Event.current.Use(); } break; case EventType.DragPerform: if (rect.Contains(Event.current.mousePosition)) { AnimationClip animClip = FAnimationEventInspector.GetAnimationClipDragAndDrop(Track.Sequence.FrameRate); if (animClip && Mathf.Approximately(animClip.frameRate, Track.Sequence.FrameRate)) { int frame = SequenceEditor.GetFrameForX(Event.current.mousePosition.x); int maxLength; if (Track.CanAddAt(frame, out maxLength)) { FPlayAnimationEvent animEvt = FEvent.Create <FPlayAnimationEvent>(new FrameRange(frame, frame + Mathf.Min(maxLength, Mathf.RoundToInt(animClip.length * animClip.frameRate)))); Track.Add(animEvt); FAnimationEventInspector.SetAnimationClip(animEvt, animClip); DragAndDrop.AcceptDrag(); } } Event.current.Use(); } break; } // if( _wasPreviewing != _track.IsPreviewing ) // { // if( _wasPreviewing ) // SequenceEditor.OnUpdateEvent.RemoveListener( OnUpdate ); // else // SequenceEditor.OnUpdateEvent.AddListener( OnUpdate ); // // _wasPreviewing = _track.IsPreviewing; // } }
public override void Render(Rect rect, float headerWidth) { base.Render(rect, headerWidth); switch (Event.current.type) { case EventType.DragUpdated: if (rect.Contains(Event.current.mousePosition)) { int numAnimationsDragged = FAnimationEventInspector.NumAnimationsDragAndDrop(Track.Sequence.FrameRate); int frame = SequenceEditor.GetFrameForX(Event.current.mousePosition.x); DragAndDrop.visualMode = numAnimationsDragged > 0 && Track.CanAddAt(frame) ? DragAndDropVisualMode.Copy : DragAndDropVisualMode.Rejected; Event.current.Use(); } break; case EventType.DragPerform: if (rect.Contains(Event.current.mousePosition)) { AnimationClip animClip = FAnimationEventInspector.GetAnimationClipDragAndDrop(Track.Sequence.FrameRate); if (animClip && Mathf.Approximately(animClip.frameRate, Track.Sequence.FrameRate)) { int frame = SequenceEditor.GetFrameForX(Event.current.mousePosition.x); int maxLength; if (Track.CanAddAt(frame, out maxLength)) { FPlayAnimationEvent animEvt = FEvent.Create <FPlayAnimationEvent>(new FrameRange(frame, frame + Mathf.Min(maxLength, Mathf.RoundToInt(animClip.length * animClip.frameRate)))); Track.Add(animEvt); FAnimationEventInspector.SetAnimationClip(animEvt, animClip); DragAndDrop.AcceptDrag(); } } Event.current.Use(); } break; } }