private void OnSelectionChange()
 {
     // Change animation if we select an animation on the project
     if (Selection.activeObject != null && Selection.activeObject.GetType() == typeof(SpriteAnimation))
     {
         SpriteAnimation sa = Selection.activeObject as SpriteAnimation;
         if (sa != selectedAnimation)
         {
             selectedAnimation = sa;
             spritePreview     = null;
             InitializeReorderableList();
             Repaint();
         }
     }
 }
        /// <summary>
        /// Draws the preview window
        /// </summary>
        /// <param name="r">Draw rect</param>
        private void PreviewBox(Rect r)
        {
            if (spritePreview == null || spritePreview.CurrentAnimation != selectedAnimation)
            {
                spritePreview = (EditorPreviewSpriteAnimation)Editor.CreateEditor(selectedAnimation, typeof(EditorPreviewSpriteAnimation));
            }

            if (spritePreview != null)
            {
                EditorGUILayout.BeginVertical(preview, GUILayout.ExpandHeight(true), GUILayout.ExpandWidth(true));
                {
                    r.height -= 21;
                    r.width  -= 2;
                    r.y      += 1;
                    r.x      += 1;
                    spritePreview.OnInteractivePreviewGUI(r, EditorStyles.whiteLabel);
                }
                EditorGUILayout.EndVertical();

                EditorGUILayout.BeginHorizontal(previewToolBar);
                {
                    // Play Button
                    GUIContent buttonContent = spritePreview.IsPlaying ? pauseButtonContent : playButtonContent;
                    spritePreview.IsPlaying = GUILayout.Toggle(spritePreview.IsPlaying, buttonContent, buttonStyle, GUILayout.Width(40));

                    // Loop Button
                    GUIContent loopContent = spritePreview.Loop ? loopIconActive : loopIcon;
                    spritePreview.Loop = GUILayout.Toggle(spritePreview.Loop, loopContent, buttonStyle, GUILayout.Width(40));

                    // FPS Slider
                    GUILayout.Box(speedScaleIcon, labelStyle, GUILayout.ExpandWidth(false));
                    spritePreview.FramesPerSecond = (int)GUILayout.HorizontalSlider(spritePreview.FramesPerSecond, 0, 60, sliderStyle, sliderThumbStyle);
                    GUILayout.Label(spritePreview.FramesPerSecond.ToString("0") + " fps", labelStyle, GUILayout.Width(50));
                }
                EditorGUILayout.EndHorizontal();
            }
        }
        /// <summary>
        /// Draws the box with the name and file of the animation
        /// </summary>
        private void ConfigBox()
        {
            EditorGUILayout.BeginVertical(box);
            {
                SpriteAnimation newSpriteAnimation = EditorGUILayout.ObjectField("Animation", selectedAnimation, typeof(SpriteAnimation), false) as SpriteAnimation;
                if (newSpriteAnimation == null)
                {
                    return;
                }

                // Reset preview and list if we select a new animation
                if (newSpriteAnimation != selectedAnimation)
                {
                    selectedAnimation = newSpriteAnimation;
                    InitializeReorderableList();
                    spritePreview = (EditorPreviewSpriteAnimation)Editor.CreateEditor(selectedAnimation, typeof(EditorPreviewSpriteAnimation));
                }

                // Name field
                EditorGUILayout.Space();
                DragAndDropBox();
            }
            EditorGUILayout.EndVertical();
        }