public static void SetData(MxMAnimationIdleSet a_data)
        {
            if (a_data != null)
            {
                m_data = a_data;

                m_data.VerifyData();

                m_soData = new SerializedObject(m_data);

                m_spPrimaryClip     = m_soData.FindProperty("PrimaryClip");
                m_spSecondaryClips  = m_soData.FindProperty("SecondaryClips");
                m_spTransitionClips = m_soData.FindProperty("TransitionClips");
                m_spTags            = m_soData.FindProperty("Tags");
                m_spFavourTags      = m_soData.FindProperty("FavourTags");
                m_spMinLoops        = m_soData.FindProperty("MinLoops");
                m_spMaxLoops        = m_soData.FindProperty("MaxLoops");

                m_spTargetPreProcessData  = m_soData.FindProperty("m_targetPreProcessData");
                m_spTargetAnimationModule = m_soData.FindProperty("m_targetAnimModule");

                MxMSettings settings = MxMSettings.Instance();
                if (settings != null)
                {
                    settings.ActiveIdleSet = a_data;
                }

                if (MxMTaggingWindow.Exists())
                {
                    MxMTaggingWindow.Inst().SetTarget(a_data);
                }
            }
        }
        public static void SetData(MxMAnimationClipComposite a_data)
        {
            if (a_data != null)
            {
                m_data = a_data;
                m_data.VerifyData();

                m_data.GenerateRootLookupTable();

                m_soData = new SerializedObject(m_data);

                m_spPrimaryClip = m_soData.FindProperty("PrimaryClip");
                m_spBeforeClips = m_soData.FindProperty("BeforeClips");
                m_spAfterClips  = m_soData.FindProperty("AfterClips");

                m_spLooping               = m_soData.FindProperty("Looping");
                m_spIgnoreEdges           = m_soData.FindProperty("IgnoreEdges");
                m_spExtrapolateTrajectory = m_soData.FindProperty("ExtrapolateTrajectory");
                m_spFlattenTrajectory     = m_soData.FindProperty("FlattenTrajectory");
                m_spRuntimeSplicing       = m_soData.FindProperty("RuntimeSplicing");

                m_spGlobalTags       = m_soData.FindProperty("GlobalTags");
                m_spGlobalFavourTags = m_soData.FindProperty("GlobalFavourTags");
                m_spTagTracks        = m_soData.FindProperty("TagTracks");
                m_spEvents           = m_soData.FindProperty("Events");

                m_spTargetPreProcessData = m_soData.FindProperty("m_targetPreProcessData");
                m_spTargetAnimModule     = m_soData.FindProperty("m_targetAnimModule");
                m_spTargetPrefab         = m_soData.FindProperty("m_targetPrefab");

                if (m_spTargetPreProcessData.objectReferenceValue != null)
                {
                    if (m_spTargetPrefab.objectReferenceValue == null)
                    {
                        SerializedProperty spTargetPrefab = m_spTargetPreProcessData.FindPropertyRelative("m_targetPrefab");

                        if (spTargetPrefab != null && spTargetPrefab.objectReferenceValue != null)
                        {
                            m_spTargetPrefab.objectReferenceValue = spTargetPrefab.objectReferenceValue;
                            m_soData.ApplyModifiedPropertiesWithoutUndo();
                        }
                    }
                }

                MxMSettings settings = MxMSettings.Instance();
                if (settings != null)
                {
                    settings.ActiveComposite = a_data;
                }

                if (MxMTaggingWindow.Exists())
                {
                    MxMTaggingWindow.Inst().SetTarget(a_data);
                }
            }
        }
        private void NextComposite()
        {
            MxMPreProcessData preProcessData = m_spTargetPreProcessData.objectReferenceValue as MxMPreProcessData;
            AnimationModule   animModule     = m_spTargetAnimModule.objectReferenceValue as AnimationModule;

            List <MxMAnimationClipComposite> compList = null;

            if (preProcessData != null)
            {
                compList = preProcessData.GetCompositeCategoryList(m_data.CategoryId);
            }
            else if (animModule != null)
            {
                compList = animModule.GetCompositeCategoryList(m_data.CategoryId);
            }

            if (compList != null)
            {
                for (int i = 0; i < compList.Count; ++i)
                {
                    if (compList[i] == m_data)
                    {
                        if (i < compList.Count - 1)
                        {
                            compList[i + 1].ValidateBaseData();
                            SetData(compList[i + 1]);
                        }
                        else
                        {
                            compList[0].ValidateBaseData();
                            SetData(compList[0]);
                        }

                        if (MxMTaggingWindow.Exists())
                        {
                            MxMTaggingWindow.Inst().ClipChanged();
                        }

                        break;
                    }
                }
            }
        }
        public void OnDeleteEventMarker(object a_eventObj)
        {
            if (a_eventObj == null)
                return;

            EventMarker eventMarker = a_eventObj as EventMarker;

            for (int i = 0; i < Events.Count; ++i)
            {
                if (eventMarker == Events[i])
                {
                    Undo.RecordObject(this, "Delete Event");
                    Events.Remove(eventMarker);
                    MxMTaggingWindow.Inst().Repaint();
                    MxMTaggingWindow.Inst().QueueDeselectEventAction();
                    break;
                }
            }
        }
        public static void ShowWindow()
        {
            m_compositeWindow  = MxMAnimationClipCompositeWindow.Inst();
            m_idleSetWindow    = MxMAnimationIdleSetWindow.Inst();
            m_blendSpaceWindow = MxMBlendSpaceWindow.Inst();

            System.Type sceneType = System.Type.GetType("UnityEditor.SceneView, UnityEditor.dll");
            System.Type gameType  = System.Type.GetType("UnityEditor.GameView, UnityEditor.dll");

            var dockTypes = new System.Type[] { typeof(MxMAnimationIdleSetWindow), typeof(MxMBlendSpaceWindow),
                                                sceneType, gameType };

            EditorWindow editorWindow = EditorWindow.GetWindow <MxMAnimConfigWindow>("MxM Anim Config",
                                                                                     true, dockTypes);

            editorWindow.minSize = new Vector2(100f, 50f);
            editorWindow.Show();

            m_inst = (MxMAnimConfigWindow)editorWindow;

            MxMTaggingWindow.ShowWindow();
        }
        //============================================================================================

        /**
         *  @brief Copy constructor
         *
         *********************************************************************************************/
        public void DrawEvent(Rect _trackRect, float _zoom, MxMTaggingWindow _taggingWindow, IMxMAnim a_mxmAnim)
        {
            Texture markerIcon = EditorGUIUtility.IconContent("Animation.EventMarker").image;

            if (m_selected)
            {
                Handles.BeginGUI();
                Handles.color = Color.green;

                Vector3 start = new Vector3(EventTime * 75f * _zoom - (markerIcon.width / 2f),
                                            _trackRect.y + markerIcon.height / 2f, 0f);
                Vector3 end  = new Vector3(start.x - Actions[0] * 75f * _zoom + markerIcon.width / 2f, start.y, 0f);
                Vector3 up   = new Vector3(end.x, end.y - markerIcon.height / 4f);
                Vector3 down = new Vector3(up.x, up.y + markerIcon.height / 2f);

                Handles.DrawLine(start, end);
                Handles.DrawLine(up, down);

                start = end;
                end   = new Vector3(start.x - Windup * 75f * _zoom, start.y, 0f);
                up.x  = down.x = end.x;

                Handles.color = Color.blue;
                Handles.DrawLine(start, end);
                Handles.DrawLine(up, down);

                start = new Vector3(EventTime * 75f * _zoom + (markerIcon.width / 2f),
                                    _trackRect.y + markerIcon.height / 2f, 0f);

                Handles.color = Color.green;
                for (int i = 1; i < Actions.Count; ++i)
                {
                    float markerWidth = 0;

                    if (i == 1)
                    {
                        markerWidth = markerIcon.width / 2f;
                    }

                    end  = new Vector3(start.x + Actions[i] * 75f * _zoom - markerWidth, start.y, 0f);
                    up.x = down.x = end.x;

                    Handles.DrawLine(start, end);
                    Handles.DrawLine(up, down);

                    //Draw a circle maybe

                    start = end;
                }

                end  = new Vector3(start.x + FollowThrough * 75f * _zoom - markerIcon.width / 2f, start.y, 0f);
                up.x = down.x = end.x;

                Handles.color = Color.red;
                Handles.DrawLine(start, end);
                Handles.DrawLine(up, down);

                start = end;
                end   = new Vector3(start.x + Recovery * 75f * _zoom, start.y, 0f);
                up.x  = down.x = end.x;

                Handles.color = Color.yellow;
                Handles.DrawLine(start, end);
                Handles.DrawLine(up, down);

                Handles.EndGUI();
            }

            Rect markerRect = new Rect(EventTime * 75f * _zoom - (markerIcon.width / 2f), _trackRect.y,
                                       markerIcon.width, markerIcon.height);

            GUI.DrawTexture(markerRect, markerIcon);

            if (m_selected)
            {
                GUI.DrawTexture(markerRect, EditorUtil.EditorFunctions.GetHighlightTex());
            }

            Event evt = Event.current;

            markerRect.x     -= 3f;
            markerRect.height = _trackRect.height;
            markerRect.width += 6f;

            if (evt.isMouse)
            {
                if (evt.button == 0)
                {
                    switch (evt.type)
                    {
                    case EventType.MouseDown:
                    {
                        if (markerRect.Contains(evt.mousePosition))
                        {
                            m_selected = true;
                            m_dragging = true;
                            _taggingWindow.SelectEvent(this, EventTime);
                            evt.Use();
                        }
                    }
                    break;

                    case EventType.MouseUp:
                    {
                        m_dragging = false;
                    }
                    break;

                    case EventType.MouseDrag:
                    {
                        if (m_dragging && m_selected)
                        {
                            float desiredValueDelta = ((evt.delta.x / _zoom)) / 75f;

                            EventTime += desiredValueDelta;

                            EventTime = Mathf.Clamp(EventTime, 0f,
                                                    _taggingWindow.TargetClip.length);

                            _taggingWindow.Modified(EventTime);

                            evt.Use();
                        }
                    }
                    break;
                    }
                }
                else if (evt.button == 1)
                {
                    //Begin Context menu
                    GenericMenu menu = new GenericMenu();

                    menu.AddItem(new GUIContent("Delete"), false, a_mxmAnim.OnDeleteEventMarker, this);
                    menu.ShowAsContext();
                }
            }
        }
Beispiel #7
0
        //============================================================================================

        /**
         *  @brief Draws and manages all the tags within the track along a GUI track in the editor
         *
         *  @param [Rect] _trackRect - the rect of the track to draw them on
         *  @param [float] _scrollValueX - the scroll value of the scroll viewEditorUtil.EditorFunctions.GetHighlightTex()
         *  @param [float] _zoom - tyhe zoom value of the
         *
         *********************************************************************************************/
        public bool DrawTags(Rect _trackRect, float _zoom, MxMTaggingWindow _taggingWindow)
        {
            bool ret = false;

            Texture markerIcon = EditorGUIUtility.IconContent("blendKey").image;
            Texture selectIcon = EditorGUIUtility.IconContent("curvekeyframe").image;

            Event evt = Event.current;

            for (int i = 0; i < m_tags.Count; ++i)
            {
                Vector2 tag = m_tags[i];

                float startX = (tag.x * 75f) * _zoom;
                float endX   = (tag.y * 75f) * _zoom;

                Color baseColor = GUI.color;

                if (EditorGUIUtility.isProSkin)
                {
                    GUI.color = Color.black;
                }

                Rect barRect = new Rect(startX, _trackRect.y + 7f, endX - startX, 5f);
                GUI.Box(barRect, "");
                GUI.color = baseColor;

                if (m_selectId == i && m_selectType == TagSelectType.All)
                {
                    GUI.DrawTexture(barRect, EditorUtil.EditorFunctions.GetHighlightTex());
                }

                barRect       = _trackRect;
                barRect.x     = startX + markerIcon.width / 2f;
                barRect.width = endX - startX - markerIcon.width;

                startX -= markerIcon.width / 2f;
                endX   -= markerIcon.width / 2f;

                Rect leftRect = new Rect(startX, _trackRect.y + 3f,
                                         markerIcon.width, markerIcon.height);

                Rect rightRect = new Rect(endX, _trackRect.y + 3f,
                                          markerIcon.width, markerIcon.height);

                if (startX > -markerIcon.width &&
                    startX < _trackRect.width + markerIcon.width)
                {
                    GUI.DrawTexture(leftRect, markerIcon);

                    if (m_selectId == i && (m_selectType == TagSelectType.Left ||
                                            m_selectType == TagSelectType.All))
                    {
                        GUI.DrawTexture(leftRect, selectIcon);
                    }
                }
                if (endX > -markerIcon.width &&
                    endX < _trackRect.width + markerIcon.width)
                {
                    GUI.DrawTexture(rightRect, markerIcon);
                    if (m_selectId == i && (m_selectType == TagSelectType.Right ||
                                            m_selectType == TagSelectType.All))
                    {
                        GUI.DrawTexture(rightRect, selectIcon);
                    }
                }

                //Selection and moving
                if (evt.isMouse && evt.button == 0)
                {
                    switch (evt.type)
                    {
                    case EventType.MouseDown:
                    {
                        if (barRect.Contains(evt.mousePosition))
                        {
                            m_selectId         = i;
                            m_selectType       = TagSelectType.All;
                            ret                = true;
                            m_draggingSelected = true;
                            _taggingWindow.SetTime(m_tags[m_selectId].x);
                        }
                        else if (leftRect.Contains(evt.mousePosition))
                        {
                            m_selectId         = i;
                            m_selectType       = TagSelectType.Left;
                            ret                = true;
                            m_draggingSelected = true;
                            _taggingWindow.SetTime(m_tags[m_selectId].x);
                        }
                        else if (rightRect.Contains(evt.mousePosition))
                        {
                            m_selectId         = i;
                            m_selectType       = TagSelectType.Right;
                            ret                = true;
                            m_draggingSelected = true;

                            _taggingWindow.SetTime(m_tags[m_selectId].y);
                        }
                    }
                    break;

                    case EventType.MouseUp:
                    {
                        m_draggingSelected = false;
                    }
                    break;

                    case EventType.MouseDrag:
                    {
                        if (m_draggingSelected && m_selectId == i)
                        {
                            float desiredValueDelta = ((evt.delta.x / _zoom)) / 75f;

                            Vector2 selected = m_tags[m_selectId];

                            switch (m_selectType)
                            {
                            case TagSelectType.All:
                            {
                                selected.x += desiredValueDelta;
                                selected.y += desiredValueDelta;

                                if (selected.x < 0f)
                                {
                                    selected.y -= selected.x;
                                    selected.x -= selected.x;
                                }

                                if (selected.y > m_clipLength)
                                {
                                    selected.x -= (selected.y - m_clipLength);
                                    selected.y -= (selected.y - m_clipLength);
                                }

                                _taggingWindow.Modified(selected.x);
                            }
                            break;

                            case TagSelectType.Left:
                            {
                                selected.x += desiredValueDelta;
                                selected.x  = Mathf.Clamp(selected.x, 0f, selected.y - 0.1f);
                                _taggingWindow.Modified(selected.x);
                            }
                            break;

                            case TagSelectType.Right:
                            {
                                selected.y += desiredValueDelta;
                                selected.y  = Mathf.Clamp(selected.y, selected.x + 0.1f, m_clipLength);
                                _taggingWindow.Modified(selected.y);
                            }
                            break;
                            }

                            m_tags[m_selectId] = selected;
                        }
                    }
                    break;
                    }
                }
            }
            return(ret);
        }
        //===========================================================================================

        /**
         *  @brief
         *
         *********************************************************************************************/
        public static void SetData(MxMBlendSpace a_data)
        {
            if (a_data == null)
            {
                return;
            }

            m_data = a_data;
            m_data.VerifyData();

            m_soData = new SerializedObject(m_data);

            m_spClips                = m_soData.FindProperty("m_clips");
            m_spPositions            = m_soData.FindProperty("m_positions");
            m_spNormalizeTime        = m_soData.FindProperty("m_normalizeTime");
            m_spTargetPreProcessData = m_soData.FindProperty("m_targetPreProcessData");
            m_spTargetAnimModule     = m_soData.FindProperty("m_targetAnimModule");
            m_spTargetPrefab         = m_soData.FindProperty("m_targetPrefab");
            m_spMagnitude            = m_soData.FindProperty("m_magnitude");
            m_spSmoothing            = m_soData.FindProperty("m_smoothing");
            m_spGlobalTags           = m_soData.FindProperty("GlobalTags");
            m_spGlobalFavourTags     = m_soData.FindProperty("GlobalFavourTags");

            m_spScatterSpace   = m_soData.FindProperty("m_scatterSpace");
            m_spScatterSpacing = m_soData.FindProperty("m_scatterSpacing");

            if (m_spTargetPreProcessData.objectReferenceValue != null)
            {
                var preProcessor = m_spTargetPreProcessData.objectReferenceValue as MxMPreProcessData;
                var animModule   = m_spTargetAnimModule.objectReferenceValue as AnimationModule;

                List <string> tagNames = null;

                if (preProcessor != null)
                {
                    tagNames = preProcessor.TagNames;
                }
                else if (animModule != null && animModule.TagNames != null)
                {
                    tagNames = animModule.TagNames;
                }
                else
                {
                    tagNames = new List <string>(Enum.GetNames(typeof(ETags)));
                }

                m_tagNames    = new string[33];
                m_tagNames[0] = "None";


                for (int i = 0; i < tagNames.Count; ++i)
                {
                    m_tagNames[i + 1] = tagNames[i];
                }


                List <string> favourTagNames = null;

                if (preProcessor != null)
                {
                    favourTagNames = preProcessor.FavourTagNames;
                }
                else if (animModule != null && animModule.FavourTagNames != null)
                {
                    favourTagNames = animModule.FavourTagNames;
                }
                else
                {
                    favourTagNames = new List <string>(Enum.GetNames(typeof(ETags)));
                }

                m_favourTagNames    = new string[33];
                m_favourTagNames[0] = "None";


                for (int i = 0; i < favourTagNames.Count; ++i)
                {
                    m_favourTagNames[i + 1] = favourTagNames[i];
                }


                m_tagIndex       = Array.IndexOf(Enum.GetValues(typeof(ETags)), (ETags)m_spGlobalTags.intValue);
                m_favourTagIndex = Array.IndexOf(Enum.GetValues(typeof(ETags)), (ETags)m_spGlobalFavourTags.intValue);

                GameObject targetPrefab = null;
                if (preProcessor != null)
                {
                    targetPrefab = preProcessor.Prefab;
                }
                else if (animModule != null)
                {
                    targetPrefab = animModule.Prefab;
                }

                if (targetPrefab != null)
                {
                    m_spTargetPrefab.objectReferenceValue = targetPrefab;
                    m_soData.ApplyModifiedPropertiesWithoutUndo();
                }
            }
            else
            {
                m_tagIndex       = 0;
                m_favourTagIndex = 0;
            }

            MxMSettings settings = MxMSettings.Instance();

            if (settings != null)
            {
                settings.ActiveBlendSpace = a_data;
            }

            if (MxMTaggingWindow.Exists())
            {
                MxMTaggingWindow.Inst().SetTarget(a_data);
            }
        }
        //===========================================================================================

        /**
         *  @brief
         *
         *********************************************************************************************/
        public void OnGUI(Rect a_position)
        {
            if (m_data == null)
            {
                MxMSettings settings = MxMSettings.Instance();
                if (settings != null)
                {
                    m_data = settings.ActiveBlendSpace;

                    if (m_data != null)
                    {
                        SetData(m_data);
                    }
                }
            }

            if (m_data != null)
            {
                Event evt = Event.current;

                float labelWidth = EditorGUIUtility.labelWidth;

                if (evt.type == EventType.Repaint)
                {
                    if (m_queueDeleteIndex >= 0 && m_queueDeleteIndex < m_spClips.arraySize)
                    {
                        if (m_selectId == m_queueDeleteIndex)
                        {
                            m_selectId = -1;
                        }

                        if (m_spClips.GetArrayElementAtIndex(m_queueDeleteIndex).objectReferenceValue != null)
                        {
                            m_spClips.DeleteArrayElementAtIndex(m_queueDeleteIndex);
                        }

                        m_spClips.DeleteArrayElementAtIndex(m_queueDeleteIndex);
                        m_spPositions.DeleteArrayElementAtIndex(m_queueDeleteIndex);

                        m_queueDeleteIndex = -1;
                    }
                }

                EditorGUILayout.BeginVertical();
                EditorGUILayout.BeginHorizontal(EditorStyles.toolbar, GUILayout.Height(20f), GUILayout.ExpandWidth(true));

                EditorGUI.BeginChangeCheck();
                m_previewActive = GUILayout.Toggle(m_previewActive, "Preview", EditorStyles.toolbarButton, GUILayout.Width(60f));
                if (EditorGUI.EndChangeCheck())
                {
                    if (m_previewActive)
                    {
                        BeginPreview();
                    }
                    else
                    {
                        EndPreview();
                    }
                }



                if (m_previewActive && MxMPreviewScene.IsSceneLoaded)
                {
                    EditorGUIUtility.labelWidth = 20f;

                    EditorGUI.BeginChangeCheck();
                    m_previewPos.x = EditorGUILayout.FloatField("X: ", m_previewPos.x, EditorStyles.toolbarTextField);
                    m_previewPos.y = EditorGUILayout.FloatField("Y: ", m_previewPos.y, EditorStyles.toolbarTextField);
                    if (EditorGUI.EndChangeCheck())
                    {
                        m_previewPos.x = Mathf.Clamp(m_previewPos.x, -1f, 1f);
                        m_previewPos.y = Mathf.Clamp(m_previewPos.y, -1f, 1f);

                        CalculateBlendWeights();
                        ApplyBlendWeights();
                    }
                    EditorGUIUtility.labelWidth = labelWidth;

                    UpdatePreview();
                    MxMAnimConfigWindow.Inst().Repaint();
                }

                GUILayout.FlexibleSpace();

                m_spNormalizeTime.boolValue = GUILayout.Toggle(m_spNormalizeTime.boolValue, "Normalize Time",
                                                               EditorStyles.toolbarButton, GUILayout.Width(90f));

                EditorGUILayout.LabelField("Type:", GUILayout.Width(40f));
                m_spScatterSpace.enumValueIndex = (int)(EBlendSpaceType)EditorGUILayout.EnumPopup(
                    (EBlendSpaceType)m_spScatterSpace.enumValueIndex, GUILayout.Width(70f));
                GUILayout.Space(5f);

                switch ((EBlendSpaceType)m_spScatterSpace.enumValueIndex)
                {
                case EBlendSpaceType.Standard:
                {
                    EditorGUILayout.LabelField("Magnitude ", GUILayout.Width(62f));
                    m_spMagnitude.vector2Value = EditorGUILayout.Vector2Field("", m_spMagnitude.vector2Value, GUILayout.Width(100f));
                    EditorGUILayout.LabelField("Smoothing ", GUILayout.Width(65f));
                    m_spSmoothing.vector2Value = EditorGUILayout.Vector2Field("", m_spSmoothing.vector2Value, GUILayout.Width(100f));
                }
                break;

                case EBlendSpaceType.Scatter:
                {
                    EditorGUILayout.LabelField("Spacing", GUILayout.Width(50f));
                    m_spScatterSpacing.vector2Value = EditorGUILayout.Vector2Field("", m_spScatterSpacing.vector2Value, GUILayout.Width(100f));
                }
                break;

                case EBlendSpaceType.ScatterX:
                {
                    EditorGUILayout.LabelField("Spacing X", GUILayout.Width(60f));
                    float spacingX = EditorGUILayout.FloatField(m_spScatterSpacing.vector2Value.x, GUILayout.Width(35f));

                    m_spScatterSpacing.vector2Value = new Vector2(spacingX, m_spScatterSpacing.vector2Value.y);
                }
                break;

                case EBlendSpaceType.ScatterY:
                {
                    EditorGUILayout.LabelField("Spacing Y", GUILayout.Width(60f));
                    float spacingY = EditorGUILayout.FloatField(m_spScatterSpacing.vector2Value.y, GUILayout.Width(35f));

                    m_spScatterSpacing.vector2Value = new Vector2(m_spScatterSpacing.vector2Value.x, spacingY);
                }
                break;
                }



                GUILayout.Space(2f);
                m_showClipNames = GUILayout.Toggle(m_showClipNames, "Show Clips", EditorStyles.toolbarButton, GUILayout.Width(80f));
                GUILayout.Space(5f);
                m_snapActive = GUILayout.Toggle(m_snapActive, "Snap", EditorStyles.toolbarButton, GUILayout.Width(40f));

                if (m_snapActive)
                {
                    m_snapInterval = EditorGUILayout.FloatField(m_snapInterval, EditorStyles.toolbarTextField, GUILayout.Width(30f));
                }

                EditorGUILayout.EndHorizontal();
                GUILayout.FlexibleSpace();

                EditorGUILayout.BeginHorizontal(EditorStyles.toolbar, GUILayout.Height(20f), GUILayout.ExpandWidth(true));

                if (m_selectId >= 0 && m_selectId < m_spClips.arraySize)
                {
                    AnimationClip      clip       = m_spClips.GetArrayElementAtIndex(m_selectId).objectReferenceValue as AnimationClip;
                    SerializedProperty spPosition = m_spPositions.GetArrayElementAtIndex(m_selectId);

                    if (clip != null && spPosition != null)
                    {
                        EditorGUILayout.LabelField(clip.name, GUILayout.Width(GUI.skin.label.CalcSize(new GUIContent(clip.name)).x + 4f));

                        EditorGUI.BeginChangeCheck();
                        spPosition.vector2Value = EditorGUILayout.Vector2Field("", spPosition.vector2Value);
                        if (EditorGUI.EndChangeCheck())
                        {
                            if (m_previewActive && MxMPreviewScene.IsSceneLoaded)
                            {
                                CalculateBlendWeights();
                                ApplyBlendWeights();
                            }
                        }
                    }
                }

                EditorGUILayout.LabelField("Require", GUILayout.Width(50f));
                MxMPreProcessData preProcessData = m_spTargetPreProcessData.objectReferenceValue as MxMPreProcessData;
                AnimationModule   animModule     = m_spTargetAnimModule.objectReferenceValue as AnimationModule;

                if (preProcessData != null)
                {
                    EditorFunctions.DrawTagFlagFieldWithCustomNames(preProcessData.TagNames.ToArray(), m_spGlobalTags, 100f);
                }
                else if (animModule != null && animModule.TagNames != null)
                {
                    EditorFunctions.DrawTagFlagFieldWithCustomNames(animModule.TagNames.ToArray(), m_spGlobalTags, 100f);
                }
                else
                {
                    m_spGlobalTags.intValue = (int)(ETags)EditorGUILayout.EnumFlagsField((ETags)m_spGlobalTags.intValue);
                }

                EditorGUILayout.LabelField("Favour", GUILayout.Width(45f));

                if (preProcessData != null)
                {
                    EditorFunctions.DrawTagFlagFieldWithCustomNames(preProcessData.FavourTagNames.ToArray(), m_spGlobalFavourTags, 100f);
                }
                else if (animModule != null && animModule.FavourTagNames != null)
                {
                    EditorFunctions.DrawTagFlagFieldWithCustomNames(animModule.FavourTagNames.ToArray(), m_spGlobalFavourTags, 100f);
                }
                else
                {
                    m_spGlobalFavourTags.intValue = (int)(ETags)EditorGUILayout.EnumFlagsField((ETags)m_spGlobalFavourTags.intValue);
                }

                GUILayout.FlexibleSpace();

                if (GUILayout.Button(new GUIContent("Open Timeline"), EditorStyles.toolbarButton))
                {
                    MxMTaggingWindow.ShowWindow();
                }

                GUILayout.Space(5f);

                if (m_spTargetPreProcessData.objectReferenceValue != null ||
                    m_spTargetAnimModule.objectReferenceValue != null)
                {
                    if (GUILayout.Button(EditorGUIUtility.IconContent("back").image, EditorStyles.toolbarButton))
                    {
                        LastBlendSpace();
                    }

                    if (GUILayout.Button(EditorGUIUtility.IconContent("forward").image, EditorStyles.toolbarButton))
                    {
                        NextBlendSpace();
                    }
                }

                EditorGUI.BeginDisabledGroup(true);

                EditorGUIUtility.labelWidth = 110f;
                if (preProcessData != null)
                {
                    EditorGUILayout.ObjectField(m_spTargetPreProcessData, new GUIContent("Target PreProcess"));
                }
                else if (animModule != null)
                {
                    EditorGUILayout.ObjectField(m_spTargetAnimModule, new GUIContent("Target Anim Module"));
                }

                EditorGUIUtility.labelWidth = 95f;
                EditorGUILayout.ObjectField(m_spTargetPrefab, new GUIContent("Preview Prefab"));

                EditorGUI.EndDisabledGroup();

                EditorGUIUtility.labelWidth = labelWidth;

                EditorGUILayout.EndHorizontal();
                EditorGUILayout.EndVertical();

                Rect blendSpaceRect = new Rect(30f, 40f, a_position.width - 60f, a_position.height - 90f);

                GUI.Box(blendSpaceRect, "");

                Rect labelRect = new Rect(blendSpaceRect.x - 18f, blendSpaceRect.y, 18f, 18f);

                GUI.Label(labelRect, "1");
                labelRect.y += blendSpaceRect.height / 2f - 9f;
                GUI.Label(labelRect, "0");
                labelRect.y = blendSpaceRect.y + blendSpaceRect.height - 18f;
                GUI.Label(labelRect, "-1");
                labelRect.y += labelRect.height;
                labelRect.x += labelRect.width;
                GUI.Label(labelRect, "-1");
                labelRect.x += blendSpaceRect.width / 2f - 9f;
                GUI.Label(labelRect, "0");
                labelRect.x = blendSpaceRect.x + blendSpaceRect.width - 18f;
                GUI.Label(labelRect, "1");

                float spacingH = blendSpaceRect.width / 10f;
                float spacingV = blendSpaceRect.height / 10f;

                float top    = blendSpaceRect.y;
                float bottom = blendSpaceRect.y + blendSpaceRect.height;
                float left   = blendSpaceRect.x;
                float right  = blendSpaceRect.x + blendSpaceRect.width;

                Handles.color = Color.grey;
                for (int i = 1; i < 10; ++i)
                {
                    float horizontal = i * spacingH + blendSpaceRect.x;
                    float vertical   = i * spacingV + blendSpaceRect.y;

                    Handles.DrawLine(new Vector3(horizontal, top), new Vector3(horizontal, bottom));
                    Handles.DrawLine(new Vector3(left, vertical), new Vector3(right, vertical));
                }

                Handles.color = Color.black;
                Handles.DrawLine(new Vector3(blendSpaceRect.x + blendSpaceRect.width / 2f, top),
                                 new Vector3(blendSpaceRect.x + blendSpaceRect.width / 2f, bottom));

                Handles.DrawLine(new Vector3(left, blendSpaceRect.y + blendSpaceRect.height / 2f),
                                 new Vector3(right, blendSpaceRect.y + blendSpaceRect.height / 2f));

                Rect    animDrawRect    = new Rect(0f, 0f, 18f, 18f);
                Vector2 blendSpaceRatio = new Vector2(2f / blendSpaceRect.width, 2f / blendSpaceRect.height);

                Texture blendKey         = EditorGUIUtility.IconContent("blendKey").image;
                Texture blendKeySelected = EditorGUIUtility.IconContent("blendKeySelected").image;
                Texture previewPointTex  = EditorGUIUtility.IconContent("d_P4_AddedLocal").image;

                Vector2 centerPos = blendSpaceRect.position;
                centerPos.x += blendSpaceRect.width / 2f;
                centerPos.y += blendSpaceRect.height / 2f;

                //Draw Points
                for (int i = 0; i < m_spClips.arraySize; ++i)
                {
                    Vector2 normalizedPos = m_spPositions.GetArrayElementAtIndex(i).vector2Value;
                    normalizedPos.y *= -1f;

                    animDrawRect.position = (normalizedPos / blendSpaceRatio) + centerPos;

                    animDrawRect.size = new Vector2(14f, 14f);

                    if (m_previewActive && MxMPreviewScene.IsSceneLoaded)
                    {
                        float size = 9f + 5f * m_blendWeights[i];
                        animDrawRect.size = new Vector2(size, size);
                    }
                    else
                    {
                        animDrawRect.size = new Vector2(14f, 14f);
                    }

                    animDrawRect.position -= (animDrawRect.size / 2f);

                    if (m_selectId == i)
                    {
                        GUI.DrawTexture(animDrawRect, blendKeySelected);
                    }
                    else
                    {
                        GUI.DrawTexture(animDrawRect, blendKey);
                    }

                    if (m_showClipNames)
                    {
                        AnimationClip clip = m_spClips.GetArrayElementAtIndex(i).objectReferenceValue as AnimationClip;

                        Vector2 labelSize = GUI.skin.label.CalcSize(new GUIContent(clip.name));

                        Rect clipNameRect = new Rect(animDrawRect.x + (animDrawRect.width / 2f) - labelSize.x / 2f,
                                                     animDrawRect.y - labelSize.y, labelSize.x, labelSize.y);

                        GUI.Label(clipNameRect, clip.name);
                    }

                    if (evt.type == EventType.MouseDown && evt.button == 0)
                    {
                        if (animDrawRect.Contains(evt.mousePosition))
                        {
                            m_selectId       = i;
                            m_dragging       = true;
                            m_cumulativeDrag = m_spPositions.GetArrayElementAtIndex(i).vector2Value;

                            if (evt.clickCount >= 2)
                            {
                                EditorGUIUtility.PingObject(m_spClips.GetArrayElementAtIndex(i).objectReferenceValue);
                            }

                            evt.Use();
                            MxMAnimConfigWindow.Inst().Repaint();
                        }
                    }
                }

                //Draw Preview Point
                if (m_previewActive && MxMPreviewScene.IsSceneLoaded)
                {
                    Vector3 previewDrawPos = m_previewPos;
                    previewDrawPos.y *= -1f;

                    animDrawRect.size     = new Vector2(18f, 18f);
                    animDrawRect.position = (previewDrawPos / blendSpaceRatio) + centerPos - (animDrawRect.size / 2f);

                    GUI.DrawTexture(animDrawRect, previewPointTex);
                }

                switch (evt.type)
                {
                case EventType.MouseDown:
                {
                    if (m_previewActive && blendSpaceRect.Contains(evt.mousePosition) && MxMPreviewScene.IsSceneLoaded)
                    {
                        Vector2 blendSpacePos = evt.mousePosition - (blendSpaceRect.position + (blendSpaceRect.size / 2f));
                        m_previewPos    = blendSpacePos * blendSpaceRatio;
                        m_previewPos.y *= -1f;

                        m_previewPos.x = Mathf.Clamp(m_previewPos.x, -1f, 1f);
                        m_previewPos.y = Mathf.Clamp(m_previewPos.y, -1f, 1f);

                        CalculateBlendWeights();
                        ApplyBlendWeights();


                        m_draggingPreview = true;
                    }

                    m_dragging = false;
                    m_selectId = -1;
                    evt.Use();
                }
                break;

                case EventType.MouseUp:
                {
                    if (m_dragging || m_draggingPreview)
                    {
                        m_draggingPreview = false;
                        m_dragging        = false;
                        m_cumulativeDrag  = Vector2.zero;
                        evt.Use();
                    }
                }
                break;

                case EventType.MouseDrag:
                {
                    if (m_dragging)
                    {
                        if (m_selectId >= 0 && m_selectId < m_spPositions.arraySize)
                        {
                            SerializedProperty spPosition = m_spPositions.GetArrayElementAtIndex(m_selectId);
                            Vector2            moveDelta  = evt.delta;
                            moveDelta.y *= -1f;

                            if (m_snapActive)
                            {
                                m_cumulativeDrag += moveDelta * blendSpaceRatio;

                                m_cumulativeDrag.x = Mathf.Clamp(m_cumulativeDrag.x, -1f, 1f);
                                m_cumulativeDrag.y = Mathf.Clamp(m_cumulativeDrag.y, -1f, 1f);

                                spPosition.vector2Value = m_cumulativeDrag;
                                SnapClip(m_selectId);
                            }
                            else
                            {
                                Vector2 newPos = spPosition.vector2Value + moveDelta * blendSpaceRatio;

                                newPos.x = Mathf.Clamp(newPos.x, -1f, 1f);
                                newPos.y = Mathf.Clamp(newPos.y, -1f, 1f);
                                spPosition.vector2Value = newPos;
                            }

                            if (m_previewActive && MxMPreviewScene.IsSceneLoaded)
                            {
                                CalculateBlendWeights();
                                ApplyBlendWeights();
                            }

                            evt.Use();
                        }
                        else
                        {
                            m_dragging = false;
                        }
                    }
                    else if (m_previewActive && m_draggingPreview && MxMPreviewScene.IsSceneLoaded)
                    {
                        Vector2 blendSpacePos = evt.mousePosition - (blendSpaceRect.position + (blendSpaceRect.size / 2f));
                        m_previewPos    = blendSpacePos * blendSpaceRatio;
                        m_previewPos.y *= -1f;

                        m_previewPos.x = Mathf.Clamp(m_previewPos.x, -1f, 1f);
                        m_previewPos.y = Mathf.Clamp(m_previewPos.y, -1f, 1f);

                        CalculateBlendWeights();
                        ApplyBlendWeights();

                        if (m_snapActive)
                        {
                            SnapPreview();
                        }

                        evt.Use();
                    }
                }
                break;

                case EventType.KeyDown:
                {
                    if (m_selectId >= 0 && m_selectId < m_spClips.arraySize)
                    {
                        if (evt.keyCode == KeyCode.Delete)
                        {
                            m_queueDeleteIndex = m_selectId;
                            MxMAnimConfigWindow.Inst().Repaint();
                            evt.Use();
                        }
                    }
                }
                break;
                }

                DragDropAnimations(blendSpaceRect);

                if (m_soData != null)
                {
                    m_soData.ApplyModifiedProperties();
                }
            }
            else
            {
                GUILayout.Space(18f);
                EditorGUILayout.BeginHorizontal();
                GUILayout.FlexibleSpace();
                EditorGUILayout.LabelField("No Blend Space Selected.", EditorStyles.boldLabel);
                GUILayout.FlexibleSpace();
                EditorGUILayout.EndHorizontal();
            }
        }
        public void OnGUI(Rect a_position)
        {
            if (m_data == null)
            {
                MxMSettings settings = MxMSettings.Instance();
                if (settings != null)
                {
                    m_data = settings.ActiveComposite;

                    if (m_data != null)
                    {
                        SetData(m_data);
                    }
                }
            }

            if (m_data != null)
            {
                Rect  viewRect      = new Rect(0f, 18f, a_position.width, a_position.height - 36f);
                float requiredWidth = (m_data.AnimAfterClips.Count + m_data.AnimBeforeClips.Count + 2) * (s_animSlotSizeSmall + s_animSlotSpacing) + (s_animSlotSize + s_animSlotSpacing);

                if (requiredWidth > a_position.width)
                {
                    Rect scrollRect = new Rect((a_position.width - requiredWidth) / 2f, 18f, Mathf.Max(requiredWidth, a_position.width), a_position.height - 36f);
                    m_scrollPosition = GUI.BeginScrollView(viewRect, m_scrollPosition, scrollRect);
                }

                Rect baseAnimRect = new Rect(a_position.width / 2f - s_animSlotSize / 2f,
                                             a_position.height / 2f - s_animSlotSize / 2f,
                                             s_animSlotSize, s_animSlotSize);

                ManageSlot(baseAnimRect, m_data.PrimaryClip, "\n\n\nPrimary Anim");

                if (m_data.BeforeClips == null)
                {
                    m_data.BeforeClips = new List <AnimationClip>();
                }

                if (m_data.AfterClips == null)
                {
                    m_data.AfterClips = new List <AnimationClip>();
                }

                if (m_data.PrimaryClip != null)
                {
                    if (!m_spLooping.boolValue)
                    {
                        Rect slotRect = new Rect(a_position.width / 2f + s_animSlotSize / 2f + s_animSlotSpacing,
                                                 a_position.height / 2f - s_animSlotSizeSmall / 2f,
                                                 s_animSlotSizeSmall, s_animSlotSizeSmall);

                        for (int i = 0; i < m_data.AfterClips.Count + 1; ++i)
                        {
                            ManageSlot(slotRect, i < m_data.AfterClips.Count ? m_data.AfterClips[i] : null,
                                       "\n\nAfter\nAnim", EAnimType.Future, i);

                            slotRect.x += s_animSlotSizeSmall + s_animSlotSpacing;
                        }

                        slotRect = new Rect(a_position.width / 2f - s_animSlotSize / 2f - s_animSlotSpacing - s_animSlotSizeSmall,
                                            a_position.height / 2f - s_animSlotSizeSmall / 2f,
                                            s_animSlotSizeSmall, s_animSlotSizeSmall);

                        for (int i = 0; i < m_data.BeforeClips.Count + 1; ++i)
                        {
                            ManageSlot(slotRect, i < m_data.BeforeClips.Count ? m_data.BeforeClips[i] : null,
                                       "\n\nBefore\nAnim", EAnimType.Past, i);

                            slotRect.x -= s_animSlotSizeSmall + s_animSlotSpacing;
                        }
                    }

                    Rect settingsRect = new Rect(baseAnimRect.x - s_animSlotSpacing / 2f,
                                                 baseAnimRect.y + baseAnimRect.height + 10f,
                                                 baseAnimRect.width + s_animSlotSpacing,
                                                 baseAnimRect.height * 2f);

                    DrawSettings(settingsRect);
                }

                Event evt = Event.current;

                if (evt.isKey && evt.keyCode == KeyCode.Delete)
                {
                    switch (evt.keyCode)
                    {
                    case KeyCode.Delete:
                    {
                        //Manage delete key
                        switch (m_selectionType)
                        {
                        case EAnimType.Current:
                        {
                            m_spPrimaryClip.objectReferenceValue = null;

                            m_data.ClearRootLookupTable();
                        }
                        break;

                        case EAnimType.Future:
                        {
                            if (m_selectionId < m_spAfterClips.arraySize)
                            {
                                if (m_spAfterClips.GetArrayElementAtIndex(m_selectionId) != null)
                                {
                                    m_spAfterClips.DeleteArrayElementAtIndex(m_selectionId);
                                }

                                m_spAfterClips.DeleteArrayElementAtIndex(m_selectionId);
                            }
                        }
                        break;

                        case EAnimType.Past:
                        {
                            if (m_selectionId < m_spBeforeClips.arraySize)
                            {
                                if (m_spBeforeClips.GetArrayElementAtIndex(m_selectionId) != null)
                                {
                                    m_spBeforeClips.DeleteArrayElementAtIndex(m_selectionId);
                                }

                                m_spBeforeClips.DeleteArrayElementAtIndex(m_selectionId);
                            }
                        }
                        break;
                        }
                    }
                    break;

                    case KeyCode.RightArrow:
                    {
                        NextComposite();
                    }
                    break;

                    case KeyCode.LeftArrow:
                    {
                        LastComposite();
                    }
                    break;
                    }



                    m_selectionType = EAnimType.None;
                    m_selectionId   = 0;

                    MxMAnimConfigWindow.Inst().Repaint();
                }
                if (requiredWidth > a_position.width)
                {
                    GUI.EndScrollView();
                }


                EditorGUILayout.BeginVertical();
                EditorGUILayout.BeginHorizontal(EditorStyles.toolbar, GUILayout.Height(20f), GUILayout.ExpandWidth(true));
                if (GUILayout.Button(new GUIContent("Open Timeline"), EditorStyles.toolbarButton))
                {
                    MxMTaggingWindow.ShowWindow();
                }

                if (GUILayout.Button(new GUIContent("Locate Asset"), EditorStyles.toolbarButton))
                {
                    if (m_spTargetPreProcessData.objectReferenceValue != null)
                    {
                        EditorGUIUtility.PingObject(m_spTargetPreProcessData.objectReferenceValue);
                    }

                    if (m_spTargetAnimModule.objectReferenceValue != null)
                    {
                        EditorGUIUtility.PingObject(m_spTargetAnimModule.objectReferenceValue);
                    }
                }

                GUILayout.FlexibleSpace();

                if (GUILayout.Button(EditorGUIUtility.IconContent("back").image, EditorStyles.toolbarButton))
                {
                    LastComposite();
                }

                if (GUILayout.Button(EditorGUIUtility.IconContent("forward").image, EditorStyles.toolbarButton))
                {
                    NextComposite();
                }

                GUILayout.Space(5f);

                if (GUILayout.Button(new GUIContent("Locate Animation"), EditorStyles.toolbarButton))
                {
                    switch (m_selectionType)
                    {
                    case EAnimType.None:
                    case EAnimType.Current:
                    {
                        if (m_spPrimaryClip.objectReferenceValue != null)
                        {
                            EditorGUIUtility.PingObject(m_spPrimaryClip.objectReferenceValue);
                        }
                    }
                    break;

                    case EAnimType.Future:
                    {
                        if (m_selectionId < m_spAfterClips.arraySize)
                        {
                            SerializedProperty spCLip = m_spAfterClips.GetArrayElementAtIndex(m_selectionId);

                            if (spCLip != null && spCLip.objectReferenceValue != null)
                            {
                                EditorGUIUtility.PingObject(spCLip.objectReferenceValue);
                            }
                        }
                    }
                    break;

                    case EAnimType.Past:
                    {
                        if (m_selectionId < m_spBeforeClips.arraySize)
                        {
                            SerializedProperty spCLip = m_spBeforeClips.GetArrayElementAtIndex(m_selectionId);

                            if (spCLip != null && spCLip.objectReferenceValue != null)
                            {
                                EditorGUIUtility.PingObject(spCLip.objectReferenceValue);
                            }
                        }
                    }
                    break;
                    }
                }

                EditorGUILayout.EndHorizontal();
                GUILayout.FlexibleSpace();

                EditorGUILayout.BeginHorizontal(EditorStyles.toolbar, GUILayout.Height(20f), GUILayout.ExpandWidth(true));
                EditorGUI.BeginDisabledGroup(true);
                if (m_spTargetPreProcessData.objectReferenceValue != null)
                {
                    EditorGUILayout.ObjectField(m_spTargetPreProcessData, GUILayout.Width(300f));
                }
                else
                {
                    EditorGUILayout.ObjectField(m_spTargetAnimModule, GUILayout.Width(300f));
                }

                GUILayout.FlexibleSpace();

                EditorGUILayout.ObjectField(m_spTargetPrefab, GUILayout.Width(300f));

                EditorGUI.EndDisabledGroup();

                EditorGUILayout.EndHorizontal();
                EditorGUILayout.EndVertical();


                if (m_soData != null)
                {
                    m_soData.ApplyModifiedProperties();
                }
            }
            else
            {
                GUILayout.Space(18f);
                EditorGUILayout.BeginHorizontal();
                GUILayout.FlexibleSpace();
                EditorGUILayout.LabelField("No Composite Selected.", EditorStyles.boldLabel);
                GUILayout.FlexibleSpace();
                EditorGUILayout.EndHorizontal();
            }
        }
        //============================================================================================
        /**
        *  @brief 
        *         
        *********************************************************************************************/
        public void DrawSections(ref Rect a_trackRect, ref Rect a_timelineRect, float a_zoom, MxMTaggingWindow a_taggingWindow)
        {
            Texture markerIcon = EditorGUIUtility.IconContent("Animation.EventMarker").image;

            Rect markerRect;

            Event evt = Event.current;

            float lastTime = 0f;

            MotionTimingPresets motionTimingPresets = null;

            if (a_taggingWindow != null)
                m_targetMxMAnim = a_taggingWindow.TargetMxMAnim;

            var targetPreProcess = m_targetMxMAnim.TargetPreProcess;

            if (m_targetMxMAnim != null && targetPreProcess != null)
            {
                motionTimingPresets = targetPreProcess.MotionTimingPresets;
            }

            string[] defenitionNames = null;
            if(motionTimingPresets != null)
            {
                defenitionNames = motionTimingPresets.GetDefenitionNames();
            }

           float maxSpeedVariance = 0.5f;

            //Determine max variance
            for (int i = 0; i < MotionSections.Count; ++i)
            {
                MotionSection curSection = MotionSections[i];

                float speedMod = 1f;
                speedMod = curSection.GetSpeedMod(lastTime, motionTimingPresets, m_targetMxMAnim);

                float speedVariance = 0f;
                if (speedMod > 1f)
                    speedVariance = (speedMod / 1f) - 1f;
                else if (speedMod < 1f)
                    speedVariance = (1f / speedMod) - 1f;

                if (speedVariance > maxSpeedVariance)
                    maxSpeedVariance = speedVariance;

                lastTime = curSection.EndTime;
            }

            lastTime = 0f;
            for (int i = 0; i < MotionSections.Count; ++i)
            {
                MotionSection curSection = MotionSections[i];

                markerRect = new Rect(curSection.EndTime * 75f * a_zoom - (markerIcon.width / 2f), a_trackRect.y,
                     markerIcon.width, markerIcon.height);

                Vector3 start = new Vector3(markerRect.x + markerRect.width / 2f,
                                                markerRect.y + markerRect.height);
                Vector3 end = new Vector3(start.x, a_timelineRect.height);

                if (i != MotionSections.Count - 1)
                {
                    GUI.DrawTexture(markerRect, markerIcon);

                    Handles.color = Color.black;
                    Handles.DrawLine(start, end);

                    if (curSection.Selected)
                        GUI.DrawTexture(markerRect, EditorUtil.EditorFunctions.GetHighlightTex());


                    markerRect.x -= 3f;
                    markerRect.height = a_trackRect.height;
                    markerRect.width += 6f;

                    if (evt.isMouse && evt.button == 0)
                    {
                        switch (evt.type)
                        {
                            case EventType.MouseDown:
                                {
                                    if (markerRect.Contains(evt.mousePosition))
                                    {
                                        curSection.Selected = true;
                                        curSection.Dragging = true;
                                        a_taggingWindow.SelectSection(curSection, curSection.EndTime);
                                    }

                                }
                                break;
                            case EventType.MouseUp:
                                {
                                    curSection.Dragging = false;
                                }
                                break;
                            case EventType.MouseDrag:
                                {
                                    if (curSection.Dragging && curSection.Selected)
                                    {
                                        float desiredValueDelta = ((evt.delta.x / a_zoom)) / 75f;

                                        curSection.EndTime += desiredValueDelta;

                                        curSection.EndTime = Mathf.Clamp(curSection.EndTime, 0f,
                                            a_taggingWindow.TargetClip.length);
                                        a_taggingWindow.Modified(curSection.EndTime);
                                    }
                                }
                                break;
                        }
                    }
                }


                float speedMod = 1f;
                speedMod = curSection.GetSpeedMod(lastTime, motionTimingPresets, m_targetMxMAnim);

                float speedVariance = 0f;
                if (speedMod > 1f)
                {
                    speedVariance = (speedMod / 1f) - 1f;
                }
                else if (speedMod < 1f)
                {
                    speedVariance = (1f / speedMod) - 1f;
                }

                float heightRatio = speedVariance / maxSpeedVariance;

                if (speedMod < 1f)
                    heightRatio *= -1;

                if (maxSpeedVariance < 0.001f)
                    heightRatio = 0f;

                //Draw Baseline
                end = new Vector3(curSection.EndTime * 75f * a_zoom, a_timelineRect.height / 2f + 9f);
                start = new Vector3(lastTime * 75f * a_zoom, end.y);

                Handles.color = new Color(0f, 0f, 0f, 0.5f);
                Handles.DrawLine(start, end);

                //Draw limit line
                Handles.color = new Color(0f, 0f, 0f, 0.3f);
                if (speedMod > 1f + Mathf.Epsilon)
                {
                    end.y = a_timelineRect.height / 2f + (a_timelineRect.height / 2f - 44f) + 9f;
                    start.y = end.y;

                    Handles.DrawLine(start, end);
                }
                else
                {

                    //Draw limit line
                    end.y = a_timelineRect.height / 2f - (a_timelineRect.height / 2f - 44f) + 9f;
                    start.y = end.y;

                    Handles.DrawLine(start, end);
                }

                //Draw Green Line
                end.y = a_timelineRect.height / 2f + heightRatio * (a_timelineRect.height / 2f - 44f) + 9f;
                start.y = end.y;

                Handles.color = Color.green;
                Handles.DrawLine(start, end);

                float invertedSpeedMod = 1f / speedMod;
                string speedString = invertedSpeedMod.ToString("F2");

                speedString += "x";

                float width = GUI.skin.label.CalcSize(new GUIContent(speedString)).x;
                GUI.Label(new Rect(start.x + (end.x - start.x) / 2f - width / 2f, end.y - 18f, width, 18f), speedString);


                Rect dataRect = new Rect(lastTime * 75f * a_zoom + 4, a_timelineRect.height / 1.75f,
                    end.x - start.x - 8, a_timelineRect.height - (a_timelineRect.height / 1.75f) - 18f);

                if (speedMod > 1f + Mathf.Epsilon)
                {
                    dataRect.y = 40f;
                }

                //Draw Drop Down Boxes

                GUI.Box(dataRect, "Section " + i);

                dataRect.x += 3f;
                dataRect.width -= 6f;

                GUILayout.BeginArea(dataRect);
                GUILayout.Space(18f);

                if (motionTimingPresets != null)
                {
                    curSection.UsePresets = GUILayout.Toggle(curSection.UsePresets,
                        new GUIContent("Use Preset"));
                }

                if (curSection.UsePresets && motionTimingPresets != null)
                {
                    curSection.MotionPresetId = EditorGUILayout.Popup(curSection.MotionPresetId,
                        defenitionNames);
                }
                else
                {
                    float defaultLabelWidth = EditorGUIUtility.labelWidth;
                    EditorGUIUtility.labelWidth = 40f;
                    curSection.ModType = (EMotionModType)EditorGUILayout.EnumPopup(new GUIContent("Type"), curSection.ModType);
                    curSection.RawModValue = EditorGUILayout.FloatField(new GUIContent("Value"), curSection.RawModValue);


                    if (curSection.RawModValue < 0.01f)
                        curSection.RawModValue = 0.01f;


                    EditorGUIUtility.labelWidth = defaultLabelWidth;
                }

                GUILayout.FlexibleSpace();

                float originalDurationF = (curSection.EndTime - lastTime);
                float finalDurationF = ((curSection.EndTime - lastTime) * speedMod);

                string originalDuration = originalDurationF.ToString("F2");
                string finalDuration = finalDurationF.ToString("F2");

                float originalSpeedF = m_targetMxMAnim.GetAverageRootSpeed(lastTime, curSection.EndTime);
                float finalSpeedF = originalSpeedF * (originalDurationF / finalDurationF);

                string originalSpeed = originalSpeedF.ToString("F2");
                string finalSpeed = finalSpeedF.ToString("F2");



                EditorGUILayout.LabelField("Original: " + originalDuration + " sec | " + originalSpeed + "m/s");
                EditorGUILayout.LabelField("Final: " + finalDuration + " sec | " + finalSpeed + "m/s");

                GUILayout.EndArea();

                lastTime = curSection.EndTime;
            }
        }