public static bool Do(WindowState state, TrackAsset track) { AnimationClip clipToEdit = null; AnimationTrack animationTrack = track as AnimationTrack; if (animationTrack != null) { if (!animationTrack.CanConvertToClipMode()) { return(false); } clipToEdit = animationTrack.infiniteClip; } else if (track.hasCurves) { clipToEdit = track.curves; } if (clipToEdit == null) { return(false); } var gameObject = state.GetSceneReference(track); var timeController = TimelineAnimationUtilities.CreateTimeController(state, CreateTimeControlClipData(track)); TimelineAnimationUtilities.EditAnimationClipWithTimeController(clipToEdit, timeController, gameObject); return(true); }
public override bool Execute(WindowState state, TimelineClip[] clips) { var clip = clips[0]; if (clip.curves != null || clip.animationClip != null) { var clipToEdit = clip.animationClip != null ? clip.animationClip : clip.curves; if (clipToEdit == null) { return(false); } var gameObject = state.GetSceneReference(clip.parentTrack); var timeController = TimelineAnimationUtilities.CreateTimeController(state, clip); TimelineAnimationUtilities.EditAnimationClipWithTimeController( clipToEdit, timeController, clip.animationClip != null ? gameObject : null); return(true); } return(false); }
internal static UndoPropertyModification[] ProcessMonoBehaviourModification(UndoPropertyModification[] modifications, WindowState state) { if (!state.recording) { return(modifications); } if (state == null || state.editSequence.director == null) { return(modifications); } s_UnprocessedMods.Clear(); s_TrackRecorder.PrepareForRecord(state); s_ModsToProcess.Clear(); s_ModsToProcess.AddRange(modifications.Reverse()); while (s_ModsToProcess.Count > 0) { var modification = s_ModsToProcess[s_ModsToProcess.Count - 1]; s_ModsToProcess.RemoveAt(s_ModsToProcess.Count - 1); // grab the clip we need to apply to var modifiedGO = GetGameObjectFromModification(modification); var track = GetTrackForGameObject(modifiedGO, state); if (track != null) { IsRecordingAnimationTrack = true; double startTime = 0; var clip = s_TrackRecorder.PrepareTrack(track, state, modifiedGO, out startTime); if (clip == null) { s_ModsToProcess.Reverse(); return(s_ModsToProcess.ToArray()); } s_RecordState.activeAnimationClip = clip; s_RecordState.activeRootGameObject = state.GetSceneReference(track); s_RecordState.activeGameObject = modifiedGO; s_RecordState.currentFrame = Mathf.RoundToInt((float)startTime); EditorUtility.SetDirty(clip); var toProcess = GatherRelatedModifications(modification, s_ModsToProcess); var animator = s_RecordState.activeRootGameObject.GetComponent <Animator>(); var animTrack = track as AnimationTrack; // update preview mode before recording so the correct values get placed (in case we modify offsets) // Case 900624 UpdatePreviewMode(toProcess, modifiedGO); // if this is the first position/rotation recording, copy the current position / rotation to the track offset AddTrackOffset(animTrack, toProcess, clip, animator); // same for clip mod clips being created AddClipOffset(animTrack, toProcess, s_TrackRecorder.recordClip, animator); // Check if we need to handle position/rotation offsets var handleOffsets = animator != null && modification.currentValue != null && modification.currentValue.target == s_RecordState.activeRootGameObject.transform && HasOffsets(animTrack, s_TrackRecorder.recordClip); if (handleOffsets) { toProcess = HandleEulerModifications(animTrack, s_TrackRecorder.recordClip, clip, s_RecordState.currentFrame * clip.frameRate, toProcess); RemoveOffsets(modification, animTrack, s_TrackRecorder.recordClip, toProcess); } var remaining = AnimationRecording.Process(s_RecordState, toProcess); if (remaining != null && remaining.Length != 0) { s_UnprocessedMods.AddRange(remaining); } if (handleOffsets) { ReapplyOffsets(modification, animTrack, s_TrackRecorder.recordClip, toProcess); } s_TrackRecorder.FinializeTrack(track, state); IsRecordingAnimationTrack = false; } else { s_UnprocessedMods.Add(modification); } } s_TrackRecorder.FinalizeRecording(state); return(s_UnprocessedMods.ToArray()); }