//============================================================================================ /** * @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 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(); } } }
//============================================================================================ /** * @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; } }