//=========================================================================================== /** * @brief * *********************************************************************************************/ public void EndPreviewLocal() { if (!m_previewActive) { return; } AnimationMixerPlayable mixer = MxMPreviewScene.Mixer; if (mixer.IsValid()) { for (int i = 0; i < mixer.GetInputCount(); ++i) { var clipPlayable = mixer.GetInput(0); if (clipPlayable.IsValid()) { mixer.DisconnectInput(0); clipPlayable.Destroy(); } } } m_previewActive = false; m_previewBlendSpace = null; }
//=========================================================================================== /** * @brief * *********************************************************************************************/ public void UpdatePreview() { if (!MxMPreviewScene.IsSceneLoaded) { return; } if (m_data == null || m_data.Clips.Count == 0 || !MxMPreviewScene.PlayableGraph.IsValid()) { EndPreview(); return; } if (m_previewBlendSpace != m_data) { SetupPreviewGraph(); m_previewBlendSpace = m_data; } //Calculate and Set blending weights here float timePassed = (float)EditorApplication.timeSinceStartup - m_lastPlayIncTime; MxMPreviewScene.PlayableGraph.Evaluate(timePassed); MxMPreviewScene.PreviewObject.transform.SetPositionAndRotation(Vector3.zero, Quaternion.identity); SceneView.RepaintAll(); m_lastPlayIncTime = (float)EditorApplication.timeSinceStartup; }
public static void MakeFromAnimationClip(MenuCommand a_cmd) { AnimationClip clip = (AnimationClip)a_cmd.context; MxMBlendSpace mxmBlendSpace = ScriptableObject.CreateInstance <MxMBlendSpace>(); mxmBlendSpace.Initialize(clip); string path = AssetDatabase.GetAssetPath(Selection.activeObject); if (path == "") { path = "Assets"; } else if (Path.GetExtension(path) != "") { path = path.Replace(Path.GetFileName(AssetDatabase.GetAssetPath(Selection.activeObject)), ""); } string assetPathAndName = AssetDatabase.GenerateUniqueAssetPath(path + "/" + clip.name + "_MxMBlend.asset"); AssetDatabase.CreateAsset(mxmBlendSpace, assetPathAndName); AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); EditorUtility.FocusProjectWindow(); Selection.activeObject = mxmBlendSpace; }
public MxMBlendClip(MxMBlendSpace a_sourceBlendSpace, Vector2 a_position) { SourceBlendSpace = a_sourceBlendSpace; Position = a_position; NormalizeTime = a_sourceBlendSpace.NormalizeTime; Weightings = SourceBlendSpace.CalculateWeightings(Position); }
//============================================================================================ /** * @brief * *********************************************************************************************/ public void CopyPreProcessData(MxMPreProcessData a_preProcessData) { m_overrideTagModule = a_preProcessData.OverrideTagModule; m_overrideEventModule = a_preProcessData.OverrideEventModule; m_overrideConfigModule = a_preProcessData.OverrideConfigModule; List<CompositeCategory> sourceCategories = a_preProcessData.CompositeCategories; m_compositeCategories = new List<CompositeCategory>(sourceCategories.Count + 1); foreach (CompositeCategory sourceCategory in sourceCategories) { CompositeCategory newCategory = new CompositeCategory(sourceCategory, this); m_compositeCategories.Add(newCategory); } List<MxMAnimationIdleSet> sourceIdleSets = a_preProcessData.AnimationIdleSets; m_animIdleSets = new List<MxMAnimationIdleSet>(sourceIdleSets.Count + 1); foreach(MxMAnimationIdleSet sourceIdleSet in sourceIdleSets) { MxMAnimationIdleSet newIdleSet = ScriptableObject.CreateInstance<MxMAnimationIdleSet>(); newIdleSet.CopyData(sourceIdleSet); newIdleSet.name = sourceIdleSet.name; newIdleSet.hideFlags = HideFlags.HideInHierarchy; newIdleSet.TargetAnimModule = this; newIdleSet.TargetPreProcess = null; EditorUtility.SetDirty(newIdleSet); AssetDatabase.AddObjectToAsset(newIdleSet, this); m_animIdleSets.Add(newIdleSet); } List<MxMBlendSpace> sourceBlendSpaces = a_preProcessData.BlendSpaces; m_blendSpaces = new List<MxMBlendSpace>(sourceBlendSpaces.Count + 1); foreach(MxMBlendSpace sourceBlendSpace in sourceBlendSpaces) { MxMBlendSpace newBlendSpace = ScriptableObject.CreateInstance<MxMBlendSpace>(); newBlendSpace.CopyData(sourceBlendSpace); newBlendSpace.name = sourceBlendSpace.name; newBlendSpace.hideFlags = HideFlags.HideInHierarchy; newBlendSpace.TargetAnimModule = this; newBlendSpace.TargetPreProcess = null; EditorUtility.SetDirty(newBlendSpace); AssetDatabase.AddObjectToAsset(newBlendSpace, this); m_blendSpaces.Add(newBlendSpace); } EditorUtility.SetDirty(this); }
//=========================================================================================== /** * @brief * *********************************************************************************************/ public static void SetData(MxMBlendSpace a_data) { if (a_data == null) { return; } m_blendSpaceData = a_data; MxMBlendSpaceWindow.SetData(m_blendSpaceData); m_nextAnimType = EMxMAnimtype.BlendSpace; }
//=========================================================================================== /** * @brief * *********************************************************************************************/ public void EndPreview() { MxMPreviewScene.EndPreview(); m_previewActive = false; m_previewBlendSpace = null; if (m_blendWeights != null) { m_blendWeights.Clear(); } }
public void CopyData(MxMBlendSpace a_copy) { ValidateBaseData(); m_magnitude = a_copy.m_magnitude; m_smoothing = a_copy.m_smoothing; m_scatterSpace = a_copy.m_scatterSpace; m_scatterSpacing = a_copy.m_scatterSpacing; m_scatterPositions = null; UseSpeedMods = a_copy.UseSpeedMods; GlobalTags = a_copy.GlobalTags; GlobalFavourTags = a_copy.GlobalFavourTags; m_clips = new List<AnimationClip>(a_copy.m_clips); m_positions = new List<Vector2>(a_copy.Positions); if(m_targetPrefab == null) m_targetPrefab = a_copy.m_targetPrefab; TagTracks = new List<TagTrack>(a_copy.TagTracks.Count + 1); foreach(TagTrack track in a_copy.TagTracks) { TagTracks.Add(new TagTrack(track)); } FavourTagTracks = new List<TagTrack>(a_copy.FavourTagTracks.Count + 1); foreach(TagTrack track in a_copy.FavourTagTracks) { FavourTagTracks.Add(new TagTrack(track)); } UserBoolTracks = new List<TagTrackBase>(a_copy.UserBoolTracks.Count + 1); foreach(TagTrackBase track in a_copy.UserBoolTracks) { UserBoolTracks.Add(new TagTrackBase(track)); } LeftFootStepTrack = new FootStepTagTrack(a_copy.LeftFootStepTrack); RightFootStepTrack = new FootStepTagTrack(a_copy.RightFootStepTrack); WarpPositionTrack = new TagTrackBase(a_copy.WarpPositionTrack); WarpRotationTrack = new TagTrackBase(a_copy.WarpRotationTrack); EnableRootMotionTrack = new TagTrackBase(a_copy.EnableRootMotionTrack); PoseFavourTrack = new FloatTagTrack(a_copy.PoseFavourTrack); WarpTrajLatTrack = new TagTrackBase(a_copy.WarpTrajLatTrack); WarpTrajLongTrack = new TagTrackBase(a_copy.WarpTrajLongTrack); MotionModifier = new MotionModifyData(a_copy.MotionModifier, this); }
public static bool OpenAssetEditor(int a_instanceID, int a_line) { MxMBlendSpace data = EditorUtility.InstanceIDToObject(a_instanceID) as MxMBlendSpace; if (data != null) { data.ValidateBaseData(); MxMAnimConfigWindow.ShowWindow(); MxMAnimConfigWindow.SetData(data); return true; } return false; }
//=========================================================================================== /** * @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(); } }