//=========================================================================================== /** * @brief * *********************************************************************************************/ private void DragDropAnimations(Rect a_dropRect) { Event evt = Event.current; switch (evt.type) { case EventType.DragUpdated: case EventType.DragPerform: { if (!a_dropRect.Contains(evt.mousePosition)) { return; } if (DragAndDrop.objectReferences[0].GetType() == typeof(AnimationClip)) { DragAndDrop.visualMode = DragAndDropVisualMode.Copy; if (evt.type == EventType.DragPerform) { DragAndDrop.AcceptDrag(); UnityEngine.Object obj = DragAndDrop.objectReferences[0]; if (obj != null && obj.GetType() == typeof(AnimationClip)) { Vector2 blendSpacePos = evt.mousePosition - (a_dropRect.position + (a_dropRect.size / 2f)); float blendSpaceRatioX = 1f / (a_dropRect.width / 2f); float blendSpaceRatioY = -1f / (a_dropRect.height / 2f); blendSpacePos *= new Vector2(blendSpaceRatioX, blendSpaceRatioY); m_spClips.InsertArrayElementAtIndex(m_spClips.arraySize); m_spPositions.InsertArrayElementAtIndex(m_spPositions.arraySize); m_spClips.GetArrayElementAtIndex(m_spClips.arraySize - 1).objectReferenceValue = obj as AnimationClip; m_spPositions.GetArrayElementAtIndex(m_spClips.arraySize - 1).vector2Value = blendSpacePos; if (m_snapActive) { SnapClip(m_spPositions.arraySize - 1); } if (m_previewActive) { AddClipToPreview(obj as AnimationClip); } MxMAnimConfigWindow.Inst().Repaint(); } } } } break; } }
public static bool OpenAssetEditor(int a_instanceId, int a_line) { MxMAnimationIdleSet data = EditorUtility.InstanceIDToObject( a_instanceId) as MxMAnimationIdleSet; if(data != null) { MxMAnimConfigWindow.ShowWindow(); MxMAnimConfigWindow.SetData(data); return true; } return false; }
public static bool OpenAssetEditor(int a_instanceID, int a_line) { MxMAnimationClipComposite data = EditorUtility.InstanceIDToObject( a_instanceID) as MxMAnimationClipComposite; if (data != null) { data.ValidateBaseData(); MxMAnimConfigWindow.ShowWindow(); MxMAnimConfigWindow.SetData(data); return true; } return false; }
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 * *********************************************************************************************/ 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(); } }
private void DragDropAnimations(Rect a_dropRect, EAnimType a_type, int a_index) { Event evt = Event.current; switch (evt.type) { case EventType.DragUpdated: case EventType.DragPerform: { if (!a_dropRect.Contains(evt.mousePosition)) { return; } if (DragAndDrop.objectReferences[0].GetType() == typeof(AnimationClip)) { DragAndDrop.visualMode = DragAndDropVisualMode.Copy; if (evt.type == EventType.DragPerform) { DragAndDrop.AcceptDrag(); UnityEngine.Object obj = DragAndDrop.objectReferences[0]; if (obj != null && obj.GetType() == typeof(AnimationClip)) { switch (a_type) { case EAnimType.Current: { m_spPrimaryClip.objectReferenceValue = obj; m_data.name = (obj as AnimationClip).name + "_comp"; if ((obj as AnimationClip).isLooping) { m_spLooping.boolValue = true; } m_selectionType = EAnimType.Current; m_selectionId = 0; m_data.GenerateRootLookupTable(); } break; case EAnimType.Future: { if (a_index == m_spAfterClips.arraySize) { m_spAfterClips.InsertArrayElementAtIndex(a_index); } m_spAfterClips.GetArrayElementAtIndex(a_index).objectReferenceValue = obj; m_selectionType = EAnimType.Future; m_selectionId = a_index; } break; case EAnimType.Past: { if (a_index == m_spBeforeClips.arraySize) { m_spBeforeClips.InsertArrayElementAtIndex(a_index); } m_spBeforeClips.GetArrayElementAtIndex(a_index).objectReferenceValue = obj; m_selectionType = EAnimType.Past; m_selectionId = a_index; } break; } MxMAnimConfigWindow.Inst().Repaint(); } } } } break; } }
private void ManageSlot(Rect a_rect, AnimationClip a_clip, string a_defaultName, EAnimType a_animType = EAnimType.Current, int a_index = 0) { if (a_clip != null) { Texture2D assetPreview = AssetPreview.GetAssetPreview(a_clip); if (assetPreview != null) { GUI.DrawTexture(a_rect, assetPreview); } GUI.Box(a_rect, "\n" + a_clip.name); if (m_selectionType == a_animType && a_index == m_selectionId) { Handles.color = Color.green; } else { Handles.color = Color.cyan; } Texture icon = EditorGUIUtility.IconContent("d_P4_DeletedLocal").image; Rect deleteRect = new Rect(a_rect.x + a_rect.width - 20f, a_rect.y + a_rect.height - 20f, 18f, 18f); GUIStyle invisiButton = new GUIStyle(GUI.skin.label); if (GUI.Button(deleteRect, icon, invisiButton)) { if (EditorUtility.DisplayDialog("Delete Clip", "Are you sure you want to delete this clip from the composite?", "Yes", "Cancel")) { if (a_animType == EAnimType.Current) { m_spPrimaryClip.objectReferenceValue = null; } else if (a_animType == EAnimType.Future) { if (a_index < m_spAfterClips.arraySize) { if (m_spAfterClips.GetArrayElementAtIndex(a_index).objectReferenceValue != null) { m_spAfterClips.DeleteArrayElementAtIndex(a_index); } m_spAfterClips.DeleteArrayElementAtIndex(a_index); } } else if (a_animType == EAnimType.Past) { if (a_index < m_spBeforeClips.arraySize) { if (m_spBeforeClips.GetArrayElementAtIndex(a_index).objectReferenceValue != null) { m_spBeforeClips.DeleteArrayElementAtIndex(a_index); } m_spBeforeClips.DeleteArrayElementAtIndex(a_index); } } } } if (CheckHover(a_rect)) { ManageSelection(a_animType, a_index); Handles.color = Color.yellow; MxMAnimConfigWindow.Inst().Repaint(); } } else { GUI.Box(a_rect, a_defaultName); Handles.color = Color.red; } //Draw highlight box Handles.DrawLine(new Vector3(a_rect.xMin, a_rect.yMin), new Vector3(a_rect.xMax, a_rect.yMin)); Handles.DrawLine(new Vector3(a_rect.xMax, a_rect.yMin), new Vector3(a_rect.xMax, a_rect.yMax)); Handles.DrawLine(new Vector3(a_rect.xMax, a_rect.yMax), new Vector3(a_rect.xMin, a_rect.yMax)); Handles.DrawLine(new Vector3(a_rect.xMin, a_rect.yMax), new Vector3(a_rect.xMin, a_rect.yMin)); DragDropAnimations(a_rect, a_animType, a_index); }
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(); } }
private void DragDropAnimations(Rect a_dropRect, EAnimType a_type, int a_index) { Event evt = Event.current; switch (evt.type) { case EventType.DragUpdated: case EventType.DragPerform: { if (!a_dropRect.Contains(evt.mousePosition)) { return; } if (DragAndDrop.objectReferences[0].GetType() == typeof(AnimationClip)) { DragAndDrop.visualMode = DragAndDropVisualMode.Copy; if (evt.type == EventType.DragPerform) { DragAndDrop.AcceptDrag(); Object obj = DragAndDrop.objectReferences[0]; if (obj != null && obj.GetType() == typeof(AnimationClip)) { switch (a_type) { case EAnimType.Primary: { m_spPrimaryClip.objectReferenceValue = obj; m_data.name = (obj as AnimationClip).name + "_idleSet"; m_selectionType = EAnimType.Primary; m_selectionId = 0; } break; case EAnimType.Secondary: { if (a_index == m_spSecondaryClips.arraySize) { m_spSecondaryClips.InsertArrayElementAtIndex(a_index); } m_spSecondaryClips.GetArrayElementAtIndex(a_index).objectReferenceValue = obj; m_selectionType = EAnimType.Secondary; m_selectionId = a_index; } break; case EAnimType.Transition: { if (a_index == m_spTransitionClips.arraySize) { m_spTransitionClips.InsertArrayElementAtIndex(a_index); } m_spTransitionClips.GetArrayElementAtIndex(a_index).objectReferenceValue = obj; m_selectionType = EAnimType.Transition; m_selectionId = a_index; } break; } MxMAnimConfigWindow.Inst().Repaint(); } } } } break; } }
public void OnGUI(Rect a_position) { if (m_data == null) { MxMSettings settings = MxMSettings.Instance(); if (settings != null) { m_data = settings.ActiveIdleSet; if (m_data != null) { SetData(m_data); } } } if (m_data != null) { Rect viewRect = new Rect(0f, 0f, a_position.width, a_position.height); float requiredWidth = (Mathf.Max(m_data.TransitionClips.Count, m_data.SecondaryClips.Count) + 1) * (s_animSlotSizeSmall + 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 - 18f); m_scrollPosition = GUI.BeginScrollView(viewRect, m_scrollPosition, scrollRect); } Rect baseAnimRect = new Rect(a_position.width / 2f - s_animSlotSize / 2f, a_position.height / 2.5f - s_animSlotSize / 2f, s_animSlotSize, s_animSlotSize); ManageSlot(baseAnimRect, m_data.PrimaryClip, "\n\n\nPrimary Anim"); if (m_data.SecondaryClips == null) { m_data.SecondaryClips = new List <AnimationClip>(); } if (m_data.PrimaryClip != null) { Rect slotRect = new Rect(a_position.width / 2f - s_animSlotSizeSmall / 2f - (m_data.TransitionClips.Count * (s_animSlotSizeSmall + s_animSlotSpacing)) / 2f, baseAnimRect.y - s_animSlotSizeSmall - s_animSlotSpacing, s_animSlotSizeSmall, s_animSlotSizeSmall); EditorGUILayout.BeginHorizontal(); GUILayout.Space(Mathf.Max(m_data.TransitionClips.Count, m_data.SecondaryClips.Count) * (s_animSlotSizeSmall + s_animSlotSpacing)); EditorGUILayout.EndHorizontal(); for (int i = 0; i < m_data.TransitionClips.Count + 1; ++i) { ManageSlot(slotRect, i < m_data.TransitionClips.Count ? m_data.TransitionClips[i] : null, "\n\nTransition\nAnim", EAnimType.Transition, i); slotRect.x += s_animSlotSizeSmall + s_animSlotSpacing; } slotRect = new Rect(a_position.width / 2f - s_animSlotSizeSmall / 2f - (m_data.SecondaryClips.Count * (s_animSlotSizeSmall + s_animSlotSpacing)) / 2f, baseAnimRect.y + s_animSlotSize + s_animSlotSpacing, s_animSlotSizeSmall, s_animSlotSizeSmall); for (int i = 0; i < m_data.SecondaryClips.Count + 1; ++i) { ManageSlot(slotRect, i < m_data.SecondaryClips.Count ? m_data.SecondaryClips[i] : null, "\n\nSecondary\nAnim", EAnimType.Secondary, i); slotRect.x += s_animSlotSizeSmall + s_animSlotSpacing; } Rect settingsRect = new Rect(baseAnimRect.x - s_animSlotSpacing / 2f, baseAnimRect.y + baseAnimRect.height + s_animSlotSpacing * 2f + s_animSlotSizeSmall, baseAnimRect.width + s_animSlotSpacing, baseAnimRect.height * 2f); DrawSettings(settingsRect); } Event evt = Event.current; if (evt.isKey && evt.keyCode == KeyCode.Delete) { switch (m_selectionType) { case EAnimType.Primary: { m_spPrimaryClip.objectReferenceValue = null; } break; case EAnimType.Secondary: { if (m_selectionId < m_spSecondaryClips.arraySize) { if (m_spSecondaryClips.GetArrayElementAtIndex(m_selectionId).objectReferenceValue != null) { m_spSecondaryClips.DeleteArrayElementAtIndex(m_selectionId); } m_spSecondaryClips.DeleteArrayElementAtIndex(m_selectionId); } } break; case EAnimType.Transition: { if (m_selectionId < m_spTransitionClips.arraySize) { if (m_spTransitionClips.GetArrayElementAtIndex(m_selectionId).objectReferenceValue != null) { m_spTransitionClips.DeleteArrayElementAtIndex(m_selectionId); } m_spTransitionClips.DeleteArrayElementAtIndex(m_selectionId); } } 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)); GUILayout.Space(3f); if (GUILayout.Button(new GUIContent("Locate Asset"), EditorStyles.toolbarButton)) { if (m_data != null) { EditorGUIUtility.PingObject(m_data); } } GUILayout.Space(a_position.width - 190f); if (GUILayout.Button(new GUIContent("Locate Animation"), EditorStyles.toolbarButton)) { if (m_selectionId >= 0) { switch (m_selectionType) { case EAnimType.Primary: { if (m_spPrimaryClip.objectReferenceValue != null) { EditorGUIUtility.PingObject(m_spPrimaryClip.objectReferenceValue); } } break; case EAnimType.Secondary: { if (m_spSecondaryClips.arraySize > m_selectionId) { SerializedProperty spAnim = m_spSecondaryClips.GetArrayElementAtIndex(m_selectionId); if (spAnim != null && spAnim.objectReferenceValue != null) { EditorGUIUtility.PingObject(spAnim.objectReferenceValue); } else { if (m_spPrimaryClip.objectReferenceValue != null) { EditorGUIUtility.PingObject(m_spPrimaryClip.objectReferenceValue); } } } } break; case EAnimType.Transition: { if (m_spTransitionClips.arraySize > m_selectionId) { SerializedProperty spAnim = m_spTransitionClips.GetArrayElementAtIndex(m_selectionId); if (spAnim != null && spAnim.objectReferenceValue != null) { EditorGUIUtility.PingObject(spAnim.objectReferenceValue); } else { if (m_spPrimaryClip.objectReferenceValue != null) { EditorGUIUtility.PingObject(m_spPrimaryClip.objectReferenceValue); } } } } break; } } else { if (m_spPrimaryClip.objectReferenceValue != null) { EditorGUIUtility.PingObject(m_spPrimaryClip.objectReferenceValue); } } } if (m_soData != null) { m_soData.ApplyModifiedProperties(); } } else { GUILayout.Space(18f); EditorGUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); EditorGUILayout.LabelField("No Idle Set Selected.", EditorStyles.boldLabel); GUILayout.FlexibleSpace(); EditorGUILayout.EndHorizontal(); } }