Example #1
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 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();
                }
            }
        }
        void DoManipulators()
        {
            if (m_EditorClip == null || m_EditorClip.clip == null)
            {
                return;
            }

            AnimationPlayableAsset animationPlayable = m_EditorClip.clip.asset as AnimationPlayableAsset;
            AnimationTrack         track             = m_EditorClip.clip.parentTrack as AnimationTrack;
            Transform transform = GetTransform();

            if (transform != null && animationPlayable != null && m_OffsetEditMode != TimelineAnimationUtilities.OffsetEditMode.None && track != null)
            {
                UndoExtensions.RegisterPlayableAsset(animationPlayable, "Inspector");
                Vector3    position = transform.position;
                Quaternion rotation = transform.rotation;

                EditorGUI.BeginChangeCheck();
                if (m_OffsetEditMode == TimelineAnimationUtilities.OffsetEditMode.Translation)
                {
                    position = Handles.PositionHandle(position, Tools.pivotRotation == PivotRotation.Global ? Quaternion.identity : rotation);
                }
                else if (m_OffsetEditMode == TimelineAnimationUtilities.OffsetEditMode.Rotation)
                {
                    rotation = Handles.RotationHandle(rotation, position);
                }

                if (EditorGUI.EndChangeCheck())
                {
                    var res = TimelineAnimationUtilities.UpdateClipOffsets(animationPlayable, track, transform, position, rotation);
                    animationPlayable.position    = res.position;
                    animationPlayable.eulerAngles = AnimationUtility.GetClosestEuler(res.rotation, animationPlayable.eulerAngles, RotationOrder.OrderZXY);
                    Reevaluate();
                    Repaint();
                }
            }
        }