public static TimelineAnimationUtilities.RigidTransform Inverse(TimelineAnimationUtilities.RigidTransform a)
 {
     TimelineAnimationUtilities.RigidTransform result;
     result.rotation = Quaternion.Inverse(a.rotation);
     result.position = result.rotation * -a.position;
     return(result);
 }
Exemple #2
0
 private void DoManipulators()
 {
     if (!(this.m_EditorClip == null) && this.m_EditorClip.clip != null)
     {
         AnimationPlayableAsset animationPlayableAsset = this.m_EditorClip.clip.asset as AnimationPlayableAsset;
         AnimationTrack         animationTrack         = this.m_EditorClip.clip.parentTrack as AnimationTrack;
         Transform transform = this.GetTransform();
         if (transform != null && animationPlayableAsset != null && this.m_OffsetEditMode != TimelineAnimationUtilities.OffsetEditMode.None && animationTrack != null)
         {
             Vector3    vector     = transform.get_position();
             Quaternion quaternion = transform.get_rotation();
             EditorGUI.BeginChangeCheck();
             if (this.m_OffsetEditMode == TimelineAnimationUtilities.OffsetEditMode.Translation)
             {
                 vector = Handles.PositionHandle(vector, (Tools.get_pivotRotation() != 1) ? quaternion : Quaternion.get_identity());
             }
             else if (this.m_OffsetEditMode == TimelineAnimationUtilities.OffsetEditMode.Rotation)
             {
                 quaternion = Handles.RotationHandle(quaternion, vector);
             }
             if (EditorGUI.EndChangeCheck())
             {
                 TimelineAnimationUtilities.RigidTransform rigidTransform = TimelineAnimationUtilities.UpdateClipOffsets(animationPlayableAsset, animationTrack, transform, vector, quaternion);
                 animationPlayableAsset.position = rigidTransform.position;
                 animationPlayableAsset.rotation = rigidTransform.rotation;
                 this.Reevaluate();
                 base.Repaint();
             }
         }
     }
 }
 public static TimelineAnimationUtilities.RigidTransform Mul(TimelineAnimationUtilities.RigidTransform a, TimelineAnimationUtilities.RigidTransform b)
 {
     TimelineAnimationUtilities.RigidTransform result;
     result.rotation = a.rotation * b.rotation;
     result.position = a.position + a.rotation * b.position;
     return(result);
 }
Exemple #4
0
 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 static void WriteMatchFields(AnimationPlayableAsset asset, TimelineAnimationUtilities.RigidTransform result, MatchTargetFields fields)
        {
            Vector3 position = asset.position;

            position.x     = ((!fields.HasAny(MatchTargetFields.PositionX)) ? position.x : result.position.x);
            position.y     = ((!fields.HasAny(MatchTargetFields.PositionY)) ? position.y : result.position.y);
            position.z     = ((!fields.HasAny(MatchTargetFields.PositionZ)) ? position.z : result.position.z);
            asset.position = position;
            if (fields.HasAny(MatchTargetFieldConstants.Rotation))
            {
                Vector3 eulerAngles  = asset.rotation.get_eulerAngles();
                Vector3 eulerAngles2 = result.rotation.get_eulerAngles();
                eulerAngles.x  = ((!fields.HasAny(MatchTargetFields.RotationX)) ? eulerAngles.x : eulerAngles2.x);
                eulerAngles.y  = ((!fields.HasAny(MatchTargetFields.RotationY)) ? eulerAngles.y : eulerAngles2.y);
                eulerAngles.z  = ((!fields.HasAny(MatchTargetFields.RotationZ)) ? eulerAngles.z : eulerAngles2.z);
                asset.rotation = Quaternion.Euler(eulerAngles);
            }
        }
        public static void MatchPrevious(TimelineClip currentClip, Transform matchPoint, PlayableDirector director)
        {
            MatchTargetFields matchFields = TimelineAnimationUtilities.GetMatchFields(currentClip);

            if (matchFields != MatchTargetFieldConstants.None && !(matchPoint == null))
            {
                double       time         = director.get_time();
                TimelineClip previousClip = TimelineAnimationUtilities.GetPreviousClip(currentClip);
                if (previousClip != null && currentClip != previousClip)
                {
                    AnimationTrack animationTrack  = currentClip.parentTrack as AnimationTrack;
                    double         blendInDuration = currentClip.blendInDuration;
                    currentClip.blendInDuration = 0.0;
                    double blendOutDuration = previousClip.blendOutDuration;
                    previousClip.blendOutDuration = 0.0;
                    director.Stop();
                    animationTrack.RemoveClip(currentClip);
                    director.Play();
                    double num = (currentClip.start <= previousClip.end) ? currentClip.start : previousClip.end;
                    director.set_time(num - 1E-05);
                    director.Evaluate();
                    Vector3    position = matchPoint.get_position();
                    Quaternion rotation = matchPoint.get_rotation();
                    director.Stop();
                    animationTrack.AddClip(currentClip);
                    animationTrack.RemoveClip(previousClip);
                    director.Play();
                    director.set_time(currentClip.start + 1E-05);
                    director.Evaluate();
                    AnimationPlayableAsset asset = currentClip.asset as AnimationPlayableAsset;
                    TimelineAnimationUtilities.RigidTransform result = TimelineAnimationUtilities.UpdateClipOffsets(asset, animationTrack, matchPoint, position, rotation);
                    TimelineAnimationUtilities.WriteMatchFields(asset, result, matchFields);
                    currentClip.blendInDuration   = blendInDuration;
                    previousClip.blendOutDuration = blendOutDuration;
                    director.Stop();
                    animationTrack.AddClip(previousClip);
                    director.Play();
                    director.set_time(time);
                    director.Evaluate();
                }
            }
        }
 public static void UpdateTrackOffset(AnimationTrack track, Transform transform, TimelineAnimationUtilities.RigidTransform offsets)
 {
     if (transform != null && transform.get_parent() != null)
     {
         offsets.position = transform.get_parent().InverseTransformPoint(offsets.position);
         offsets.rotation = Quaternion.Inverse(transform.get_parent().get_rotation()) * offsets.rotation;
         MathUtils.QuaternionNormalize(ref offsets.rotation);
     }
     track.position = offsets.position;
     track.rotation = offsets.rotation;
     track.UpdateClipOffsets();
 }