public SynchronizeObject(Animation animation, AnimationClip clip) { this.animation = animation; gameObject = animation.gameObject; transformPoseSave = new TransformPoseSave(gameObject); blendShapeWeightSave = new BlendShapeWeightSave(gameObject); animationClipValueSave = new AnimationClipValueSave(gameObject, clip); this.clip = clip; }
public SynchronizeObject(Animator animator, AnimationClip clip) { this.animator = animator; gameObject = animator.gameObject; transformPoseSave = new TransformPoseSave(gameObject); blendShapeWeightSave = new BlendShapeWeightSave(gameObject); animationClipValueSave = new AnimationClipValueSave(gameObject, clip); this.clip = clip; #if UNITY_2018_3_OR_NEWER #region BuildPlayableGraph { m_PlayableGraph = PlayableGraph.Create("SynchronizeObject." + gameObject.name); m_PlayableGraph.SetTimeUpdateMode(DirectorUpdateMode.Manual); m_AnimationClipPlayable = AnimationClipPlayable.Create(m_PlayableGraph, clip); m_AnimationClipPlayable.SetApplyPlayableIK(false); m_AnimationClipPlayable.SetApplyFootIK(false); { UAnimationClipPlayable uAnimationClipPlayable = new UAnimationClipPlayable(); uAnimationClipPlayable.SetRemoveStartOffset(m_AnimationClipPlayable, true); } Playable rootPlayable = m_AnimationClipPlayable; #if VERYANIMATION_ANIMATIONRIGGING m_VARigBuilder = gameObject.GetComponent <VeryAnimationRigBuilder>(); m_RigBuilder = gameObject.GetComponent <RigBuilder>(); if (m_VARigBuilder != null && m_RigBuilder != null) { m_VARigBuilder.StartPreview(); m_RigBuilder.StartPreview(); rootPlayable = m_VARigBuilder.BuildPreviewGraph(m_PlayableGraph, rootPlayable); rootPlayable = m_RigBuilder.BuildPreviewGraph(m_PlayableGraph, rootPlayable); } #endif if (animator.applyRootMotion) { bool hasRootMotionBone = false; if (animator.isHuman) { hasRootMotionBone = true; } else { UAvatar uAvatar = new UAvatar(); var genericRootMotionBonePath = uAvatar.GetGenericRootMotionBonePath(animator.avatar); hasRootMotionBone = !string.IsNullOrEmpty(genericRootMotionBonePath); } if (hasRootMotionBone) { var uAnimationOffsetPlayable = new UAnimationOffsetPlayable(); m_AnimationOffsetPlayable = uAnimationOffsetPlayable.Create(m_PlayableGraph, transformPoseSave.startLocalPosition, transformPoseSave.startLocalRotation, 1); m_AnimationOffsetPlayable.SetInputWeight(0, 1f); m_PlayableGraph.Connect(rootPlayable, 0, m_AnimationOffsetPlayable, 0); rootPlayable = m_AnimationOffsetPlayable; } { var uAnimationMotionXToDeltaPlayable = new UAnimationMotionXToDeltaPlayable(); m_AnimationMotionXToDeltaPlayable = uAnimationMotionXToDeltaPlayable.Create(m_PlayableGraph); uAnimationMotionXToDeltaPlayable.SetAbsoluteMotion(m_AnimationMotionXToDeltaPlayable, true); m_AnimationMotionXToDeltaPlayable.SetInputWeight(0, 1f); m_PlayableGraph.Connect(rootPlayable, 0, m_AnimationMotionXToDeltaPlayable, 0); rootPlayable = m_AnimationMotionXToDeltaPlayable; } } var playableOutput = AnimationPlayableOutput.Create(m_PlayableGraph, "Animation", animator); playableOutput.SetSourcePlayable(rootPlayable); } #endregion #else animator.enabled = false; //In order to avoid the mysterious behavior where an event is called from "UnityEditor.Handles: DrawCameraImpl", it is invalid except when updating #endif #region Save saveFireEvents = animator.fireEvents; animator.fireEvents = false; #endregion }