/// <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(GUILayout.ExpandHeight(true)); { r.height -= 21; r.width -= 2; r.y += 1; r.x += 1; spritePreview.OnInteractivePreviewGUI(r, EditorStyles.whiteLabel); } EditorGUILayout.EndVertical(); EditorGUILayout.BeginHorizontal(new GUIStyle("ProjectBrowserPreviewBg"), GUILayout.Height(10)); { // Play Button GUIContent buttonContent = spritePreview.IsPlaying ? pauseButtonContent : playButtonContent; spritePreview.IsPlaying = GUILayout.Toggle(spritePreview.IsPlaying, buttonContent, buttonStyle); // FPS Slider GUILayout.Box(speedScale, labelStyle); 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 selectedAnimation.Name = EditorGUILayout.TextField("Name", selectedAnimation.Name); EditorGUILayout.Space(); DragAndDropBox(); } EditorGUILayout.EndVertical(); }
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(); } } }