Beispiel #1
0
        void StartProcess()
        {
            m_idle = false;
            m_controller.IsAnalisisRunning = true;
            m_uiDelay                   = Float.Zero;
            m_progress                  = Float.Zero;
            m_currentAnimation          = -Int.One;
            MotionAsset                 = CreateInstance <MotionAsset>();
            MotionAsset.MotionData      = new MotionData[Clips.Length];
            MotionAsset.MotionCount     = Int.Zero;
            MotionAsset.MovingCount     = Int.Zero;
            MotionAsset.StationaryCount = Int.Zero;

            m_originalPosition = m_controller.Transform.position;
            m_originalRotation = m_controller.Transform.rotation;
            if (m_originalPos == null || m_originalRot == null)
            {
                m_originalPos = new Dictionary <Transform, Vector3>();
                m_originalRot = new Dictionary <Transform, Quaternion>();
                GetChildRecursive(m_controller.gameObject);
            }

            MotionAsset.PoseBaseIndex   = m_selectedPoseBase;
            MotionAsset.AnkleHeelVector = new Vector3[m_controller.Legs.Length];
            MotionAsset.ToeToetipVector = new Vector3[m_controller.Legs.Length];

            // Reset to standing pose, time 0
            for (int i = 0; i < m_controller.Legs.Length; i++)
            {
                Clips[m_selectedPoseBase].Clip.SampleAnimation(m_controller.gameObject, Float.Zero);
                SetupFoot(i);
            }
        }
Beispiel #2
0
 void RemoveController()
 {
     m_originalPos = null;
     m_originalRot = null;
     m_controller  = null;
     MotionAsset   = null;
     Clips         = null;
 }
Beispiel #3
0
        void OnGUI()
        {
            if (m_style == null)
            {
                m_style = new EditorStyle();
                m_style.SetupStyle();
            }

            GUI.enabled = m_idle;
            EditorGUILayout.BeginVertical(m_style.GreyBox);
            m_style.DrawTitleBar("Required component (Motion Controller)");

            if (m_controller == null)
            {
                m_controller = (MotionController)EditorGUILayout.ObjectField(m_controller, typeof(MotionController), true);
            }
            else
            {
                EditorGUILayout.BeginHorizontal();
                GUI.enabled = false;
                EditorGUILayout.ObjectField(m_controller, typeof(MotionController), true);
                GUI.enabled = m_idle;
                if (GUILayout.Button("Unlock"))
                {
                    RemoveController();
                }
                EditorGUILayout.EndHorizontal();
            }

            EditorGUILayout.EndVertical();

            if (m_controller == null)
            {
                Clips              = null;
                m_originalPos      = null;
                m_originalRot      = null;
                m_selectedPoseBase = 0;
                EditorGUILayout.HelpBox("Before setting up animations you must set all the required components, right now you are missing the Motion Controller component.", MessageType.Error);
                return;
            }

            if (!m_controller.Ready)
            {
                Clips = null;
                EditorGUILayout.HelpBox("Before setting up animations you must setup the Root bone and Legs of your Motion Controller.", MessageType.Error);
                return;
            }

            if (m_controller.Animator == null)
            {
                Clips = null;
                EditorGUILayout.HelpBox("The selected MotionController has no Animator component defined.", MessageType.Error);
                return;
            }

            if (m_controller.Animator.runtimeAnimatorController == null)
            {
                Clips = null;
                EditorGUILayout.HelpBox("The selected Animator GameObject has no AnimatorController.", MessageType.Error);
                return;
            }

            m_animator = m_controller.Animator;
            if (m_animator.avatar == null)
            {
                Clips = null;
                EditorGUILayout.HelpBox("The selected Animator GameObject has no Avatar.", MessageType.Error);
                return;
            }

            var rCtrl = m_animator.runtimeAnimatorController;

            if (rCtrl.animationClips == null || rCtrl.animationClips.Length == 0)
            {
                m_list = null;
                EditorGUILayout.HelpBox("AnimatorController has no animations, it should not be empty.", MessageType.Error);
                return;
            }

            m_scrollPos = EditorGUILayout.BeginScrollView(m_scrollPos, false, false);
            EditorGUILayout.BeginVertical(m_style.GreyBox);
            m_style.DrawTitleBar("Animations from Animator Controller");

            if (Clips == null || Clips.Length == 0)
            {
                var clips = rCtrl.animationClips;
                Clips            = new MotionClip[clips.Length];
                m_animationPoses = new string[clips.Length];

                for (int i = 0; i < clips.Length; i++)
                {
                    var clip = clips[i];
                    m_animationPoses[i] = clip.name;

                    var m = new MotionClip()
                    {
                        Clip           = clip,
                        Id             = clip.GetInstanceID(),
                        Name           = clip.name,
                        FixFootSkating = false,
                    };
                    var nm = clip.name.ToLower();
                    if (nm.Contains("stand") || nm.Contains("idle"))
                    {
                        m.Stationary     = true;
                        m.FixFootSkating = true;
                    }

                    if (nm.Contains("walk") || nm.Contains("run") || nm.Contains("sprint") || nm.Contains("strafe"))
                    {
                        m.Stationary = false;
                    }

                    Clips[i] = m;
                }
            }

            m_so.Update();
            m_list.DoLayoutList();
            m_so.ApplyModifiedProperties();

            m_style.DrawTitleBar("Animation analisis");
            m_ignoreRootMotion = (IgnoreRootMotionOnBone)EditorGUILayout.EnumPopup("Ignore Root motion", m_ignoreRootMotion);
            m_selectedPoseBase = EditorGUILayout.Popup("Standing pose", m_selectedPoseBase, m_animationPoses);
            m_samples          = EditorGUILayout.IntSlider("Samples", m_samples, Int.Ten, Int.OneHundred);//EditorGUI.IntSlider(EditorGUILayout.GetControlRect(false, m_progHeight), "Samples", m_samples, Int.Ten, Int.OneHundred);

            if (m_idle)
            {
                if (!Clips[m_selectedPoseBase].Stationary)
                {
                    EditorGUILayout.HelpBox("Selected Standing pose is not Stationary.", MessageType.Error);
                }
                else
                {
                    EditorGUILayout.BeginHorizontal();
                    if (GUILayout.Button("Start analisis"))
                    {
                        StartProcess();
                    }
                    if (MotionAsset == null || MotionAsset.MotionCount == Int.Zero)
                    {
                        GUI.enabled = false;
                    }
                    if (GUILayout.Button("Save data"))
                    {
                        SaveAsset();
                    }

                    GUI.enabled = m_idle;
                    EditorGUILayout.EndHorizontal();
                }
            }
            else
            {
                ProcessAnimation();
                string clipName;
                if (m_currentAnimation > -Int.One)
                {
                    clipName = Clips[m_currentAnimation].Name;
                }
                else
                {
                    clipName = Clips[Int.Zero].Name;
                }

                GUI.enabled = true;
                var prog = m_progress * Float.OneHundred;
                var sts  = prog.ToString("0") + "% " + clipName;
                if (m_progress >= Float.One)
                {
                    EditorGUI.ProgressBar(EditorGUILayout.GetControlRect(false, m_progHeight), m_progress, "Done");
                }
                else
                {
                    EditorGUI.ProgressBar(EditorGUILayout.GetControlRect(false, m_progHeight), m_progress, sts);
                }
            }

            EditorGUILayout.EndVertical();
            EditorGUILayout.EndScrollView();

            if (!m_idle && (m_uiDelay != m_lastUIDelay))
            {
                m_lastUIDelay = m_uiDelay;
                Repaint();
            }

            if (!m_idle && m_currentAnimation == (Clips.Length - Int.One))
            {
                m_uiDelay += Float.DotOne;
                if (m_uiDelay < Float.One)
                {
                    return;
                }

                m_idle = true;
                FinishAnalisis();
                SaveAsset();
                return;
            }

            if (m_reset)
            {
                MotionAsset = null;
                m_reset     = false;
            }
        }