private static void DoDragAndDrop(AnimationPlayer animationPlayer, PersistedInt selectedLayer, PersistedInt selectedState, AnimationPlayerEditor editor) { var dragAndDropRect = EditorUtilities.ReserveRect(GUILayout.Height(62f)); Event evt = Event.current; GUI.Box(dragAndDropRect, "Drag clips here to add\nthem to the player!", dragAndDropBoxStyle); switch (evt.type) { case EventType.DragUpdated: case EventType.DragPerform: if (!dragAndDropRect.Contains(evt.mousePosition)) { return; } DragAndDrop.visualMode = DragAndDropVisualMode.Copy; if (evt.type == EventType.DragPerform) { DragAndDrop.AcceptDrag(); var animationClips = DragAndDrop.objectReferences.FilterByType <AnimationClip>().ToList(); foreach (var obj in DragAndDrop.objectReferences.FilterByType <GameObject>()) { var assetPath = AssetDatabase.GetAssetPath(obj); if (!(AssetImporter.GetAtPath(assetPath) is ModelImporter)) { return; } animationClips.AddRange(AssetDatabase.LoadAllAssetsAtPath(assetPath).FilterByType <AnimationClip>(). Where(clip => (clip.hideFlags & HideFlags.HideInHierarchy) == 0)); } if (animationClips.Count > 0) { EditorUtilities.RecordUndo(animationPlayer, "Added clip to Animation Player"); var layer = animationPlayer.layers[selectedLayer]; int numClipsBefore = layer.states.Count; foreach (var clip in animationClips) { var newStateName = GetUniqueStateName(clip.name, layer.states); var newState = SingleClipState.Create(newStateName, clip); layer.states.Add(newState); } selectedState.SetTo(numClipsBefore); editor.MarkDirty(); } } break; } }
private static void DoDragAndDrop(AnimationPlayer animationPlayer, PersistedInt selectedLayer, PersistedInt selectedState, AnimationPlayerEditor editor) { const int numButtons = 5; const float spacePerButton = 20f; const float border = 3f; Debug.Log(DragAndDrop.objectReferences.PrettyPrint()); var dragAndDropRect = EditorUtilities.ReserveRect(GUILayout.Height((numButtons * spacePerButton) + border)); Event evt = Event.current; GUI.Box(dragAndDropRect, "Drag clips here to add\nthem to the player!", dragAndDropBoxStyle); switch (evt.type) { case EventType.DragUpdated: case EventType.DragPerform: if (!dragAndDropRect.Contains(evt.mousePosition)) { return; } DragAndDrop.visualMode = DragAndDropVisualMode.Copy; if (evt.type == EventType.DragPerform) { DragAndDrop.AcceptDrag(); var animationClips = DragAndDrop.objectReferences.OfType <AnimationClip>().ToList(); foreach (var obj in DragAndDrop.objectReferences.OfType <GameObject>()) { var assetPath = AssetDatabase.GetAssetPath(obj); if (!(AssetImporter.GetAtPath(assetPath) is ModelImporter)) { return; } animationClips.AddRange(AssetDatabase.LoadAllAssetsAtPath(assetPath).OfType <AnimationClip>(). Where(clip => (clip.hideFlags & HideFlags.HideInHierarchy) == 0)); } if (animationClips.Count == 1) { AddClipsAsSeperateStates(animationPlayer, selectedLayer, selectedState, editor, animationClips); } else if (animationClips.Count > 1) { editor.StartDragAndDropMultiChoice(animationClips); } } break; } }
private void DrawSelectedState() { EditorGUILayout.BeginHorizontal(editLayerButton_Background); //Making tabbed views are hard! var editStatesRect = EditorUtilities.ReserveRect(); var editTransitionsRect = EditorUtilities.ReserveRect(); var eventsRect = EditorUtilities.ReserveRect(); var metaDataRect = EditorUtilities.ReserveRect(); EditorGUILayout.EndHorizontal(); DrawTabHeader(editStatesRect, "Clips", 0); DrawTabHeader(editTransitionsRect, "Transitions", 1); DrawTabHeader(eventsRect, "Events", 2); DrawTabHeader(metaDataRect, "Metadata", 3); EditorGUILayout.BeginVertical(editLayerStyle); GUILayout.Space(10f); switch ((AnimationPlayerEditMode)selectedEditMode) { case AnimationPlayerEditMode.States: StateDataDrawer.DrawStateData(animationPlayer, selectedLayer, selectedState, this); break; case AnimationPlayerEditMode.Transitions: AnimationTransitionDrawer.DrawTransitions(animationPlayer, selectedLayer, selectedState, selectedToState, allStateNames[selectedLayer]); break; case AnimationPlayerEditMode.Events: DrawEvents(); break; case AnimationPlayerEditMode.MetaData: metaDataDrawer.DrawMetaData(); break; } GUILayout.Space(20f); EditorGUILayout.EndVertical(); }