Exemple #1
0
        public static void Open(MotionController controller)
        {
            // Get existing open window or if none, make a new one:
            EditorMotionWindow window = GetWindow <EditorMotionWindow>(true, "Setup Animations", true);

            window.SetController(controller);
            window.Show();
        }
Exemple #2
0
 void RemoveController()
 {
     m_originalPos = null;
     m_originalRot = null;
     m_controller  = null;
     MotionAsset   = null;
     Clips         = null;
 }
        public void Setup(MotionController controller)
        {
            m_controller = controller;

            if (m_rigidbody == null)
            {
                m_rigidbody = m_controller.GetComponent <Rigidbody>();
            }
            if (m_transform == null)
            {
                m_transform = m_controller.Transform;
            }
        }
Exemple #4
0
 public void Init(MotionController controller,
                  MotionClip source,
                  Transform reference,
                  IgnoreRootMotionOnBone ignore,
                  int samples = 50)
 {
     Clip           = source.Clip;
     Samples        = samples;
     Name           = Clip.name;
     Stationary     = source.Stationary;
     FixFootSkating = source.FixFootSkating;
     m_controller   = controller;
     m_gameObject   = controller.gameObject;
     m_reference    = reference;
     m_ignore       = ignore;
 }
Exemple #5
0
 private void Awake()
 {
     m_controller = GetComponent <MotionController>();
     m_camera     = Camera.main.transform;
 }
Exemple #6
0
 public void SetController(MotionController controller)
 {
     m_controller = controller;
 }
Exemple #7
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;
            }
        }