示例#1
0
        public void OnGUI(Rect r, GUIStyle background)
        {
            if (Event.current.type == EventType.Repaint)
            {
                #region TimeControl
                {
                    var beforePlaying = uTimeControl.playing;
#if UNITY_2019_1_OR_NEWER
                    var beforeCurrentTime = uTimeControl.currentTime;
                    uTimeControl.Update();
                    if (uTimeControl.playing && uTimeControl.currentTime < beforeCurrentTime)
                    {
                        loopCount++;
                    }
#else
                    uTimeControl.Update();
#endif
                    if (beforePlaying != uTimeControl.playing)
                    {
                        uTimeControl.playing = beforePlaying;
                    }
                }
                #endregion

                {
                    var clip = dg_get_m_SourcePreviewMotion(instance);
                    uTimeControl.loop      = true;
                    uTimeControl.startTime = 0f;
                    uTimeControl.stopTime  = clip.length;
                    dg_set_fps(instance, (int)clip.frameRate);
                    if (!clip.legacy && animator != null)
                    {
                        dg_set_ShowIKOnFeetButton(animator.isHuman && clip.isHumanMotion);

#if UNITY_2019_1_OR_NEWER
                        if (m_PlayableGraph.IsValid())
                        {
                            if (m_AnimationOffsetPlayable.IsValid())
                            {
                                m_UAnimationOffsetPlayable.SetPosition(m_AnimationOffsetPlayable, transformPoseSave.startPosition);
                                m_UAnimationOffsetPlayable.SetRotation(m_AnimationOffsetPlayable, transformPoseSave.startRotation);
                            }
                            m_AnimationClipPlayable.SetApplyFootIK(isIKOnFeet);
                            m_AnimationClipPlayable.SetTime(loopCount * clip.length + uTimeControl.currentTime);
#if VERYANIMATION_ANIMATIONRIGGING
                            if (m_RigBuilder != null && m_RigBuilder.enabled && m_RigBuilder.layers.Count > 0)
                            {
                                m_RigBuilder.UpdatePreviewGraph(m_PlayableGraph);
                            }
#endif
                            m_PlayableGraph.Evaluate();
                        }
#else
                        if (animator.runtimeAnimatorController != null)
                        {
                            AnimationClipSettings animationClipSettings = AnimationUtility.GetAnimationClipSettings(clip);
                            if (m_State != null)
                            {
                                m_State.iKOnFeet = isIKOnFeet;
                            }

                            var normalizedTime = animationClipSettings.stopTime - animationClipSettings.startTime == 0.0 ? 0.0f : (float)((uTimeControl.currentTime - animationClipSettings.startTime) / (animationClipSettings.stopTime - animationClipSettings.startTime));
                            animator.Play(0, 0, normalizedTime);
                            animator.Update(uTimeControl.deltaTime);
                        }
#endif
                    }
                    else if (animation != null)
                    {
                        dg_set_ShowIKOnFeetButton(false);
                        clip.SampleAnimation(gameObject, uTimeControl.currentTime);
                    }
                }
            }

            dg_DoAvatarPreview(r, background);

            if (animator.applyRootMotion && transformPoseSave != null)
            {
                var rect = r;
                rect.yMin  = rect.yMax - 40f;
                rect.yMax -= 15f;
                var invRot = Quaternion.Inverse(transformPoseSave.originalRotation);
                var pos    = invRot * (gameObject.transform.position - transformPoseSave.originalPosition);
                var rot    = (invRot * gameObject.transform.rotation).eulerAngles;
                EditorGUI.DropShadowLabel(rect, string.Format("Root Motion Position {0}\nRoot Motion Rotation {1}", pos, rot));
            }
        }