public static IEnumerable <GameObject> GetRecordableGameObjects(WindowState state) { if (state == null || state.editSequence.asset == null || state.editSequence.director == null) { yield break; } var outputTracks = state.editSequence.asset.GetOutputTracks(); foreach (var track in outputTracks) { if (track.GetType() != typeof(AnimationTrack)) { continue; } if (!state.IsTrackRecordable(track) && !track.GetChildTracks().Any(state.IsTrackRecordable)) { continue; } var obj = TimelineUtility.GetSceneGameObject(state.editSequence.director, track); if (obj != null) { yield return(obj); } } }
public GameObject GetSceneReference(TrackAsset asset) { if (editSequence.director == null) return null; // no player bound return TimelineUtility.GetSceneGameObject(editSequence.director, asset); }
public override bool Execute(IEnumerable <TimelineClip> clips) { var clip = clips.FirstOrDefault(); if (clip != null && (clip.curves != null || clip.animationClip != null)) { var clipToEdit = clip.animationClip != null ? clip.animationClip : clip.curves; if (clipToEdit == null) { return(false); } GameObject gameObject = null; if (TimelineEditor.inspectedDirector != null) { gameObject = TimelineUtility.GetSceneGameObject(TimelineEditor.inspectedDirector, clip.parentTrack); } var timeController = TimelineAnimationUtilities.CreateTimeController(clip); TimelineAnimationUtilities.EditAnimationClipWithTimeController( clipToEdit, timeController, clip.animationClip != null ? gameObject : null); return(true); } return(false); }
public override string ModifyPropertyDisplayName(string path, string propertyName) { if (!AnimatedPropertyUtility.IsMaterialProperty(propertyName)) { return(propertyName); } var track = m_ClipGUI.clip.GetParentTrack(); if (track == null) { return(propertyName); } var gameObjectBinding = TimelineUtility.GetSceneGameObject(TimelineEditor.inspectedDirector, track); if (gameObjectBinding == null) { return(propertyName); } if (!string.IsNullOrEmpty(path)) { var transform = gameObjectBinding.transform.Find(path); if (transform == null) { return(propertyName); } gameObjectBinding = transform.gameObject; } return(AnimatedPropertyUtility.RemapMaterialName(gameObjectBinding, propertyName)); }
private static string GetTrackDisplayName(TrackAsset track, TimelineWindow.TimelineState state) { string result; if (track == null) { result = ""; } else { string name = track.get_name(); if (track.get_name().StartsWith(track.GetType().Name)) { if (state.currentDirector != null) { GameObject sceneGameObject = TimelineUtility.GetSceneGameObject(state.currentDirector, track); if (sceneGameObject != null) { name = sceneGameObject.get_name(); } } } result = name; } return(result); }
private void DoOffsetManipulator() { if (base.get_targets().Length <= 1) { if (!(base.timelineWindow == null) && base.timelineWindow.state != null && !(base.timelineWindow.state.currentDirector == null)) { AnimationTrack animationTrack = base.get_target() as AnimationTrack; if (animationTrack != null && animationTrack.applyOffsets && this.m_OffsetEditMode != TimelineAnimationUtilities.OffsetEditMode.None) { GameObject sceneGameObject = TimelineUtility.GetSceneGameObject(base.timelineWindow.state.currentDirector, animationTrack); Transform transform = (!(sceneGameObject != null)) ? null : sceneGameObject.get_transform(); TimelineAnimationUtilities.RigidTransform trackOffsets = TimelineAnimationUtilities.GetTrackOffsets(animationTrack, transform); EditorGUI.BeginChangeCheck(); TimelineAnimationUtilities.OffsetEditMode offsetEditMode = this.m_OffsetEditMode; if (offsetEditMode != TimelineAnimationUtilities.OffsetEditMode.Translation) { if (offsetEditMode == TimelineAnimationUtilities.OffsetEditMode.Rotation) { trackOffsets.rotation = Handles.RotationHandle(trackOffsets.rotation, trackOffsets.position); } } else { trackOffsets.position = Handles.PositionHandle(trackOffsets.position, (Tools.get_pivotRotation() != 1) ? trackOffsets.rotation : Quaternion.get_identity()); } if (EditorGUI.EndChangeCheck()) { TimelineAnimationUtilities.UpdateTrackOffset(animationTrack, transform, trackOffsets); this.Evaluate(); base.Repaint(); } } } } }
private Animator GetAnimator() { Animator result; if (this.m_PreviousAnimator != null) { result = this.m_PreviousAnimator; } else { TrackAsset trackAsset = base.get_target() as TrackAsset; if (trackAsset != null && base.timelineWindow.state != null && base.timelineWindow.state.currentDirector != null) { GameObject sceneGameObject = TimelineUtility.GetSceneGameObject(base.timelineWindow.state.currentDirector, trackAsset); if (sceneGameObject != null && sceneGameObject.get_transform() != null) { Animator component = sceneGameObject.get_transform().GetComponent <Animator>(); this.m_PreviousAnimator = component; if (component != null) { result = component; return(result); } } } result = null; } return(result); }
static bool IsValidClip(TimelineClip clip, PlayableDirector director) { return(clip != null && clip.GetParentTrack() != null && (clip.asset as AnimationPlayableAsset) != null && clip.GetParentTrack().clips.Any(x => x.start > clip.start) && TimelineUtility.GetSceneGameObject(director, clip.GetParentTrack()) != null); }
// Gets the appropriate track for a given game object static TrackAsset GetTrackForGameObject(GameObject gameObject, WindowState state) { if (gameObject == null) { return(null); } var director = state.editSequence.director; if (director == null) { return(null); } var level = int.MaxValue; TrackAsset result = null; // search the output tracks var outputTracks = state.editSequence.asset.flattenedTracks; foreach (var track in outputTracks) { if (track.GetType() != typeof(AnimationTrack)) { continue; } if (!state.IsTrackRecordable(track)) { continue; } var obj = TimelineUtility.GetSceneGameObject(director, track); if (obj != null) { // checks if the effected gameobject is our child var childLevel = GetChildLevel(obj, gameObject); if (childLevel != -1 && childLevel < level) { result = track; level = childLevel; } } } // the resulting track is not armed. checking here avoids accidentally recording objects with their own // tracks if (result && !state.IsTrackRecordable(result)) { result = null; } return(result); }
internal static void MatchClipsToNext(ITimelineState state, TimelineClip[] clips) { if (AnimationOffsetMenu.EnforcePreviewMode(state)) { clips = (from x in clips orderby x.start descending select x).ToArray <TimelineClip>(); TimelineClip[] array = clips; for (int i = 0; i < array.Length; i++) { TimelineClip timelineClip = array[i]; TimelineUndo.PushUndo(timelineClip.asset, "Match Clip"); GameObject sceneGameObject = TimelineUtility.GetSceneGameObject(state.currentDirector, timelineClip.parentTrack); TimelineAnimationUtilities.MatchNext(timelineClip, sceneGameObject.get_transform(), state.currentDirector); } } }
/// <summary> /// Determines whether the Timeline window can enable recording mode on an AnimationTrack. /// For a track to support recording, it needs to have a valid scene binding, /// its offset mode should not be Auto and needs to be currently visible in the Timeline Window. /// </summary> /// <param name="track">The track to query.</param> /// <returns>True if recording can start, False otherwise.</returns> public static bool CanStartRecording(this AnimationTrack track) { if (track == null) { throw new ArgumentNullException(nameof(track)); } if (TimelineEditor.state == null) { return(false); } var director = TimelineEditor.inspectedDirector; var animTrack = TimelineUtility.GetSceneReferenceTrack(track) as AnimationTrack; return(animTrack != null && animTrack.trackOffset != TrackOffset.Auto && TimelineEditor.inspectedAsset == animTrack.timelineAsset && director != null && TimelineUtility.GetSceneGameObject(director, animTrack) != null); }
void DoOffsetManipulator() { if (targets.Length > 1) //do not edit the track offset on a multiple selection { return; } if (timelineWindow == null || timelineWindow.state == null || timelineWindow.state.editSequence.director == null) { return; } AnimationTrack animationTrack = target as AnimationTrack; if (animationTrack != null && (animationTrack.trackOffset == TrackOffset.ApplyTransformOffsets) && m_OffsetEditMode != TimelineAnimationUtilities.OffsetEditMode.None) { var boundObject = TimelineUtility.GetSceneGameObject(timelineWindow.state.editSequence.director, animationTrack); var boundObjectTransform = boundObject != null ? boundObject.transform : null; var offsets = TimelineAnimationUtilities.GetTrackOffsets(animationTrack, boundObjectTransform); EditorGUI.BeginChangeCheck(); switch (m_OffsetEditMode) { case TimelineAnimationUtilities.OffsetEditMode.Translation: offsets.position = Handles.PositionHandle(offsets.position, (Tools.pivotRotation == PivotRotation.Global) ? Quaternion.identity : offsets.rotation); break; case TimelineAnimationUtilities.OffsetEditMode.Rotation: offsets.rotation = Handles.RotationHandle(offsets.rotation, offsets.position); break; } if (EditorGUI.EndChangeCheck()) { UndoExtensions.RegisterTrack(animationTrack, L10n.Tr("Inspector")); TimelineAnimationUtilities.UpdateTrackOffset(animationTrack, boundObjectTransform, offsets); Evaluate(); Repaint(); } } }
public static void ComputeClipWorldSpaceOffset(PlayableDirector director, TimelineClip clip, out Vector3 clipPositionOffset, out Quaternion clipRotationOffset) { GameObject sceneGameObject = TimelineUtility.GetSceneGameObject(director, clip.parentTrack); double time = director.get_time(); TrackAsset parentTrack = clip.parentTrack; TimelineClip[] clips = parentTrack.clips; director.Stop(); for (int i = 0; i < clips.Length; i++) { parentTrack.RemoveClip(clips[i]); } parentTrack.AddClip(clip); double start = clip.start; double blendInDuration = clip.blendInDuration; clip.blendInDuration = 0.0; clip.start = 1.0; director.Play(); director.set_time(0.0); director.Evaluate(); clipPositionOffset = sceneGameObject.get_transform().get_position(); clipRotationOffset = sceneGameObject.get_transform().get_rotation(); AnimationPlayableAsset animationPlayableAsset = clip.asset as AnimationPlayableAsset; if (!(animationPlayableAsset == null)) { clipPositionOffset += clipRotationOffset * animationPlayableAsset.position; clipRotationOffset *= animationPlayableAsset.rotation; director.Stop(); clip.start = start; clip.blendInDuration = blendInDuration; parentTrack.RemoveClip(clip); for (int j = 0; j < clips.Length; j++) { parentTrack.AddClip(clips[j]); } director.Play(); director.set_time(time); director.Evaluate(); } }
internal static void MatchClipsToNext(TimelineClip[] clips) { if (!EnforcePreviewMode()) { return; } clips = clips.OrderByDescending(x => x.start).ToArray(); foreach (var clip in clips) { var sceneObject = TimelineUtility.GetSceneGameObject(TimelineEditor.inspectedDirector, clip.GetParentTrack()); if (sceneObject != null) { TimelineAnimationUtilities.MatchNext(clip, sceneObject.transform, TimelineEditor.inspectedDirector); } } InspectorWindow.RepaintAllInspectors(); TimelineEditor.Refresh(RefreshReason.ContentsModified); }
Transform GetTransform() { if (m_Binding != null) { return(m_Binding.transform); } if (m_TimelineWindow != null && m_TimelineWindow.state != null && m_TimelineWindow.state.editSequence.director != null && m_EditorClip != null && m_EditorClip.clip != null) { var obj = TimelineUtility.GetSceneGameObject(m_TimelineWindow.state.editSequence.director, m_EditorClip.clip.parentTrack); m_Binding = obj; if (obj != null) { return(obj.transform); } } return(null); }
internal static void MatchClipsToNext(WindowState state, TimelineClip[] clips) { if (!EnforcePreviewMode(state)) { return; } clips = clips.OrderByDescending(x => x.start).ToArray(); foreach (var clip in clips) { var sceneObject = TimelineUtility.GetSceneGameObject(state.editSequence.director, clip.parentTrack); if (sceneObject != null) { TimelineUndo.PushUndo(clip.asset, "Match Clip"); TimelineAnimationUtilities.MatchNext(clip, sceneObject.transform, state.editSequence.director); } } InspectorWindow.RepaintAllInspectors(); TimelineEditor.Refresh(RefreshReason.ContentsModified); }
public static void ComputeTrackOffsets(PlayableDirector director, TimelineClip clip, out Vector3 parentPositionOffset, out Quaternion parentRotationOffset, out Vector3 positionOffset, out Quaternion rotationOffset) { GameObject sceneGameObject = TimelineUtility.GetSceneGameObject(director, clip.parentTrack); double time = director.get_time(); TrackAsset parentTrack = clip.parentTrack; TimelineClip[] clips = parentTrack.clips; director.Stop(); for (int i = 0; i < clips.Length; i++) { parentTrack.RemoveClip(clips[i]); } parentTrack.AddClip(clip); double start = clip.start; double blendInDuration = clip.blendInDuration; clip.blendInDuration = 0.0; clip.start = 1.0; director.Play(); director.set_time(1.0); director.Evaluate(); positionOffset = sceneGameObject.get_transform().get_position(); rotationOffset = sceneGameObject.get_transform().get_rotation(); director.set_time(0.0); director.Evaluate(); parentPositionOffset = sceneGameObject.get_transform().get_position(); parentRotationOffset = sceneGameObject.get_transform().get_rotation(); director.Stop(); clip.start = start; clip.blendInDuration = blendInDuration; parentTrack.RemoveClip(clip); for (int j = 0; j < clips.Length; j++) { parentTrack.AddClip(clips[j]); } director.Play(); director.set_time(time); director.Evaluate(); }
public static bool Do(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); } GameObject gameObject = null; if (TimelineEditor.inspectedDirector != null) { gameObject = TimelineUtility.GetSceneGameObject(TimelineEditor.inspectedDirector, track); } var timeController = TimelineAnimationUtilities.CreateTimeController(CreateTimeControlClipData(track)); TimelineAnimationUtilities.EditAnimationClipWithTimeController(clipToEdit, timeController, gameObject); return(true); }
public override bool Execute(IEnumerable <TimelineClip> clips) { TimelineClip clip; AnimationClip clipToEdit; if (!GetEditableClip(clips, out clip, out clipToEdit)) { return(false); } GameObject gameObject = null; if (TimelineEditor.inspectedDirector != null) { gameObject = TimelineUtility.GetSceneGameObject(TimelineEditor.inspectedDirector, clip.parentTrack); } var timeController = TimelineAnimationUtilities.CreateTimeController(clip); TimelineAnimationUtilities.EditAnimationClipWithTimeController( clipToEdit, timeController, clip.animationClip != null ? gameObject : null); return(true); }
private Transform GetTransform() { Transform result; if (this.m_Binding != null) { result = this.m_Binding.get_transform(); } else { if (this.m_TimelineWindow != null && this.m_TimelineWindow.state != null && this.m_TimelineWindow.state.currentDirector != null && this.m_EditorClip != null && this.m_EditorClip.clip != null) { GameObject sceneGameObject = TimelineUtility.GetSceneGameObject(this.m_TimelineWindow.state.currentDirector, this.m_EditorClip.clip.parentTrack); this.m_Binding = sceneGameObject; if (sceneGameObject != null) { result = sceneGameObject.get_transform(); return(result); } } result = null; } return(result); }
static HashSet <double> GetKeyTimes(IList <PropertyModification> modifications, WindowState state) { var keyTimes = new HashSet <double>(); AnimationClip animationClip; double keyTime; bool inRange; var component = modifications[0].target as Component; var target = modifications[0].target; if (component != null) { var track = GetTrackForGameObject(component.gameObject, state); var go = TimelineUtility.GetSceneGameObject(TimelineEditor.inspectedDirector, track); if (go != null) { target = go.transform; } } GetClipAndRelativeTime(target, state, out animationClip, out keyTime, out inRange); if (animationClip == null) { return(keyTimes); } var playableAsset = target as IPlayableAsset; var info = AnimationClipCurveCache.Instance.GetCurveInfo(animationClip); TimelineClip clip = null; if (component != null) { GetTrackForGameObject(component.gameObject, state).FindRecordingClipAtTime(state.editSequence.time, out clip); } else if (playableAsset != null) { clip = FindClipWithAsset(state.editSequence.asset, playableAsset); } foreach (var mod in modifications) { EditorCurveBinding temp; if (HasBinding(target, mod, animationClip, out temp)) { IEnumerable <double> keys = new HashSet <double>(); if (temp.isPPtrCurve) { var curve = info.GetObjectCurveForBinding(temp); if (curve != null) { keys = curve.Select(x => (double)x.time); } } else { var curve = info.GetCurveForBinding(temp); if (curve != null) { keys = curve.keys.Select(x => (double)x.time); } } // Transform the times in to 'global' space using the clip if (clip != null) { foreach (var k in keys) { var time = clip.FromLocalTimeUnbound(k); const double eps = 1e-5; if (time >= clip.start - eps && time <= clip.end + eps) { keyTimes.Add(time); } } } // infinite clip mode, global == local space else { keyTimes.UnionWith(keys); } } } return(keyTimes); }