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; }
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; } }